Skip to content

Add magic generics to ai.ops.evaluate - #307

Closed
anbuzin wants to merge 1 commit into
mainfrom
evaluate-magic-generics
Closed

anbuzin wants to merge 1 commit into
mainfrom
evaluate-magic-generics

Conversation

@anbuzin

@anbuzin anbuzin commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

Here's one option for how we can tie together FooQuestions and FooAnswers without having to pass FooAnswers somewhere twice.

class TicketAnswers(ai.ops.BaseAnswerModel):
    queue: ai.ops.ChoiceAnswer
    urgency: ai.ops.ScoreAnswer
    refund_warranted: ai.ops.BooleanAnswer


class TicketQuestions(ai.ops.BaseQuestionModel[TicketAnswers]):
    queue: ai.ops.ChoiceQuestion
    urgency: ai.ops.ScoreQuestion
    refund_warranted: ai.ops.BooleanQuestion

See evaluation.py:213 for why we might not want to do this.

    if isinstance(questions, BaseQuestionModel):
        # Pydantic stores concrete generic arguments on the specialized base,
        # not on a question subclass. Walk the MRO for indirect subclasses.
        for base in type(questions).__mro__:
            if issubclass(base, BaseQuestionModel):
                args = getattr(base, "__pydantic_generic_metadata__", {}).get(
                    "args", ()
                )
                if args:
                    answer_model = args[0]
                    break

@vercel

vercel Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
ai-python Ready Ready Preview, v0 Sep 28, 2026 4:14pm UTC

@anbuzin
anbuzin marked this pull request as draft September 23, 2026 23:41
@anbuzin
anbuzin requested review from 1st1 and msullivan September 23, 2026 23:42
@anbuzin
anbuzin changed the base branch from main to tighten-evaluate-typing September 23, 2026 23:47
Base automatically changed from tighten-evaluate-typing to main September 28, 2026 16:11

This branch was successfully deployed

1 active deployment
Preview — 5703b82d Deployed Sep 28, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants