From 6ce493d4dfc2884832ff5b5be4479a55818b2fe7 Mon Sep 17 00:00:00 2001 From: H Lohaus Date: Sat, 16 Nov 2024 13:19:51 +0100 Subject: Fix api streaming, fix AsyncClient (#2357) * Fix api streaming, fix AsyncClient, Improve Client class, Some providers fixes, Update models list, Fix some tests, Update model list in Airforce provid er, Add OpenAi image generation url to api, Fix reload and debug in api arguments, Fix websearch in gui * Fix Cloadflare and Pi and AmigoChat provider * Fix conversation support in DDG provider, Add cloudflare bypass with nodriver * Fix unittests without curl_cffi --- etc/examples/api.py | 13 +++++++++---- etc/examples/image_api.py | 6 +++--- 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'etc/examples') 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 -- cgit v1.2.3