-
Notifications
You must be signed in to change notification settings - Fork 0
/
ask_ollama.py
35 lines (27 loc) · 972 Bytes
/
ask_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
import argparse
import requests
import json
def main():
parser = argparse.ArgumentParser(description="A simple API client for an inference service.")
parser.add_argument("model", help="The model you want to use. It must be installed on your system.")
parser.add_argument("question", help="The question to ask.")
args = parser.parse_args()
url = "http://inference.weninger.local:11434/api/generate"
headers = {
"Content-Type": "application/json"
}
data = {
"model": args.model,
"prompt": args.question,
"stream": False
}
response = requests.post(url, headers=headers, data=json.dumps(data))
if response.status_code == 200:
response_text = response.text
data = json.loads(response_text)
actual_response = data["response"]
print(actual_response)
else:
print("Error:", response.status_code, response.text)
if __name__ == "__main__":
main()