Skip to content

Commit

Permalink
Merge pull request #31 from microsoft/won
Browse files Browse the repository at this point in the history
Fix issues failing open_ai2 call
  • Loading branch information
WonSong authored Sep 17, 2024
2 parents 75ce904 + 6a013f4 commit a646830
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
5 changes: 0 additions & 5 deletions Server/modules/career_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ def __process_game__(self, conversation_id):
if open_ai_response is None:
continue

if type(open_ai_response) == str and open_ai_response.startswith("```") and open_ai_response.endswith("```"):
open_ai_response = open_ai_response.strip(
"```json").strip()
open_ai_response = json.loads(open_ai_response)

self.message_history.append_assistant_message(
conversation_id, open_ai_response)

Expand Down
8 changes: 5 additions & 3 deletions Server/modules/open_ai2.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ def chat(self, messageContext="", requiredWords=[], number_of_responses=1, attem
).choices
for response in allResponses:
content = response.message['content']
content_dict = dict()
try:
content_dict = json.loads(content)
if type(content) == str and content.startswith("```") and content.endswith("```"):
content = content.strip(
"```json").strip()
content = json.loads(content)
except json.JSONDecodeError:
continue
if all(word in content for word in requiredWords):
return content_dict
return content
except openai.error.OpenAIError as e:
print(e=f"Attempt {i+1} failed with error: {e}")
continue
Expand Down

0 comments on commit a646830

Please sign in to comment.