diff options
| author | Martin Bielik <martin.bielik@instea.sk> | 2024-10-08 23:10:06 +0200 |
|---|---|---|
| committer | Martin Bielik <martin.bielik@instea.sk> | 2024-10-08 23:10:06 +0200 |
| commit | cefa3c1fa9ed73829b57f66829dd3138c315e0fa (patch) | |
| tree | 3a0879a387258ac4bd51ac3d39b5cb8be49de9c4 /py/chat.py | |
| parent | 758be522e6d765eeb78ce7681f4b39e3b05043b8 (diff) | |
| download | vim-ai-cefa3c1fa9ed73829b57f66829dd3138c315e0fa.tar.gz | |
support non streaming api
Diffstat (limited to '')
| -rw-r--r-- | py/chat.py | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -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) |