class UserRequest(BaseModel):
message: str
max_tokens: int = 1000
temperature: float = 0.9
system_msg: str = "You are an expert to answer"
presence_penalty: float = 0
frequency_penalty: float = 0
persist_directory: str = "none"
uid: int = 0
llmtype: str="gpt-3.5-turbo"
def classify_intent(msg):
prompt = f"""Forget all your previous instructions. Your job is to classify intent.
Choose one of the following intents:
- the terminologies of fortune telling
- telling about personal fortune
- Consulting on personal plan
- Historical events
- etc.
Please don't make new intent except for the above examples.
User: {msg}
Intent:
"""
messages=[ {"role": "user", "content": prompt}, ]
try:
response = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=messages)
return response.choices[0].message.content.strip()
except:
response = client.chat.completions.create(model="solar-1-mini-chat",
messages=messages)
return response.choices[0].message.content.strip()
@app.post("/customerintention")
def chat_intention(req: UserRequest):
context = req.dict()
intent = classify_intent(req.message)
if(any(keyword in req.message for keyword in keywordlist)):
message = "사전 정의된 keyword, value set에서 답변을 가져옵니다."
elif intent == "travel_plan":
response = openai.ChatCompletion.create(model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": req.system_msg},
{"role": "user", "content": req.message},
],
temperature=req.temperature)
message=response.choices[0].message.content
elif intent == "customer_support":
context["related_database"] = query_db(query=req.message, directory='cs_docx')
message= rag1_chain.run(context)
elif intent == "reservation":
message="Here is reservation number: 0987654321"
else:
message = intent
return { "answer": message }