From 83484c0a5658b023bcef930aee5099a4fc059cb4 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Sat, 20 Apr 2024 15:41:49 +0200 Subject: Add workers and use_colors options to api --- etc/examples/api.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 etc/examples/api.py (limited to 'etc/examples/api.py') diff --git a/etc/examples/api.py b/etc/examples/api.py new file mode 100644 index 00000000..d4d03a77 --- /dev/null +++ b/etc/examples/api.py @@ -0,0 +1,19 @@ +import requests +import json +url = "http://localhost:1337/v1/chat/completions" +body = { + "model": "", + "provider": "MetaAI", + "stream": True, + "messages": [ + {"role": "assistant", "content": "What can you do? Who are you?"} + ] +} +lines = requests.post(url, json=body, stream=True).iter_lines() +for line in lines: + if line.startswith(b"data: "): + try: + print(json.loads(line[6:]).get("choices", [{"delta": {}}])[0]["delta"].get("content", ""), end="") + except json.JSONDecodeError: + pass +print() \ No newline at end of file -- cgit v1.2.3