-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathollama_example.py
More file actions
38 lines (29 loc) · 871 Bytes
/
ollama_example.py
File metadata and controls
38 lines (29 loc) · 871 Bytes
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
import ollama
import asyncio
import requests
from rich import print
async def run(model: str):
client = ollama.AsyncClient()
messages = [
{
"role": "user",
"content": "Find open ports on 127.0.0.1",
}
]
response = await client.chat(
model=model,
messages=messages,
# get the tools from the Robopages server
tools=requests.get("http://localhost:8000/").json(),
)
print(response)
# if the response contains tool calls
if response["message"]["tool_calls"]:
# execute them via the API
results = requests.post(
"http://localhost:8000/process", json=response["message"]["tool_calls"]
)
results.raise_for_status()
# do whatever you want with the results
print(results.json())
asyncio.run(run("llama3.1"))