| | |
| | def get_history_from_prompt(prompt:str): |
| | if "Here are previous chats for your reference (only use this if you need further information to infer the intent):" in prompt: |
| | history = prompt.split("Here are previous chats for your reference (only use this if you need further information to infer the intent):") |
| | else: |
| | history = prompt.split("Here are previous chats or summary conversation for your reference (only use this if you need further information to infer the intent):") |
| | return history[1].replace("""The Intent:""", '') |
| |
|
| | def get_latest_user_input_from_prompt(prompt:str): |
| | input = prompt.split("Here is the message you are to classify:") |
| | if "Here are previous chats for your reference (only use this if you need further information to infer the intent):" in prompt: |
| | input = input[1].split("Here are previous chats for your reference (only use this if you need further information to infer the intent):") |
| | else: |
| | input = input[1].split("Here are previous chats or summary conversation for your reference (only use this if you need further information to infer the intent)") |
| | return input[0] |
| |
|
| | |
| | def get_top_intents(intent_list:list, similarity, n=5, threshold=0.3, flow=None) -> str: |
| | result = dict() |
| | for i in range(len(intent_list)): |
| | if flow: |
| | if intent_list[i] in flow: |
| | |
| | if similarity[i].item() > threshold: |
| | result[intent_list[i]] = similarity[i].item() |
| | else: |
| | if similarity[i].item() > threshold: |
| | result[intent_list[i]] = similarity[i].item() |
| |
|
| | top_intents = sorted(result.items(), key=lambda item: item[1], reverse=True)[:n] |
| |
|
| | if not top_intents: |
| | top_intents.append(('unknown', 1.0)) |
| | return top_intents |
| |
|
| | def create_embedding(intents:dict, model_en): |
| | intents_description_en = [] |
| | for k,v in intents.items(): |
| | intents_description_en.append(v) |
| | intents_embedding = model_en.encode(intents_description_en) |
| | return intents_embedding |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|