fix: recover Work runs after failed verification
This commit is contained in:
@@ -22,6 +22,18 @@ from agent_platform.runtime.schemas import ChatCompletionRequest
|
||||
from agent_platform.runtime.tools import ToolRegistry
|
||||
from agent_platform.store import RuntimeStore
|
||||
|
||||
OPENWEBUI_BACKGROUND_TASKS = {
|
||||
"title_generation",
|
||||
"follow_up_generation",
|
||||
"tags_generation",
|
||||
"emoji_generation",
|
||||
"query_generation",
|
||||
"image_prompt_generation",
|
||||
"autocomplete_generation",
|
||||
"function_calling",
|
||||
"moa_response_generation",
|
||||
}
|
||||
|
||||
|
||||
def _sse_chunk(model: str, content: str = "", finish_reason: str | None = None) -> bytes:
|
||||
payload = {
|
||||
@@ -145,15 +157,7 @@ def create_app(
|
||||
except ValueError as exc:
|
||||
raise HTTPException(status_code=404, detail=str(exc)) from exc
|
||||
|
||||
stable_chat_id = (chat_id or message_id or f"ephemeral-{uuid.uuid4().hex}").strip()
|
||||
selected_mode = await app.state.store.select_mode(identity.user_id, chat_id or "", spec.mode)
|
||||
if selected_mode == "work" and spec.mode == "chat":
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_409_CONFLICT,
|
||||
detail="This conversation has been upgraded to Work and cannot return to Chat.",
|
||||
)
|
||||
|
||||
if spec.mode == "chat":
|
||||
async def forward_direct():
|
||||
payload = body.model_dump(exclude_none=True)
|
||||
payload["model"] = spec.provider_model
|
||||
response = await app.state.provider.forward(payload)
|
||||
@@ -183,6 +187,21 @@ def create_app(
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
background_task = str((body.metadata or {}).get("task", "")).strip()
|
||||
if background_task in OPENWEBUI_BACKGROUND_TASKS:
|
||||
return await forward_direct()
|
||||
|
||||
stable_chat_id = (chat_id or message_id or f"ephemeral-{uuid.uuid4().hex}").strip()
|
||||
selected_mode = await app.state.store.select_mode(identity.user_id, chat_id or "", spec.mode)
|
||||
if selected_mode == "work" and spec.mode == "chat":
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_409_CONFLICT,
|
||||
detail="This conversation has been upgraded to Work and cannot return to Chat.",
|
||||
)
|
||||
|
||||
if spec.mode == "chat":
|
||||
return await forward_direct()
|
||||
|
||||
messages = [message.model_dump(exclude_none=True) for message in body.messages]
|
||||
if not body.stream:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user