Skip to content

Commit 65cc56d

Browse files
committed
content changes
1 parent 3329cb7 commit 65cc56d

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

api/Assistant/assistant_service.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from api.db.pg_database import SessionLocal
33
from api.Assistant.assistant_repository import get_all_assistants, get_assistant_by_id_repository, delete_assistant_repository, update_assistant_repository
44
from api.Assistant.assistant_response_model import AssistantRequest, AssistantResponse, AssistantInfoResponse, AssistantListItemResponse, ContextResponse, UpdateAssistantRequest
5+
from api.search.search_service import get_search_texts_details
56
from api.Assistant.assistant_repository import create_assistant_repository
67
from typing import List
78
from api.Assistant.assistant_model import Assistant, Context
@@ -75,10 +76,14 @@ async def create_assistant_service(token: str, assistant_request: AssistantReque
7576
current_user_email = validate_and_extract_user_email(token=token)
7677
contexts_list = []
7778
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
7884
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)
8086
)
81-
8287
if files:
8388
for file in files:
8489
if file.filename:
@@ -159,10 +164,17 @@ async def update_assistant_service(assistant_id: UUID, update_request: UpdateAss
159164
if update_request.contexts is not None:
160165
for context in assistant.contexts:
161166
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
166178

167179
assistant.updated_at = datetime.now(timezone.utc)
168180

api/search/search_view.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
tags=["search"]
1111
)
1212

13-
1413
@search_router.get("/{text_id}", status_code=status.HTTP_200_OK, response_model=list[SearchTextsDetailsResponse])
1514
async def read_texts_details(
1615
text_id: str

0 commit comments

Comments
 (0)