(
post_data: dict[str, Any],
auth: AuthContext,
open_api_service: OpenApiService,
chat_service: ChatService,
)
| 86 | |
| 87 | |
| 88 | async def _open_api_chat_response( |
| 89 | post_data: dict[str, Any], |
| 90 | auth: AuthContext, |
| 91 | open_api_service: OpenApiService, |
| 92 | chat_service: ChatService, |
| 93 | ) -> StreamingResponse | JSONResponse: |
| 94 | if auth.via != "api_key": |
| 95 | return await _build_streaming_chat_response( |
| 96 | chat_service, |
| 97 | auth.username, |
| 98 | post_data, |
| 99 | ) |
| 100 | |
| 101 | try: |
| 102 | ( |
| 103 | effective_username, |
| 104 | session_id, |
| 105 | config_id, |
| 106 | ) = await open_api_service.prepare_chat_send( |
| 107 | post_data, |
| 108 | _get_chat_config_list(open_api_service), |
| 109 | ) |
| 110 | except OpenApiServiceError as exc: |
| 111 | return _open_api_error(str(exc)) |
| 112 | |
| 113 | config_err = await open_api_service.update_session_config_route( |
| 114 | username=effective_username, |
| 115 | session_id=session_id, |
| 116 | config_id=config_id, |
| 117 | ) |
| 118 | if config_err: |
| 119 | return _open_api_error(config_err) |
| 120 | |
| 121 | return await _build_streaming_chat_response( |
| 122 | chat_service, |
| 123 | effective_username, |
| 124 | post_data, |
| 125 | ) |
| 126 | |
| 127 | |
| 128 | async def _insert_webchat_user_message( |
no test coverage detected