1. Installation

First install the traceAI package to access the observability framework

pip install traceAI-openai

2. Set Environment Variables

Set up your environment variables to authenticate with both FutureAGI and OpenAI services.

import os

os.environ["TOGETHER_API_KEY"] = "your-together-api-key"
os.environ["FI_API_KEY"] = "your-futureagi-api-key"
os.environ["FI_SECRET_KEY"] = "your-futureagi-secret-key"

3. Initialize Trace Provider

Set up the trace provider to create a new project in FutureAGI, establish telemetry data pipelines .

from fi_instrumentation import register
from fi_instrumentation.fi_types import ProjectType

trace_provider = register(
    project_type=ProjectType.OBSERVE,
    project_name="togetherai_project",
)

4. Instrument your Project

Use the OpenAI Instrumentor to instrument your project, as the OpenAI Client is utilized for interactions with Together AI. This step guarantees that all interactions are tracked and monitored. If you are using a different client to interact with Together AI, use that client’s Instrumentor instead.

from traceai_openai import OpenAIInstrumentor

OpenAIInstrumentor().instrument(tracer_provider=trace_provider)

5. Interact with Together AI

Interact with the Together AI through OpenAI Client. Our OpenAI Instrumentor will automatically trace and send the telemetry data to our platform.

import openai

client = openai.OpenAI(
  api_key=os.environ.get("TOGETHER_API_KEY"),
  base_url="https://api.together.xyz/v1",
)

response = client.chat.completions.create(
  model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo",
  messages=[
    {"role": "system", "content": "You are a travel agent. Be descriptive and helpful."},
    {"role": "user", "content": "Tell me the top 3 things to do in San Francisco"},
  ]
)

print(response.choices[0].message.content)

Was this page helpful?