@@ -223,38 +223,34 @@ def chat_gpt(prompt):
223
223
messages .append ({" role" : " user" , " content" : prompt })
224
224
messages .insert (0 , systemCtx)
225
225
226
- try :
227
- client = create_client ()
228
- response = client.chat.completions.create (
229
- model= model,
230
- messages = messages ,
231
- temperature= temperature,
232
- max_tokens= max_tokens,
233
- stream= True
234
- )
235
-
236
- # Iterate through the response chunks
237
- for chunk in response:
238
- # newer Azure API responses contain empty chunks in the first streamed
239
- # response
240
- if not chunk.choices:
241
- continue
242
-
243
- chunk_session_id = session_id if session_id else chunk.id
244
- choice = chunk.choices[0 ]
245
- finish_reason = choice.finish_reason
226
+ client = create_client ()
227
+ response = client.chat.completions.create (
228
+ model= model,
229
+ messages = messages ,
230
+ temperature= temperature,
231
+ max_tokens= max_tokens,
232
+ stream= True
233
+ )
234
+
235
+ # Iterate through the response chunks
236
+ for chunk in response:
237
+ # newer Azure API responses contain empty chunks in the first streamed
238
+ # response
239
+ if not chunk.choices:
240
+ continue
241
+
242
+ chunk_session_id = session_id if session_id else chunk.id
243
+ choice = chunk.choices[0 ]
244
+ finish_reason = choice.finish_reason
245
+
246
+ # Call DisplayChatGPTResponse with the finish_reason or content
247
+ if finish_reason:
248
+ vim .command (" call DisplayChatGPTResponse('', '{0}', '{1}')" .format (finish_reason.replace (" '" , " ''" ), chunk_session_id))
249
+ elif choice.delta:
246
250
content = choice.delta.content
251
+ vim .command (" call DisplayChatGPTResponse('{0}', '', '{1}')" .format (content.replace (" '" , " ''" ), chunk_session_id))
247
252
248
- # Call DisplayChatGPTResponse with the finish_reason or content
249
- if finish_reason:
250
- vim .command (" call DisplayChatGPTResponse('', '{0}', '{1}')" .format (finish_reason.replace (" '" , " ''" ), chunk_session_id))
251
- elif content:
252
- vim .command (" call DisplayChatGPTResponse('{0}', '', '{1}')" .format (content.replace (" '" , " ''" ), chunk_session_id))
253
-
254
- vim .command (" redraw" )
255
-
256
- except Exception as e :
257
- print (" Error:" , str (e ))
253
+ vim .command (" redraw" )
258
254
259
255
chat_gpt (vim .eval (' a:prompt' ))
260
256
EOF
0 commit comments