diff --git a/examples/logging/litellm_async_stream_completion.py b/examples/logging/litellm_async_stream_completion.py index a1d84a3..0d4daa4 100644 --- a/examples/logging/litellm_async_stream_completion.py +++ b/examples/logging/litellm_async_stream_completion.py @@ -8,12 +8,47 @@ log10_handler = Log10LitellmLogger(tags=["litellm_acompletion"]) litellm.callbacks = [log10_handler] -model_name = "claude-3-haiku-20240307" +model_name = "gemini/gemini-2.0-flash" async def completion(): response = await litellm.acompletion( - model=model_name, messages=[{"role": "user", "content": "count to 10"}], stream=True + model=model_name, + messages=[ + { + "role": "system", + "content": "You are a helpful math tutor. Guide the user through the solution step by step.", + }, + {"role": "user", "content": "how can I solve 8x + 7 = -23"}, + ], + response_format={ + "type": "json_schema", + "json_schema": { + "name": "math_response", + "strict": True, + "schema": { + "type": "object", + "properties": { + "steps": { + "type": "array", + "items": { + "type": "object", + "properties": { + "explanation": {"type": "string"}, + "output": {"type": "string"}, + }, + "required": ["explanation", "output"], + "additionalProperties": False, + }, + }, + "final_answer": {"type": "string"}, + }, + "required": ["steps", "final_answer"], + "additionalProperties": False, + }, + }, + }, + stream=True, ) async for chunk in response: if chunk.choices[0].delta.content: diff --git a/src/log10/llm.py b/src/log10/llm.py index 36770c9..55550c8 100644 --- a/src/log10/llm.py +++ b/src/log10/llm.py @@ -4,12 +4,12 @@ import re import traceback from abc import ABC +from copy import deepcopy from enum import Enum from typing import List, Optional from urllib.parse import urljoin, urlparse import requests -from copy import deepcopy Role = Enum("Role", ["system", "assistant", "user"])