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

fix: Add support for output messages for sync/async #1188

Merged
merged 17 commits into from
Jan 15, 2025
Merged

Conversation

nate-mar
Copy link
Contributor

@nate-mar nate-mar commented Jan 13, 2025

resolves #1060

Screenshot 2025-01-13 at 1 11 37 AM

@nate-mar nate-mar requested a review from a team as a code owner January 13, 2025 07:57
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jan 13, 2025
@mikeldking
Copy link
Contributor

Possibly also resolves #1189

@nate-mar
Copy link
Contributor Author

The stream tests I added work in that the stream parameter works with the litellm client and the updated handling. However, the result provided by the litellm client when using a mock_response is not actually representative of how streaming will work in a normal setting unfortunately.

in actuality, the streamed chunks won't be populated automatically for the response. so I will need to remove the handling I added, as it only works for litellm client mocked responses. I will add a separate PR for streaming and will perhaps drop a note to the lite-lm maintainers to add some clarity around the client when using mock_response in the case of streaming.

@mikeldking
Copy link
Contributor

pinging @anticorrelator here to take a look

cc @nate-mar

@nate-mar
Copy link
Contributor Author

Github pushes are down atm so I can't push my latest changes. FYI

@nate-mar nate-mar changed the title fix: Add support for output messages for streaming/non-streaming and sync/async fix: Add support for output messages for sync/async Jan 14, 2025
@@ -31,6 +31,7 @@ dependencies = [
"openinference-instrumentation>=0.1.17",
"openinference-semantic-conventions>=0.1.9",
"wrapt",
"setuptools",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixes build error

@@ -39,6 +40,7 @@ test = [
"opentelemetry-sdk",
"opentelemetry-instrumentation-httpx",
"tenacity",
"tokenizers==0.20.3; python_version == '3.8'"
Copy link
Contributor Author

@nate-mar nate-mar Jan 14, 2025

Choose a reason for hiding this comment

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

fixes build error related to bad version of tokenizers that needed to be yanked. for now, force an earlier version pre-the bad version; related to huggingface/tokenizers#1691

@nate-mar
Copy link
Contributor Author

Possibly also resolves #1189

Yep, should resolve this too.

@anticorrelator
Copy link
Contributor

hi @nate-mar if we want to handle streaming it looks like we need to add another handler for the CustomStreamWrapper output type: https://github.com/BerriAI/litellm/blob/00f50bc2018eb45dd300e6d7d5ad8b3ab0ff5410/litellm/litellm_core_utils/streaming_handler.py#L59.

All of their streaming logic is there and we can hook into what they're already doing to instrument the stream (such as compiling the final streamed message and attaching it to our span).

Currently we don't handle this streaming return type and only handle ModelResponse: https://github.com/Arize-ai/openinference/blob/main/python/instrumentation/openinference-instrumentation-litellm/src/openinference/instrumentation/litellm/__init__.py#L155

@nate-mar
Copy link
Contributor Author

Sounds good @anticorrelator !

For now, if you wouldn't mind giving me a review on this one so we can get it across the line first, that'd be great. Thanks!

Copy link
Contributor

@anticorrelator anticorrelator left a comment

Choose a reason for hiding this comment

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

lgtm!

@nate-mar nate-mar merged commit 0bb96b6 into main Jan 15, 2025
3 checks passed
@nate-mar nate-mar deleted the add-output-messages branch January 15, 2025 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:M This PR changes 30-99 lines, ignoring generated files.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[bug][litellm] output message attributes are not instrumented for litellm
3 participants