First AI API. #4

Merged
YasinOnm08 merged 1 commit from React-Group/ai-virtual-assistant:main into main 2024-09-16 10:29:52 +02:00
Showing only changes of commit 7cdcc35a2a - Show all commits

View file

@ -1,7 +1,29 @@
import requests import requests
import json
class api: class api:
def initialize_ollama(self, prompt):
ollama_url = "http://localhost:11434"
model = "phi3.5"
def send_message(message): response = requests.post(
answer = "Test" f"{ollama_url}/api/generate", json={"model": model, "prompt": prompt}
return answer )
if response.status_code == 200:
response_data = []
for line in response.iter_lines():
line_decoded = line.decode("utf-8")
line_raw = json.loads(line_decoded)
response_data.append(line_raw["response"])
final_response = "".join(response_data)
generated_text = final_response.splitlines()[-1]
return generated_text
else:
return "Error: " + response.text
def send_message(self, message):
answer = self.initialize_ollama(message)
return answer