Skip to content

Commit 21ed680

Browse files
Akhilesh NegiAkhilesh Negi
authored andcommitted
allowing extra fields in the response
1 parent cf0dc22 commit 21ed680

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

backend/app/api/routes/responses.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from sqlmodel import Session
99

1010
from app.api.deps import get_current_user_org, get_db
11-
from app.api.routes.threads import send_callback
1211
from app.crud.credentials import get_provider_credential
1312
from app.crud.assistants import get_assistant_by_id
1413
from app.models import UserOrganization
@@ -69,6 +68,11 @@ class _APIResponse(BaseModel):
6968
chunks: list[FileResultChunk]
7069
diagnostics: Optional[Diagnostics] = None
7170

71+
class Config:
72+
extra = (
73+
Extra.allow
74+
) # This allows additional fields to be included in the response
75+
7276

7377
class ResponsesAPIResponse(APIResponse[_APIResponse]):
7478
pass
@@ -101,7 +105,7 @@ def process_response(
101105
):
102106
"""Process a response and send callback with results."""
103107
logger.info(
104-
f"[responses.process_response] Starting generating response for assistant_id={request.assistant_id}, project_id={request.project_id}, organization_id={organization_id}"
108+
f"Starting generating response for assistant_id={request.assistant_id}, project_id={request.project_id}, organization_id={organization_id}"
105109
)
106110
try:
107111
response = client.responses.create(
@@ -121,7 +125,7 @@ def process_response(
121125
)
122126
response_chunks = get_file_search_results(response)
123127
logger.info(
124-
f"[responses.process_response] Successfully generated response: response_id={response.id}, assistant={request.assistant_id}, project_id={request.project_id}, organization_id={organization_id}"
128+
f"Successfully generated response: response_id={response.id}, assistant={request.assistant_id}, project_id={request.project_id}, organization_id={organization_id}"
125129
)
126130

127131
# Convert request to dict and include all fields
@@ -155,18 +159,19 @@ def process_response(
155159
except openai.OpenAIError as e:
156160
error_message = handle_openai_error(e)
157161
logger.error(
158-
f"[responses.process_response] OpenAI API error during response processing: {error_message}, project_id={request.project_id}, organization_id={organization_id}"
162+
f"OpenAI API error during response processing: {error_message}, project_id={request.project_id}, organization_id={organization_id}"
159163
)
160164
callback_response = ResponsesAPIResponse.failure_response(error=error_message)
161165

162166
if request.callback_url:
163167
logger.info(
164-
f"[responses.process_response] Sending callback to URL: {request.callback_url}, assistant={request.assistant_id}, project_id={request.project_id}, organization_id={organization_id}"
168+
f"Sending callback to URL: {request.callback_url}, assistant={request.assistant_id}, project_id={request.project_id}, organization_id={organization_id}"
165169
)
170+
from app.api.routes.threads import send_callback
166171

167172
send_callback(request.callback_url, callback_response.model_dump())
168173
logger.info(
169-
f"[responses.process_response] Callback sent successfully, assistant={request.assistant_id}, project_id={request.project_id}, organization_id={organization_id}"
174+
f"Callback sent successfully, assistant={request.assistant_id}, project_id={request.project_id}, organization_id={organization_id}"
170175
)
171176

172177

@@ -179,7 +184,7 @@ async def responses(
179184
):
180185
"""Asynchronous endpoint that processes requests in background."""
181186
logger.info(
182-
f"[responses.responses] Processing response request for assistant_id={request.assistant_id}, project_id={request.project_id}, organization_id={_current_user.organization_id}"
187+
f"Processing response request for assistant_id={request.assistant_id}, project_id={request.project_id}, organization_id={_current_user.organization_id}"
183188
)
184189

185190
# Get assistant details
@@ -188,7 +193,7 @@ async def responses(
188193
)
189194
if not assistant:
190195
logger.error(
191-
f"[responses.responses] Assistant not found: assistant_id={request.assistant_id}, project_id={request.project_id}, organization_id={_current_user.organization_id}"
196+
f"Assistant not found: assistant_id={request.assistant_id}, project_id={request.project_id}, organization_id={_current_user.organization_id}"
192197
)
193198
raise HTTPException(
194199
status_code=404,
@@ -203,7 +208,7 @@ async def responses(
203208
)
204209
if not credentials or "api_key" not in credentials:
205210
logger.error(
206-
f"[responses.responses] OpenAI API key not configured for org_id={_current_user.organization_id}, project_id={request.project_id}, organization_id={_current_user.organization_id}"
211+
f"OpenAI API key not configured for org_id={_current_user.organization_id}, project_id={request.project_id}, organization_id={_current_user.organization_id}"
207212
)
208213
return {
209214
"success": False,
@@ -231,7 +236,7 @@ async def responses(
231236
process_response, request, client, assistant, _current_user.organization_id
232237
)
233238
logger.info(
234-
f"[responses.responses] Background task scheduled for response processing: assistant_id={request.assistant_id}, project_id={request.project_id}, organization_id={_current_user.organization_id}"
239+
f"Background task scheduled for response processing: assistant_id={request.assistant_id}, project_id={request.project_id}, organization_id={_current_user.organization_id}"
235240
)
236241

237242
return initial_response

0 commit comments

Comments
 (0)