|
2 | 2 | from api.db.pg_database import SessionLocal |
3 | 3 | from api.Assistant.assistant_repository import get_all_assistants, get_assistant_by_id_repository, delete_assistant_repository, update_assistant_repository |
4 | 4 | from api.Assistant.assistant_response_model import AssistantRequest, AssistantResponse, AssistantInfoResponse, AssistantListItemResponse, ContextResponse, UpdateAssistantRequest |
| 5 | +from api.search.search_service import get_search_texts_details |
5 | 6 | from api.Assistant.assistant_repository import create_assistant_repository |
6 | 7 | from typing import List |
7 | 8 | from api.Assistant.assistant_model import Assistant, Context |
@@ -75,10 +76,14 @@ async def create_assistant_service(token: str, assistant_request: AssistantReque |
75 | 76 | current_user_email = validate_and_extract_user_email(token=token) |
76 | 77 | contexts_list = [] |
77 | 78 | for ctx in assistant_request.contexts: |
| 79 | + if ctx.pecha_text_id: |
| 80 | + search_details = await get_search_texts_details(ctx.pecha_text_id) |
| 81 | + content = "\n\n".join([detail.content for detail in search_details]) if search_details else "" |
| 82 | + else: |
| 83 | + content = ctx.content |
78 | 84 | contexts_list.append( |
79 | | - Context(content=ctx.content, pecha_title=ctx.pecha_title, pecha_text_id=ctx.pecha_text_id) |
| 85 | + Context(content=content, pecha_title=ctx.pecha_title, pecha_text_id=ctx.pecha_text_id) |
80 | 86 | ) |
81 | | - |
82 | 87 | if files: |
83 | 88 | for file in files: |
84 | 89 | if file.filename: |
@@ -159,10 +164,17 @@ async def update_assistant_service(assistant_id: UUID, update_request: UpdateAss |
159 | 164 | if update_request.contexts is not None: |
160 | 165 | for context in assistant.contexts: |
161 | 166 | db_session.delete(context) |
162 | | - assistant.contexts = [ |
163 | | - Context(content=ctx.content, pecha_title=ctx.pecha_title, pecha_text_id=ctx.pecha_text_id) |
164 | | - for ctx in update_request.contexts |
165 | | - ] |
| 167 | + new_contexts = [] |
| 168 | + for ctx in update_request.contexts: |
| 169 | + if ctx.pecha_text_id: |
| 170 | + search_details = await get_search_texts_details(ctx.pecha_text_id) |
| 171 | + content = "\n\n".join([detail.content for detail in search_details]) if search_details else "" |
| 172 | + else: |
| 173 | + content = ctx.content |
| 174 | + new_contexts.append( |
| 175 | + Context(content=content, pecha_title=ctx.pecha_title, pecha_text_id=ctx.pecha_text_id) |
| 176 | + ) |
| 177 | + assistant.contexts = new_contexts |
166 | 178 |
|
167 | 179 | assistant.updated_at = datetime.now(timezone.utc) |
168 | 180 |
|
|
0 commit comments