Closed 7flash closed 7 months ago
@7flash you can use open ai blocks for it. @baptisteArno am I right? Is there a better way?
Indeed, you can definitely do that with a AI completion block. See the OpenAI condition template for an example of that
I mean with vector embeddings? @baptisteArno
It's also called semantic router can be done like this
message_to_intent = {
'how much money i have?': 'show balance',
'hi there': 'show greetings'
}
for message in message_to_intent.keys():
similarity = cosine_similarity(user_msg_embedding, generate_embedding(message))
intent = message_to_intent[message]
if intent in similarities:
similarities[intent]['sum'] += similarity
similarities[intent]['count'] += 1
else:
similarities[intent] = {'sum': similarity, 'count': 1}
average_similarities = [(intent, similarities[intent]['sum'] / similarities[intent]['count']) for intent in similarities]
top_intent = sorted(average_similarities, key=lambda x: x[1], reverse=True)[0]
if top_intent == 'show balance':
# ...
else:
# ...
That's not supported for now!
Currently I can branch out the conversation based on exact user input, but now I'd also like to be able approximate user message(even when written with typos) to one of available categories of intent and handle correspondingly