Update project/bot/openai_backend.py
Browse files
project/bot/openai_backend.py
CHANGED
@@ -96,7 +96,7 @@ class SearchBot:
|
|
96 |
|
97 |
@staticmethod
|
98 |
async def _get_context_data(user_query: list[float]) -> list[dict]:
|
99 |
-
radius =
|
100 |
_, distances, indices = settings.FAISS_INDEX.range_search(user_query, radius)
|
101 |
indices_distances_df = pd.DataFrame({'index': indices, 'distance': distances})
|
102 |
filtered_data_df = settings.products_dataset.iloc[indices].copy()
|
@@ -104,14 +104,17 @@ class SearchBot:
|
|
104 |
sorted_data_df: pd.DataFrame = filtered_data_df.sort_values(by='distance').reset_index(drop=True)
|
105 |
sorted_data_df = sorted_data_df.drop('distance', axis=1)
|
106 |
data = sorted_data_df.head(3).to_dict(orient='records')
|
107 |
-
|
|
|
|
|
|
|
|
|
108 |
|
109 |
@staticmethod
|
110 |
async def create_context_str(context: List[Dict]) -> str:
|
111 |
context_str = ''
|
112 |
for i, chunk in enumerate(context):
|
113 |
-
|
114 |
-
context_str += f'{i + 1}) {chunk["chunks"]}'
|
115 |
return context_str
|
116 |
|
117 |
async def _rag(self, context: List[Dict], query: str, session: AsyncSession, country: str):
|
|
|
96 |
|
97 |
@staticmethod
|
98 |
async def _get_context_data(user_query: list[float]) -> list[dict]:
|
99 |
+
radius = 4
|
100 |
_, distances, indices = settings.FAISS_INDEX.range_search(user_query, radius)
|
101 |
indices_distances_df = pd.DataFrame({'index': indices, 'distance': distances})
|
102 |
filtered_data_df = settings.products_dataset.iloc[indices].copy()
|
|
|
104 |
sorted_data_df: pd.DataFrame = filtered_data_df.sort_values(by='distance').reset_index(drop=True)
|
105 |
sorted_data_df = sorted_data_df.drop('distance', axis=1)
|
106 |
data = sorted_data_df.head(3).to_dict(orient='records')
|
107 |
+
cleaned_data = []
|
108 |
+
for chunk in data:
|
109 |
+
if "Comments:" in chunk['chunks']:
|
110 |
+
cleaned_data.append(chunk)
|
111 |
+
return cleaned_data
|
112 |
|
113 |
@staticmethod
|
114 |
async def create_context_str(context: List[Dict]) -> str:
|
115 |
context_str = ''
|
116 |
for i, chunk in enumerate(context):
|
117 |
+
context_str += f'{i + 1}) {chunk["chunks"]}'
|
|
|
118 |
return context_str
|
119 |
|
120 |
async def _rag(self, context: List[Dict], query: str, session: AsyncSession, country: str):
|