Max
Max•13mo ago

observationId in Python SDK

are you using langchain or the normal sdk?
6 Replies
Alex
Alex•13mo ago
Normal SDK, no langchain I have langfuse.model.CreateGeneration objects handy
Max
Max•13mo ago
from langfuse.model import CreateGeneration, Usage, UpdateGeneration

from datetime import datetime

generationStartTime = datetime.now()

# chat_completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=[{"role": "user", "content": "Hello world"}])
# ...

generation = trace.generation(CreateGeneration(
name="summary-generation",
startTime=generationStartTime,
endTime=datetime.now(),
model="gpt-3.5-turbo",
modelParameters={"maxTokens": "1000", "temperature": "0.9"},
prompt=[{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Please generate a summary of the following documents \nThe engineering department defined the following OKR goals...\nThe marketing department defined the following OKR goals..."}],
metadata={"interface": "whatsapp"}
))

generation.id # <- id for observations
from langfuse.model import CreateGeneration, Usage, UpdateGeneration

from datetime import datetime

generationStartTime = datetime.now()

# chat_completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=[{"role": "user", "content": "Hello world"}])
# ...

generation = trace.generation(CreateGeneration(
name="summary-generation",
startTime=generationStartTime,
endTime=datetime.now(),
model="gpt-3.5-turbo",
modelParameters={"maxTokens": "1000", "temperature": "0.9"},
prompt=[{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Please generate a summary of the following documents \nThe engineering department defined the following OKR goals...\nThe marketing department defined the following OKR goals..."}],
metadata={"interface": "whatsapp"}
))

generation.id # <- id for observations
you can do the same with spans
span = trace.span(CreateSpan(
name="embedding-search",
startTime=retrievalStartTime,
endTime=datetime.now(),
metadata={"database": "pinecone"},
input = {'query': 'This document entails the OKR goals for ACME'},
)
)
span.id # <- id for observations
span = trace.span(CreateSpan(
name="embedding-search",
startTime=retrievalStartTime,
endTime=datetime.now(),
metadata={"database": "pinecone"},
input = {'query': 'This document entails the OKR goals for ACME'},
)
)
span.id # <- id for observations
Alex
Alex•13mo ago
Great, thanks! Just curious now, so the ids are generated directly by the sdk on the client side? No validation needed on the server? Or, does CreateGeneration communicate with the server under the hood?
Max
Max•13mo ago
yes exactly 🙂 its non blocking, no validation server side
Alex
Alex•13mo ago
very cool, thanks!
Max
Max•13mo ago
sure 🙂