Skip to content

Commit

Permalink
fixed unpack issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sfahad1414 committed Apr 26, 2023
1 parent b532048 commit 6b7bdc5
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions kairon/shared/nlu/classifier/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class OpenAIClassifier(IntentClassifier):
"top_k": 5,
"temperature": 0.0,
"max_tokens": 50,
"retry": 3
}

system_prompt = "You are an intent classifier. Based on the users prompt, you will classify the prompt to one of the intent if it is not from one of the stories you will classify it as nlu_fallback. Also provide the explanation why particular intent is classified."
Expand Down Expand Up @@ -110,7 +111,7 @@ def predict(self, text):
retry = 0
intent = None
explanation = None
while retry < 3:
while retry < self.component_config.get("retry", 3):
try:
response = openai.ChatCompletion.create(
model=self.component_config.get("prediction_model", "gpt-4"),
Expand All @@ -123,11 +124,14 @@ def predict(self, text):
stop=["\n\n"],
api_key=self.api_key
)
intent_str, explanation_str = response.choices[0]['message']['content'].split('\n')
intent = intent_str.split(':')[1].strip()
explanation = explanation_str.split(':')[1].strip()
intent = None
explanation = None
responses = response.choices[0]['message']['content'].split('\n')
intent = responses[0].split(':')[1].strip()
if len(responses) == 2:
explanation = responses[1].split(':')[1].strip()
break
except Exception as e:
except TimeoutError as e:
logger.error(e)
retry += 1
if retry == 3:
Expand Down

0 comments on commit 6b7bdc5

Please sign in to comment.