Chats

Logs a chat 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_LLM: For text data.

• 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.

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 = {
    "chat_history": [
      {"role": "user", "content": "How do I implement a neural network in Python?"},
      {"role": "assistant", "content": "To implement a neural network in Python, you can use libraries like TensorFlow or PyTorch. Here’s a simple example using PyTorch..."},
      {"role": "user", "content": "Can you give me more details about the layers and activation functions?"},
      {"role": "assistant", "content": "Sure! A neural network typically consists of an input layer, one or more hidden layers, and an output layer. Each layer has neurons, which apply an activation function to the input data. Common activation functions include ReLU, Sigmoid, and Tanh."},
      {"role": "user", "content": "What is the purpose of an activation function?"},
      {"role": "assistant", "content": "The activation function introduces non-linearity into the network, allowing it to learn complex patterns. Without activation functions, the network would essentially be a linear model, regardless of its depth."},
      {"role": "user", "content": "Can you show me an example of a neural network with ReLU activation function?"},
      {"role": "assistant", "content": "Certainly! Here’s a simple example using PyTorch:\n\n```python\nimport torch\nimport torch.nn as nn\nimport torch.optim as optim\n\nclass SimpleNN(nn.Module):\n    def __init__(self):\n        super(SimpleNN, self).__init__()\n        self.fc1 = nn.Linear(10, 50)\n        self.relu = nn.ReLU()\n        self.fc2 = nn.Linear(50, 1)\n    \n    def forward(self, x):\n        x = self.fc1(x)\n        x = self.relu(x)\n        x = self.fc2(x)\n        return x\n\nmodel = SimpleNN()\ncriterion = nn.MSELoss()\noptimizer = optim.SGD(model.parameters(), lr=0.01)\n```"},
      {"role": "user", "content": "How do I train this neural network?"},
      {"role": "assistant", "content": "To train the neural network, you need to feed it data, compute the loss, and update the weights. Here’s how you can do it:\n\n```python\nfor epoch in range(100):\n    optimizer.zero_grad()\n    outputs = model(inputs)\n    loss = criterion(outputs, targets)\n    loss.backward()\n    optimizer.step()\n    print(f'Epoch [{epoch+1}/100], Loss: {loss.item():.4f}')\n```"},
      {"role": "user", "content": "What kind of data can I use to train this model?"},
      {"role": "assistant", "content": "You can use any numerical data that fits the input and output dimensions of your model. For example, if you’re working on a regression problem, you might use datasets like the Boston Housing dataset. For classification, you could use the MNIST dataset. The key is to preprocess your data to match the input shape expected by the model."}
    ]
  },
  tags = {"category": "AI", "level": "advanced"}
).result()

Structure:

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. Must be a string.

context (Optional): The context of the message. Must be a list of pairs of strings in the format [["", ""]...].

Description:

Role: Indicates who sent the message (e.g., user or assistant).

Content: The actual message sent.

Context: (Optional) Additional information that may provide background or supporting data for the message.

Last updated