-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathswarm-ollama.py
58 lines (41 loc) · 1.29 KB
/
swarm-ollama.py
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 openai import OpenAI
from swarm import Swarm, Agent
client = OpenAI(
base_url="http://localhost:11434/v1",
api_key="ollama", # required, but unused
)
client = Swarm(client=client) # client is an instance of the Swarm class
def transfer_to_agent_b():
return agent_b
agent_a = Agent(
name="agent A",
model="llama3.2",
instructions="You are a helpful agent.",
functions=[transfer_to_agent_b],
)
agent_b = Agent(
name="agent B",
model="llama3.2",
instructions="Only speak in Haikus. and writes a haiku for the user.",
)
def run_demo_loop(agent_a, context_variables=None, stream=False, debug=False) -> None:
# client = Swarm(client=ollama_client)
print("Starting Ollama Swarm CLI 🐝")
messages = []
agent = agent_a
while True:
user_input = input("\033[90mUser\033[0m: ")
messages.append({"role": "user", "content": user_input})
response = client.run(
agent=agent,
messages=messages,
context_variables=context_variables or {},
stream=stream,
debug=debug,
)
res = response.messages
print(res[-1]["content"])
messages.extend(response.messages)
agent = response.agent
if __name__ == "__main__":
run_demo_loop(agent_a)