-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2289 from Agenta-AI/fix/litellm-streaming-warnings
[Fix] litellm streaming warnings
- Loading branch information
Showing
2 changed files
with
89 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...a-cli/tests/observability_sdk/integrations/litellm/03_agenta_implementationa_streaming.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import litellm | ||
import agenta as ag | ||
|
||
|
||
ag.init() | ||
|
||
|
||
@ag.instrument() | ||
async def agenerate_completion(): | ||
litellm.callbacks = [ag.callbacks.litellm_handler()] | ||
|
||
messages = [ | ||
{ | ||
"role": "user", | ||
"content": "Hey, how's it going? please respond in a in German.", | ||
} | ||
] | ||
|
||
response = await litellm.acompletion( | ||
model="gpt-4-turbo", | ||
messages=messages, | ||
stream=True, | ||
) | ||
|
||
chat_completion = "" | ||
async for part in response: | ||
print(part.choices[0].delta.content) | ||
chat_completion += part.choices[0].delta.content or "" | ||
|
||
print(chat_completion) | ||
|
||
return chat_completion | ||
|
||
|
||
@ag.instrument() | ||
def generate_completion(): | ||
litellm.callbacks = [ag.callbacks.litellm_handler()] | ||
|
||
messages = [ | ||
{ | ||
"role": "user", | ||
"content": "Hey, how's it going? please respond in a in Spanish.", | ||
} | ||
] | ||
|
||
response = litellm.completion( | ||
model="gpt-4-turbo", | ||
messages=messages, | ||
stream=True, | ||
) | ||
|
||
chat_completion = "" | ||
for part in response: | ||
print(part.choices[0].delta.content) | ||
chat_completion += part.choices[0].delta.content or "" | ||
|
||
print(chat_completion) | ||
|
||
return chat_completion | ||
|
||
|
||
if __name__ == "__main__": | ||
import asyncio | ||
|
||
asyncio.run(agenerate_completion()) | ||
# generate_completion() |