-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatcmpl-gemini3-streaming.py
More file actions
51 lines (41 loc) · 1.55 KB
/
Copy pathchatcmpl-gemini3-streaming.py
File metadata and controls
51 lines (41 loc) · 1.55 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
from agents import Agent, ModelSettings, Runner, function_tool, OpenAIChatCompletionsModel
from openai.types.shared import Reasoning
from openai import AsyncOpenAI
import os
custom_client = AsyncOpenAI(
base_url="https://generativelanguage.googleapis.com/v1beta/openai/",
api_key=os.getenv("GEMINI_API_KEY")
)
my_model = OpenAIChatCompletionsModel(
model="gemini-3-pro-preview",
openai_client=custom_client,
)
@function_tool
def echo_tool(input: str) -> str:
print("called echo_tool !!!")
return input
agent = Agent(
name="Assistant",
instructions="You are a helpful assistant",
model=my_model,
tools=[echo_tool],
model_settings=ModelSettings(reasoning=Reasoning(effort="low"))
)
async def main():
result = Runner.run_streamed(
agent, """think about life, then use echo_tool
<tool_preambles>
- Always begin by rephrasing the user's goal in a friendly, clear, and concise manner, before calling any tools.
- Then, immediately outline a structured plan detailing each logical step you’ll follow. - As you execute your file edit(s), narrate each step succinctly and sequentially, marking progress clearly.
- Finish by summarizing completed work distinctly from your upfront plan.
</tool_preambles>"""
)
async for event in result.stream_events():
print(event, flush=True)
print("--------------------------------")
print(result.final_output)
print("================================")
print(result.to_input_list())
import asyncio
if __name__ == "__main__":
asyncio.run(main())