-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlitellm-deepseek.py
More file actions
58 lines (46 loc) · 1.68 KB
/
litellm-deepseek.py
File metadata and controls
58 lines (46 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from agents import Agent, ModelSettings, Runner, function_tool
from agents.extensions.models.litellm_model import LitellmModel
from openai.types.shared import Reasoning
import os
@function_tool
def echo_tool(input: str) -> str:
return input
@function_tool
def speak_tool(input: str) -> str:
return input
@function_tool
def final_tool(input: str) -> str:
return input
model = LitellmModel(
model="deepseek/deepseek-reasoner",
api_key=os.getenv("DEEPSEEK_API_KEY")
)
agent = Agent(
name="Assistant",
instructions="You are a helpful assistant",
model=model,
tools=[echo_tool, speak_tool, final_tool],
# model_settings=ModelSettings(reasoning=Reasoning(effort="low"))
#model_settings=ModelSettings(
# extra_body={"thinking": {"type": "enabled"}}
#)
)
print("================================================ Turn 1")
result = Runner.run_sync(
agent, "think about life, then use echo_tool and speak_tool"
)
print(result.final_output)
print("----------")
print(result.to_input_list())
messages = result.to_input_list()
print("================================================ Turn 2")
messages.append( { "role": "user", "content": "summarize the above content, then use final_tool"})
result = Runner.run_sync(
agent, messages
)
print(result.final_output)
print("----------")
print(result.to_input_list())
# 2025/12/6 error
# litellm.llms.openai.common_utils.OpenAIError: {"error":{"message":"Missing `reasoning_content` field in the assistant message at
# message index 2. For more information, please refer to https://api-docs.deepseek.com/guides/thinking_mode#tool-calls","type":"invalid_request_error","param":null,"code":"invalid_request_error"}}