How to Retrieve and Save Trace/Span IDs for Chat Completion Requests to Update Metadata Later
Does anyone have experience with retrieving trace/span IDs after a request is made? I'm trying to save the ID on our end so that I can reference it later and make updates to the metadata (use case here being allowing the user to submit 👍 / 👎 for a response and have that saved in the metadata). Here's what I've currently got for making requests:
with using_metadata(metadata), using_user(user_id):
try:
response = self.oai_client.chat.completions.create(**formatted_prompt)
response_content: str = response.choices[0].message.content
response_model = Response.objects.create(
prompt_name=prompt_name,
full_prompt_text=formatted_prompt['messages'],
response_text=response_content,
success=response.choices[0].finish_reason == 'stop',
)
return {
'response': response_model,
'span': None, # Not supported yet
'raw_response': response,
}