Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions weaviate_agents/query/classes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
IsNullPropertyFilter,
ModelUnitUsage,
NumericMetrics,
ParsedAskModeResponse,
ProgressDetails,
ProgressMessage,
QueryAgentResponse,
Expand Down Expand Up @@ -79,6 +80,7 @@
"GeoPropertyFilter",
"UnknownPropertyAggregation",
"UnknownPropertyFilter",
"ParsedAskModeResponse",
"ProgressDetails",
"ProgressMessage",
"QueryWithCollection",
Expand Down
9 changes: 8 additions & 1 deletion weaviate_agents/query/classes/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
)
from uuid import UUID

from pydantic import BaseModel, ConfigDict, Field, field_validator
from pydantic import BaseModel, ConfigDict, Field, SerializeAsAny, field_validator
from typing_extensions import TypedDict
from weaviate.outputs.query import QueryReturn

Expand Down Expand Up @@ -479,6 +479,13 @@ def display(self) -> None:
return None


T = TypeVar("T", bound=Union[dict, BaseModel])


class ParsedAskModeResponse(AskModeResponse, Generic[T]):
final_answer_parsed: SerializeAsAny[T]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dannyjameswilliams can you help me understand this?

You say the bound of the type is a dict or any BaseModel? What does that do?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late response. The bound lets a users own model flow through with their own fields intact, rather than just being a generic BaseModel/dict

So if the user inputs a basemodel, e.g.

class MyResponse(BaseModel):
    my_answer: str
    used_sources: list[UUID]
    
res = qa.ask(..., output_format=MyResponse)

then type checkers know to expect those fields in the response, so doing e.g.

res.final_answer_parsed.my_answer
res.final_answer_parsed.used_sources[0]

will be recognised as their respective types and so on.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah got it! Thanks so much! 🧠



class ResearchModeResponse(BaseModel):
output_type: Literal["final_state"] = "final_state"

Expand Down
Loading
Loading