From cefa3c1fa9ed73829b57f66829dd3138c315e0fa Mon Sep 17 00:00:00 2001 From: Martin Bielik Date: Tue, 8 Oct 2024 23:10:06 +0200 Subject: support non streaming api --- py/chat.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'py/chat.py') 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) -- cgit v1.2.3