From 6ad26db0e2de56f83fb28993eee25f0f14a64b81 Mon Sep 17 00:00:00 2001 From: Aviraj <100823015+avirajsingh7@users.noreply.github.com> Date: Fri, 20 Jun 2025 14:01:00 +0530 Subject: [PATCH 1/3] add validation in thread/start --- backend/app/api/routes/threads.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/backend/app/api/routes/threads.py b/backend/app/api/routes/threads.py index 66bc35ee..13760612 100644 --- a/backend/app/api/routes/threads.py +++ b/backend/app/api/routes/threads.py @@ -4,6 +4,7 @@ from fastapi import APIRouter, BackgroundTasks, Depends, HTTPException from openai import OpenAI +from pydantic import BaseModel, Field from sqlmodel import Session from langfuse.decorators import observe, langfuse_context @@ -19,6 +20,14 @@ router = APIRouter(tags=["threads"]) +class StartThreadRequest(BaseModel): + question: str = Field(..., description="The user's input question.") + assistant_id: str = Field(..., description="The ID of the assistant to be used.") + remove_citation: bool = Field( + default=False, description="Whether to remove citations from the response." + ) + + def send_callback(callback_url: str, data: dict): """Send results to the callback URL (synchronously).""" try: @@ -340,7 +349,7 @@ async def threads_sync( @router.post("/threads/start") async def start_thread( - request: dict, + request: StartThreadRequest, background_tasks: BackgroundTasks, db: Session = Depends(get_db), _current_user: UserOrganization = Depends(get_current_user_org), @@ -348,6 +357,7 @@ async def start_thread( """ Create a new OpenAI thread for the given question and start polling in the background. """ + request = request.model_dump() prompt = request["question"] credentials = get_provider_credential( session=db, From 84a8fc4bfc312ed5a4475a16a5c0c01503795025 Mon Sep 17 00:00:00 2001 From: Aviraj <100823015+avirajsingh7@users.noreply.github.com> Date: Fri, 20 Jun 2025 22:33:47 +0530 Subject: [PATCH 2/3] add thread id optional --- backend/app/api/routes/threads.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/backend/app/api/routes/threads.py b/backend/app/api/routes/threads.py index 13760612..321e48a6 100644 --- a/backend/app/api/routes/threads.py +++ b/backend/app/api/routes/threads.py @@ -6,6 +6,7 @@ from openai import OpenAI from pydantic import BaseModel, Field from sqlmodel import Session +from typing import Optional from langfuse.decorators import observe, langfuse_context from app.api.deps import get_current_user_org, get_db @@ -26,6 +27,9 @@ class StartThreadRequest(BaseModel): remove_citation: bool = Field( default=False, description="Whether to remove citations from the response." ) + thread_id: Optional[str] = Field( + default=None, description="An optional existing thread ID to continue the conversation." + ) def send_callback(callback_url: str, data: dict): From a4c14c5d4cb9e3a113e635cd293ace713686c094 Mon Sep 17 00:00:00 2001 From: Aviraj <100823015+avirajsingh7@users.noreply.github.com> Date: Fri, 20 Jun 2025 22:37:49 +0530 Subject: [PATCH 3/3] precommit run --- backend/app/api/routes/threads.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/app/api/routes/threads.py b/backend/app/api/routes/threads.py index 321e48a6..2019d0e8 100644 --- a/backend/app/api/routes/threads.py +++ b/backend/app/api/routes/threads.py @@ -28,7 +28,8 @@ class StartThreadRequest(BaseModel): default=False, description="Whether to remove citations from the response." ) thread_id: Optional[str] = Field( - default=None, description="An optional existing thread ID to continue the conversation." + default=None, + description="An optional existing thread ID to continue the conversation.", )