summaryrefslogtreecommitdiffstats
path: root/etc/examples
diff options
context:
space:
mode:
Diffstat (limited to 'etc/examples')
-rw-r--r--etc/examples/api.py13
-rw-r--r--etc/examples/image_api.py6
2 files changed, 12 insertions, 7 deletions
diff --git a/etc/examples/api.py b/etc/examples/api.py
index 1ab9b51b..f8f5d5ec 100644
--- a/etc/examples/api.py
+++ b/etc/examples/api.py
@@ -6,14 +6,19 @@ body = {
"provider": "",
"stream": True,
"messages": [
- {"role": "assistant", "content": "What can you do? Who are you?"}
+ {"role": "user", "content": "What can you do? Who are you?"}
]
}
-lines = requests.post(url, json=body, stream=True).iter_lines()
-for line in lines:
+response = requests.post(url, json=body, stream=True)
+response.raise_for_status()
+for line in response.iter_lines():
if line.startswith(b"data: "):
try:
- print(json.loads(line[6:]).get("choices", [{"delta": {}}])[0]["delta"].get("content", ""), end="")
+ json_data = json.loads(line[6:])
+ if json_data.get("error"):
+ print(json_data)
+ break
+ print(json_data.get("choices", [{"delta": {}}])[0]["delta"].get("content", ""), end="")
except json.JSONDecodeError:
pass
print() \ No newline at end of file
diff --git a/etc/examples/image_api.py b/etc/examples/image_api.py
index dbae22ed..9a438f9b 100644
--- a/etc/examples/image_api.py
+++ b/etc/examples/image_api.py
@@ -1,9 +1,9 @@
import requests
url = "http://localhost:1337/v1/images/generations"
body = {
- "prompt": "heaven for dogs",
- "provider": "OpenaiAccount",
- "response_format": "b64_json",
+ "model": "dall-e",
+ "prompt": "hello world user",
+ #"response_format": "b64_json",
}
data = requests.post(url, json=body, stream=True).json()
print(data) \ No newline at end of file