Image & Text

Logs a multimodel data for evaluation using Future Agi client.

Creating an Client

from fi_client import Client

api_key = os.environ["FI_API_KEY"]
secret_key = os.environ["FI_SECRET_KEY"]
base_url = os.environ["FI_API_URL"]

fi_client = Client(api_key=api_key, secret_key=secret_key,uri=base_url)

Supported Model Types:

• GENERATIVE_IMAGE: For text and image data.

Supported Environments:

• TRAINING: For models in the training phase.

• VALIDATION: For models in the validation phase.

• PRODUCTION: For models deployed in a production environment.

• CORPUS: For models dealing with a large collection of data or corpus.

Converting Image to bytes


from PIL import Image
import base64
from io import BytesIO

def to_byte_image(image):
    buffered = BytesIO()
    image.save(buffered, format="JPEG")
    
    # Get the byte data
    img_byte = buffered.getvalue()
    
    # Encode the byte data to base64
    img_base64 = base64.b64encode(img_byte).decode('utf-8')
    
    # Create the base64 string with the data URI scheme
    img_base64_str = f"data:image/jpeg;base64,{img_base64}"
    
    # Output the result
    return img_base64_str

Sending a data for Evaluation

To log an event, you need to provide the required parameters such as model_id, model_type, environment, and optionally model_version, prediction_timestamp, conversation, and tags.

from fi.client import ModelTypes, Environments
import time

fi_client.log(
  "model_id = "your-model-ID",
  model_type = ModelTypes.GENERATIVE_LLM,
  environment = Environments.PRODUCTION,
  model_version = "v2",
  prediction_timestamp =int(time.time()),
  consersation = {
 "conversation_id" : "123456",
    "chat_history": [
{
            "role": "user",
            "content": [
                {"type": "text", "text":<instruction> },
                {"type": "image_url", "image_url": {"url": to_byte_image(<source_img>) }},
            ]
        },
        {
            "role": "assistant",
            "content": [
                {"type": "image_url", "image_url": {"url": to_byte_image(<target_img>) }}
            ]
        }
    ]
  },
  tags={"category": "AI", "level": "advanced", 123: "invalid_key"}
).result()

Structure:

conversation_id: The ID of the conversation. Must be a string.

chat_history: A list of dictionaries, each representing a message.

role: The role of the participant (e.g., “user”, “assistant”). Must be a string.

content: The content of the message. Can be a list of dictionaries with different content types (e.g., text, image_url).

Description:

Conversation ID: Unique identifier for the conversation, allowing for easy retrieval and association of messages.

Role: Indicates who sent the message.

Content: The message content, which can include text and images.

Last updated