2
2
from baml_handlers .extract_product_information_from_message_handler import extract_product_information_from_message
3
3
from models .request .create_chat_message_request import CreateChatMessageRequest
4
4
from models .response .create_chat_message_response import CreateChatMessageResponse
5
- from models .request .get_product_price_range_request import GetProductPriceRangeRequest
5
+ from models .request .get_products_in_price_range_request import GetProductsInPriceRangeRequest
6
6
from core .similarity_helper import *
7
- from database .data_helpers import *
7
+ from database .data_helpers import is_product_description_valid , is_price_range_valid , apply_mask_for_df , get_products_summary
8
8
from database .in_memory_db import products_embeddings
9
9
from core .constants import AssistantMessages
10
+ from core .constants import *
10
11
11
12
@app .post ("/v1/chat/message/" )
12
13
async def handle_new_chat_message_from_user (request : CreateChatMessageRequest ):
13
14
extracted_chat_gpt_request = await extract_product_information_from_message (request .text )
14
15
product_description = extracted_chat_gpt_request .description
15
16
product_price_range = extracted_chat_gpt_request .price_range
17
+ global products
16
18
products = products_embeddings
17
19
filter_was_active = False
18
20
@@ -24,7 +26,7 @@ async def handle_new_chat_message_from_user(request: CreateChatMessageRequest):
24
26
products = apply_mask_for_df (products , product_price_range )
25
27
filter_was_active = True
26
28
27
- if len (products ) is 0 or filter_was_active is False :
29
+ if len (products ) == 0 or filter_was_active is False :
28
30
return CreateChatMessageResponse (text = AssistantMessages .ASSISTANT_MESSAGE_PRODUCT_SIMILARITY_SEARCH_FAILURE )
29
31
30
32
product_summary = get_products_summary (products )
@@ -35,7 +37,7 @@ async def handle_product_description_request(request: CreateChatMessageRequest):
35
37
extracted_chat_gpt_request = await extract_product_information_from_message (request .text )
36
38
product_description = extracted_chat_gpt_request .description
37
39
38
- if not is_product_description_valid (product_description ):
40
+ if is_product_description_valid (product_description ) is False :
39
41
return CreateChatMessageResponse (text = AssistantMessages .ASSISTANT_MESSAGE_INVALID_DESCRIPTION )
40
42
41
43
products = get_similarity_df (product_description , products_embeddings , request .similarities_results_max_count , request .similarities_results_threshold , OPENAI .EMBEDDING_MODEL )
@@ -46,16 +48,16 @@ async def handle_product_description_request(request: CreateChatMessageRequest):
46
48
return CreateChatMessageResponse (text = product_summary )
47
49
48
50
@app .post ("/v1/chat/product/price/" )
49
- async def handle_product_price_range_request (request : GetProductPriceRangeRequest ):
51
+ async def handle_product_price_range_request (request : GetProductsInPriceRangeRequest ):
50
52
extracted_chat_gpt_request = await extract_product_information_from_message (request .text )
51
53
product_price_range = extracted_chat_gpt_request .price_range
52
54
53
- if not is_price_range_valid (product_price_range ):
55
+ if is_price_range_valid (product_price_range ) is False :
54
56
return CreateChatMessageResponse (text = AssistantMessages .ASSISTANT_MESSAGE_INVALID_PRICE_RANGE )
55
57
56
58
products = apply_mask_for_df (products_embeddings , product_price_range )
57
59
if len (products ) == 0 :
58
- return CreateChatMessageResponse (text = AssistantMessages .ASSISTANT_MESSAGE_PRODUCT_SIMILARITY_SEARCH_FAILURE )
60
+ return CreateChatMessageResponse (text = AssistantMessages .ASSISTANT_MESSAGE_INVALID_PRICE_RANGE )
59
61
60
62
product_summary = get_products_summary (products )
61
63
return CreateChatMessageResponse (text = product_summary )
0 commit comments