summaryrefslogtreecommitdiffstats
path: root/etc/examples/api.py
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2024-04-20 20:12:36 +0200
committerGitHub <noreply@github.com>2024-04-20 20:12:36 +0200
commitda81d1e51aa5c625e4107bf8148cdb3c778f4001 (patch)
tree01b7677bfd51667e6b8bebe0ac72921aa48cba58 /etc/examples/api.py
parentMerge pull request #1862 from hlohaus/nem (diff)
parentDisable Bing integration test (diff)
downloadgpt4free-da81d1e51aa5c625e4107bf8148cdb3c778f4001.tar
gpt4free-da81d1e51aa5c625e4107bf8148cdb3c778f4001.tar.gz
gpt4free-da81d1e51aa5c625e4107bf8148cdb3c778f4001.tar.bz2
gpt4free-da81d1e51aa5c625e4107bf8148cdb3c778f4001.tar.lz
gpt4free-da81d1e51aa5c625e4107bf8148cdb3c778f4001.tar.xz
gpt4free-da81d1e51aa5c625e4107bf8148cdb3c778f4001.tar.zst
gpt4free-da81d1e51aa5c625e4107bf8148cdb3c778f4001.zip
Diffstat (limited to '')
-rw-r--r--etc/examples/api.py19
1 files changed, 19 insertions, 0 deletions
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