Skip to content

Commit

Permalink
handle emptyness
Browse files Browse the repository at this point in the history
  • Loading branch information
bassner committed Jan 21, 2025
1 parent 92512b1 commit 3c97cae
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/pipeline/chat_gpt_wrapper_pipeline.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import logging
from typing import List, Optional

Expand Down Expand Up @@ -80,9 +81,16 @@ def __call__(
],
)

prompts = [pyris_system_prompt] + dto.chat_history
prompts = [pyris_system_prompt] + [msg for msg in dto.chat_history if msg.contents is not None and len(msg.contents) > 0 and msg.contents[0].text_content and len(msg.contents[0].text_content) > 0]

response = self.request_handler.chat(
prompts, CompletionArguments(temperature=0.5, max_tokens=2000)
)

logger.info(f"ChatGPTWrapperPipeline response: {response}")

if response.contents is None or len(response.contents) == 0 or response.contents[0].text_content is None or len(response.contents[0].text_content) == 0:
self.callback.error("ChatGPT did not reply. Try resending.")
return

self.callback.done(final_result=response.contents[0].text_content)

0 comments on commit 3c97cae

Please sign in to comment.