mirror of
https://github.com/onyx-dot-app/onyx.git
synced 2026-10-23 03:42:59 -05:00
* ran bump-pydantic * replace root_validator with model_validator * mostly working. some alternate assistant error. changed root_validator and typing_extensions * working generation chat. changed type * replacing .dict with .model_dump * argument needed to bring model_dump up to parity with dict() * fix a fewremaining issues -- working with llama and gpt * updating requirements file * more requirement updates * more requirement updates * fix to make search work * return type fix: * half way tpyes change * fixes for mypy and pydantic: * endpoint fix * fix pydantic protected namespaces * it works! * removed unecessary None initializations * better logging * changed default values to empty lists * mypy fixes * fixed array defaulting --------- Co-authored-by: hagen-danswer <hagen@danswer.ai>
40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
from typing import Any
|
|
|
|
from pydantic import BaseModel
|
|
from pydantic import model_validator
|
|
|
|
|
|
class ToolResponse(BaseModel):
|
|
id: str | None = None
|
|
response: Any = None
|
|
|
|
|
|
class ToolCallKickoff(BaseModel):
|
|
tool_name: str
|
|
tool_args: dict[str, Any]
|
|
|
|
|
|
class ToolRunnerResponse(BaseModel):
|
|
tool_run_kickoff: ToolCallKickoff | None = None
|
|
tool_response: ToolResponse | None = None
|
|
tool_message_content: str | list[str | dict[str, Any]] | None = None
|
|
|
|
@model_validator(mode="after")
|
|
def validate_tool_runner_response(self) -> "ToolRunnerResponse":
|
|
fields = ["tool_response", "tool_message_content", "tool_run_kickoff"]
|
|
provided = sum(1 for field in fields if getattr(self, field) is not None)
|
|
|
|
if provided != 1:
|
|
raise ValueError(
|
|
"Exactly one of 'tool_response', 'tool_message_content', "
|
|
"or 'tool_run_kickoff' must be provided"
|
|
)
|
|
|
|
return self
|
|
|
|
|
|
class ToolCallFinalResult(ToolCallKickoff):
|
|
tool_result: Any = (
|
|
None # we would like to use JSON_ro, but can't due to its recursive nature
|
|
)
|