Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion backend/app/api/routes/threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

from fastapi import APIRouter, BackgroundTasks, Depends, HTTPException
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
Expand All @@ -19,6 +21,18 @@
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."
)
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):
"""Send results to the callback URL (synchronously)."""
try:
Expand Down Expand Up @@ -340,14 +354,15 @@

@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),
):
"""
Create a new OpenAI thread for the given question and start polling in the background.
"""
request = request.model_dump()

Check warning on line 365 in backend/app/api/routes/threads.py

View check run for this annotation

Codecov / codecov/patch

backend/app/api/routes/threads.py#L365

Added line #L365 was not covered by tests
prompt = request["question"]
credentials = get_provider_credential(
session=db,
Expand Down