diff options
author | H Lohaus <hlohaus@users.noreply.github.com> | 2024-11-20 19:58:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-20 19:58:16 +0100 |
commit | ffb4b0d162cc29b1caa4539d854de37206804225 (patch) | |
tree | ea565c46ed908d2a6b4ef3fef1f100e68428aec3 /etc | |
parent | Update api.py (diff) | |
download | gpt4free-ffb4b0d162cc29b1caa4539d854de37206804225.tar gpt4free-ffb4b0d162cc29b1caa4539d854de37206804225.tar.gz gpt4free-ffb4b0d162cc29b1caa4539d854de37206804225.tar.bz2 gpt4free-ffb4b0d162cc29b1caa4539d854de37206804225.tar.lz gpt4free-ffb4b0d162cc29b1caa4539d854de37206804225.tar.xz gpt4free-ffb4b0d162cc29b1caa4539d854de37206804225.tar.zst gpt4free-ffb4b0d162cc29b1caa4539d854de37206804225.zip |
Diffstat (limited to 'etc')
-rw-r--r-- | etc/examples/api.py | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/etc/examples/api.py b/etc/examples/api.py index f8f5d5ec..2485bade 100644 --- a/etc/examples/api.py +++ b/etc/examples/api.py @@ -1,13 +1,17 @@ import requests import json +import uuid + url = "http://localhost:1337/v1/chat/completions" +conversation_id = str(uuid.uuid4()) body = { "model": "", - "provider": "", + "provider": "Copilot", "stream": True, "messages": [ - {"role": "user", "content": "What can you do? Who are you?"} - ] + {"role": "user", "content": "Hello, i am Heiner. How are you?"} + ], + "conversation_id": conversation_id } response = requests.post(url, json=body, stream=True) response.raise_for_status() @@ -21,4 +25,27 @@ for line in response.iter_lines(): print(json_data.get("choices", [{"delta": {}}])[0]["delta"].get("content", ""), end="") except json.JSONDecodeError: pass -print()
\ No newline at end of file +print() +print() +print() +body = { + "model": "", + "provider": "Copilot", + "stream": True, + "messages": [ + {"role": "user", "content": "Tell me somethings about my name"} + ], + "conversation_id": conversation_id +} +response = requests.post(url, json=body, stream=True) +response.raise_for_status() +for line in response.iter_lines(): + if line.startswith(b"data: "): + try: + 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
\ No newline at end of file |