chunk.usage is not None, but i can not found the usage information in web UI.
from openai import AsyncOpenAI
import os
from dotenv import load_dotenv
load_dotenv()
import weave
import asyncio
weave.init("llamaindex-test")
async def main():
response = await AsyncOpenAI(
api_key=os.environ['DS_API_KEY'],
base_url="https://api.deepseek.com"
).chat.completions.create(
model="deepseek-chat",
messages=[{"role": "user", "content": "Hello, how are you?"}],
stream=True,
stream_options={"include_usage": True},
temperature=0.1,
tool_choice="auto",
tools=[
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description":"The city and state, e.g. San Francisco, CA",
}
}
}
}
}
]
)
full_response = []
async for chunk in response:
if chunk.usage is not None:
usage_data = chunk.usage
content = chunk.choices[0].delta.content
if content:
print(content, end="", flush=True)
full_response.append(content)
asyncio.run(main())