feat(openai): POC for updated gen_ai.attributes#3682
feat(openai): POC for updated gen_ai.attributes#3682dinmukhamedm wants to merge 2 commits intotraceloop:mainfrom
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| }) | ||
| elif role == "user": | ||
| content = msg.get("content") | ||
| content = [{"text": content, "type": "text"}] if isinstance(content, str) else content |
There was a problem hiding this comment.
Hey i think in the conv its
{ “type”: “text”, “content”: “....” }
https://opentelemetry.io/docs/specs/semconv/registry/attributes/gen-ai/#gen-ai-input-messages
There was a problem hiding this comment.
Good catch! Fair, this slipped through, though I added the correct convention in the schema https://github.com/traceloop/openllmetry/pull/3682/changes#diff-419663c6ce668e979666f0d34f908c8e4a255242e2d7c35aab0dd139e15558ddR72
I'll do that in the next revision of this PR once I've gathered more feedback.
f8ec5cd to
3f6cbd0
Compare
| @@ -0,0 +1,207 @@ | |||
| """ | |||
| This module provides TypedDict definitions for the JSON values used | |||
| in Generative AI span attributes, including `gen_ai.input_messages`, | |||
| messages = [] | ||
| for choice in choices: | ||
| messages.append({ | ||
| "role": "assistant", |
There was a problem hiding this comment.
Maybe we should take it to const / enum its will be more typed
| }) | ||
| _set_span_attribute( | ||
| span, | ||
| "gen_ai.output.messages", |
There was a problem hiding this comment.
Same for here maybe its should use the const
| for choice in choices: | ||
| message = choice.get("message") | ||
| content = message.get("content") | ||
| parts = [{"text": content, "type": "text"}] if isinstance(content, str) else content |
| span, | ||
| "gen_ai.input.messages", | ||
| # f"{SpanAttributes.GEN_AI_INPUT_MESSAGES}", | ||
| json.dumps([{"role": "user", "parts": [{"content": prompt, "type": "text"}]}]), |
There was a problem hiding this comment.
I think the type of the part should be also an a enum its will be easier to mange
|
|
||
| _set_span_attribute( | ||
| span, | ||
| "gen_ai.input.messages", |
There was a problem hiding this comment.
and use the const over here too
| content = msg.get("content") | ||
| attr_messages.append({ | ||
| "role": role, | ||
| "parts": [{"type": "tool_call_response", "id": id, "response": content}], |
There was a problem hiding this comment.
WDT about extracting it to helper and create a build part method that we can use along all the code
This is an early work attempting to tackle #3515. Once I get initial green light, I will rebase, properly restructure, and continue work on this, gradually adding instrumentations one by one
feat(instrumentation): ...orfix(instrumentation): ....