Skip to content

Commit

Permalink
Update litellm example
Browse files Browse the repository at this point in the history
  • Loading branch information
kxtran committed Feb 11, 2025
1 parent 6ec73fd commit 3cd9636
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
39 changes: 37 additions & 2 deletions examples/logging/litellm_async_stream_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/log10/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down

0 comments on commit 3cd9636

Please sign in to comment.