Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: extend QA gen types #133

Merged
merged 2 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 12 additions & 2 deletions deepsearch/model/examples/dummy_qa_generator/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

from deepsearch.model.base.types import Kind
from deepsearch.model.kinds.qagen.model import BaseQAGenerator
from deepsearch.model.kinds.qagen.types import GenerateAnswersOutput, QAGenConfig
from deepsearch.model.kinds.qagen.types import (
GenerateAnswersOutEntry,
GenerateAnswersOutput,
QAGenConfig,
)


class DummyQAGenerator(BaseQAGenerator):
Expand All @@ -24,4 +28,10 @@ def generate_answers(
Args:
texts: a list of context, question pairs.
"""
return [question for _, question in texts]
return [
GenerateAnswersOutEntry(
answer=question,
metadata={"foo": "bar"},
)
for _, question in texts
]
13 changes: 9 additions & 4 deletions deepsearch/model/kinds/qagen/types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import List, Literal
from typing import Any, Dict, List, Literal

from pydantic import root_validator
from pydantic import BaseModel, root_validator

from deepsearch.model.base.types import (
BaseAppPredInput,
Expand Down Expand Up @@ -29,7 +29,7 @@ def check_lengths_match(cls, values):
return values


class QAGenReqSpec(StrictModel):
class QAGenReqSpec(BaseModel):
generateAnswers: GenerateAnswers


Expand All @@ -38,7 +38,12 @@ class QAGenAppPredInput(BaseAppPredInput):
spec: QAGenReqSpec


GenerateAnswersOutput = List[str]
class GenerateAnswersOutEntry(StrictModel):
answer: str
metadata: Dict[str, Any]


GenerateAnswersOutput = List[GenerateAnswersOutEntry]


class QAGenCtrlPredOutput(StrictModel):
Expand Down