diff options
author | H Lohaus <hlohaus@users.noreply.github.com> | 2024-11-16 13:19:51 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-16 13:19:51 +0100 |
commit | 6ce493d4dfc2884832ff5b5be4479a55818b2fe7 (patch) | |
tree | 92e9efce62f7832ebe56969c120d8e92e75881a3 /etc/examples | |
parent | Update internet.py (diff) | |
download | gpt4free-6ce493d4dfc2884832ff5b5be4479a55818b2fe7.tar gpt4free-6ce493d4dfc2884832ff5b5be4479a55818b2fe7.tar.gz gpt4free-6ce493d4dfc2884832ff5b5be4479a55818b2fe7.tar.bz2 gpt4free-6ce493d4dfc2884832ff5b5be4479a55818b2fe7.tar.lz gpt4free-6ce493d4dfc2884832ff5b5be4479a55818b2fe7.tar.xz gpt4free-6ce493d4dfc2884832ff5b5be4479a55818b2fe7.tar.zst gpt4free-6ce493d4dfc2884832ff5b5be4479a55818b2fe7.zip |
Diffstat (limited to 'etc/examples')
-rw-r--r-- | etc/examples/api.py | 13 | ||||
-rw-r--r-- | etc/examples/image_api.py | 6 |
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 |