-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCHECK_QUARY.py
More file actions
35 lines (27 loc) · 1.23 KB
/
CHECK_QUARY.py
File metadata and controls
35 lines (27 loc) · 1.23 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
import requests
import json
import re
#setting up ollama details
model = open("OLLAMA_MODEL").read()
prompt = f"using this info'{open("SEARCH_RESULTS").read()}', is this statment correct? '{open("UNPROCCESSED_TEXT").read()}. answer in only a true or false. not one word more, i don't need any explaination or how you deducted that answer. just a true or false. write 1 for true and 0 for false. if you answer is one word more than 0 or 1. the proggram will fail'"
url = "http://localhost:11434/api/generate"
data = {
"model": model,
"prompt": prompt,
}
#Generating responce
response = requests.post(url, json = data, stream = True)
def Check_Quary():
final_text = ""
for line in response.iter_lines():
if line:
msg = json.loads(line)
if "response" in msg:
final_text += msg["response"]
# print(msg["response"], end="", flush=True)
# print(re.sub(r"<think>.*?</think>", "", final_text, flags=re.DOTALL), end="", flush=True)
if msg.get("done"):
final_text = re.sub(r"<think>.*?</think>", "", final_text, flags=re.DOTALL)
#if __name__ == "__main__":
#print(final_text)
return final_text