Skip to content

Conversation

@Humbertzhang
Copy link
Contributor

@Humbertzhang Humbertzhang commented Mar 19, 2024

Fixes #627

  • I have added tests that cover my changes.
  • If adding a new instrumentation or changing an existing one, I've added screenshots from some observability platform showing the change.
  • For Traces:
image
  • For Metrics:
image

…to stream_token

# Conflicts:
#	packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/shared/chat_wrappers.py
#	packages/opentelemetry-instrumentation-openai/poetry.lock
#	packages/opentelemetry-instrumentation-openai/pyproject.toml
#	packages/opentelemetry-instrumentation-openai/tests/metrics/test_openai_metrics.py
#	packages/opentelemetry-instrumentation-openai/tests/traces/test_chat.py
#	packages/opentelemetry-instrumentation-openai/tests/traces/test_completions.py
@Humbertzhang
Copy link
Contributor Author

Humbertzhang commented Mar 19, 2024

CI error:

  E               vcr.errors.CannotOverwriteExistingCassetteException: Can't overwrite existing cassette ('/home/runner/work/openllmetry/openllmetry/packages/opentelemetry-instrumentation-openai/tests/traces/cassettes/test_chat/test_chat_streaming.yaml') in your current record mode ('none').
  E               No match for the request (<Request (GET) https://openaipublic.blob.core.windows.net/encodings/cl100k_base.tiktoken>) was found.

tiktoken need to download file at it first run, so vcr's none record mode maybe not suite for it...

@nirga Do u have some thoughts about it?

@nirga
Copy link
Member

nirga commented Mar 19, 2024

@Humbertzhang you can tell VCR to ignore certain hostnames, then it will not try and replay the cassette for those host names, but actually try to make an HTTP call, see this example -

"ignore_hosts": ["raw.githubusercontent.com"],

@nirga nirga changed the title feat(openai): Support report token usage in stream mode fix(openai): Support report token usage in stream mode Mar 19, 2024
return model


def should_record_stream_token_usage():
Copy link
Member

Choose a reason for hiding this comment

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

Let's put it as an optional parameter to the __init__ of the instrumentation (I'd default it to true)? I think it's cleaner (and I want to move the should_trace_content to be like that as well)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean move it to Traceloop.init()'s arg, right?

Copy link
Member

Choose a reason for hiding this comment

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

No, the instrumentation init. Then traceloop sdk can pass it yes

…to stream_token

# Conflicts:
#	packages/opentelemetry-instrumentation-langchain/poetry.lock
#	packages/opentelemetry-instrumentation-llamaindex/poetry.lock
#	packages/opentelemetry-instrumentation-openai/poetry.lock
#	packages/opentelemetry-instrumentation-pinecone/poetry.lock
#	packages/opentelemetry-instrumentation-weaviate/poetry.lock
@Humbertzhang
Copy link
Contributor Author

Hello @nirga, I have resolved the VCR issue by adding ignore_hosts. However, I'm not entirely sure what you mean by "put it as an optional parameter to the __init__ of the instrumentation."

Could you provide me an example? Alternatively, we could just merge this, and I can make modifications in a later PR after you've updated should_trace_content.

@nirga
Copy link
Member

nirga commented Mar 24, 2024

@Humbertzhang sure, thanks!

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.

🐛 Bug Report: Number of tokens not reported when streaming OpenAI/AOAI

2 participants