summaryrefslogtreecommitdiff
path: root/py/chat.py
diff options
context:
space:
mode:
authorMartin Bielik <martin.bielik@instea.sk>2024-10-08 23:10:06 +0200
committerMartin Bielik <martin.bielik@instea.sk>2024-10-08 23:10:06 +0200
commitcefa3c1fa9ed73829b57f66829dd3138c315e0fa (patch)
tree3a0879a387258ac4bd51ac3d39b5cb8be49de9c4 /py/chat.py
parent758be522e6d765eeb78ce7681f4b39e3b05043b8 (diff)
downloadvim-ai-cefa3c1fa9ed73829b57f66829dd3138c315e0fa.tar.gz
support non streaming api
Diffstat (limited to '')
-rw-r--r--py/chat.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/py/chat.py b/py/chat.py
index 67f2d5d..4850bae 100644
--- a/py/chat.py
+++ b/py/chat.py
@@ -71,16 +71,23 @@ try:
vim.command("redraw")
request = {
- 'stream': True,
'messages': messages,
**openai_options
}
printDebug("[chat] request: {}", request)
url = options['endpoint_url']
response = openai_request(url, request, http_options)
- def map_chunk(resp):
+
+ def map_chunk_no_stream(resp):
+ printDebug("[chat] response: {}", resp)
+ return resp['choices'][0]['message'].get('content', '')
+
+ def map_chunk_stream(resp):
printDebug("[chat] response: {}", resp)
return resp['choices'][0]['delta'].get('content', '')
+
+ map_chunk = map_chunk_stream if openai_options['stream'] else map_chunk_no_stream
+
text_chunks = map(map_chunk, response)
render_text_chunks(text_chunks, is_selection)