Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Cohere instrumentation #3081

Draft
wants to merge 29 commits into
base: main
Choose a base branch
from
Draft

Conversation

lzchen
Copy link
Contributor

@lzchen lzchen commented Dec 9, 2024

Part of #3050

TODO:

Add tests
Support streaming

lzchen added 26 commits August 29, 2024 11:33
}
response_format = kwargs.get("response_format")
if response_format:
# TODO: Add to sem conv
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make the openai generic instead?

Copy link
Contributor

@codefromthecrypt codefromthecrypt Dec 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so you mean remove the openai one and make a generic one for this entry: https://github.com/open-telemetry/semantic-conventions/blob/abd92c153b627efd3222e6b46828c5e94bf1b2cd/model/gen-ai/spans.yaml#L88

I think it can make sense, and in any case we can open an issue any cohere specific attributes and add that into the TODO comment. That issue could be closed either by normalizing things from openai, cohere specific adds, or a combo.

@karthikscale3 you happen to know how many other LLM providers have a concept of response_format?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lmolkova Is it possible to have a generic attribute but have each implementation (openai, cohere) have their own list of possible values?

"stop_sequences"
),
GenAIAttributes.GEN_AI_REQUEST_TEMPERATURE: kwargs.get("temperature"),
# TODO: Add to sem conv
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

I'd merge it with gen_ai.openai.request.seed into gen_ai.request.seed

if getattr(result.usage, "tokens"):
span.set_attribute(
GenAIAttributes.GEN_AI_USAGE_INPUT_TOKENS,
result.usage.tokens.input_tokens,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PTAL at the open-telemetry/semantic-conventions#1279

Cohere reports billed tokens in addition to input/output

image

https://docs.cohere.com/v2/reference/chat#response.body.usage

I'm not sure what's the difference and if we need to report one or another (or maybe both?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


def get_span_name(span_attributes):
name = span_attributes.get(GenAIAttributes.GEN_AI_OPERATION_NAME, "")
model = span_attributes.get(GenAIAttributes.GEN_AI_REQUEST_MODEL, "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

model might not be available in some cases, we should report "f{name}"

span.set_attribute(
ErrorAttributes.ERROR_TYPE, type(error).__qualname__
)
span.end()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is span.end() needed?

trace.get_tracer_provider().add_span_processor(
BatchSpanProcessor(ConsoleSpanExporter())
)
tracer = trace.get_tracer(__name__)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we setup logs/events and mention how to turn on content?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants