Created
May 14, 2024 14:08
-
-
Save sphaero/3360c0393491f468a2844d528358aaa9 to your computer and use it in GitHub Desktop.
Ollama Actor. Just a sample ollama Gazebosc Python actor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import urllib.request | |
import urllib.parse | |
data = { | |
"model": "llama3", | |
"prompt": "Why is the sky blue?", | |
"stream": False | |
} | |
class apitest(object): | |
def __init__(self, *args, **kwargs): | |
self.url = "http://10.2.4.9:11434/api/generate" | |
def handleSocket(self, address, data, *args, **kwargs): | |
print(address, data) | |
data = { | |
"model": "llama3", | |
"prompt": "Why is the sky blue?", | |
"stream": False | |
} | |
data_json = json.dumps(data).encode("utf-8") | |
req = urllib.request.Request(self.url, data=data_json, method="POST") | |
req.add_header("Content-Type", "application/json") | |
answer = None | |
with urllib.request.urlopen(req) as response: | |
answer = json.loads(response.read().decode("utf-8")) | |
#print(answer["response"]) | |
if answer.get("response"): | |
return ("/answer", [answer.get("response")]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment