Repository navigation
feat(assessment): Add audio input column #1317
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
base: main
Are you sure you want to change the base?
Changes from all commits
cef847d
8f7cc45
0509580
d296d26
c42ebc2
57004a2
3f8b952
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import logging | ||
| import re | ||
| from typing import Literal | ||
| from typing import Literal, get_args | ||
|
|
||
| from pydantic import JsonValue, model_validator | ||
| from sqlmodel import Field, SQLModel | ||
|
|
@@ -18,14 +18,15 @@ | |
| # object-typed dict. Provider strict-mode normalisation is a run-mode concern. | ||
| JSON_SCHEMA_OBJECT_TYPE = "object" | ||
|
|
||
| IMAGE_COLUMN_TYPE = "image" | ||
| PDF_COLUMN_TYPE = "pdf" | ||
| VIDEO_COLUMN_TYPE = "video" | ||
| AttachmentColumnType = Literal["image", "pdf", "video", "audio"] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| ColumnType = Literal["text"] | AttachmentColumnType | ||
|
vprashrex marked this conversation as resolved.
Resolved
|
||
| # Input-column types carrying a media reference rather than prompt text. | ||
| ATTACHMENT_COLUMN_TYPES = (IMAGE_COLUMN_TYPE, PDF_COLUMN_TYPE, VIDEO_COLUMN_TYPE) | ||
| ATTACHMENT_COLUMN_TYPES = get_args(AttachmentColumnType) | ||
|
|
||
| AttachmentColumnType = Literal["image", "pdf", "video"] | ||
| ColumnType = Literal["text"] | AttachmentColumnType | ||
| # Media column types a provider cannot take, so a config pairing them is rejected at save. | ||
| UNSUPPORTED_COLUMN_TYPES_BY_PROVIDER: dict[str, tuple[str, ...]] = dict.fromkeys( | ||
| (Provider.OPENAI, Provider.ANTHROPIC), ("video", "audio") | ||
| ) | ||
|
|
||
| # {column} placeholders in a submission template; the capture group is the column name. | ||
| PLACEHOLDER_RE = re.compile(r"\{(\w+)\}") | ||
|
|
@@ -51,8 +52,8 @@ class InputColumn(SQLModel): | |
|
|
||
| @model_validator(mode="after") | ||
| def _validate_video_format(self): | ||
| if self.type == VIDEO_COLUMN_TYPE and self.format == "base64": | ||
| raise ValueError("A 'video' input column must be url-format.") | ||
| if self.type in ("video", "audio") and self.format == "base64": | ||
| raise ValueError(f"A '{self.type}' input column must be url-format.") | ||
| return self | ||
|
|
||
|
|
||
|
|
@@ -225,3 +226,26 @@ def _validate_submission_placeholders(self): | |
| f"{', '.join(unknown)}" | ||
| ) | ||
| return self | ||
|
|
||
| @model_validator(mode="after") | ||
| def _validate_column_types_supported(self): | ||
| """Every stage's provider must accept each media column type in input_schema.""" | ||
| stage_providers = {"assessment": self.assessment.provider} | ||
| if self.pre_filters and self.pre_filters.topic_relevance: | ||
| stage_providers[ | ||
| "pre_filter topic_relevance" | ||
| ] = self.pre_filters.topic_relevance.provider | ||
|
|
||
| for stage, provider in stage_providers.items(): | ||
| unsupported = UNSUPPORTED_COLUMN_TYPES_BY_PROVIDER.get(provider, ()) | ||
| offending = sorted( | ||
| column | ||
| for column, spec in self.input_schema.items() | ||
| if spec.type in unsupported | ||
| ) | ||
| if offending: | ||
| raise ValueError( | ||
| f"{stage} provider '{provider}' does not support " | ||
| f"{'/'.join(unsupported)} input columns: {', '.join(offending)}" | ||
| ) | ||
| return self | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: ProjectTech4DevAI/kaapi-backend
Length of output: 5341
Return a 422 when a stored
mixedattachment cannot be parsed on retry._build_retry_requestrebuilds each stored attachment withAssessmentAttachment.model_validate. Themixedtype was removed fromAssessmentAttachment.type, so a stored attachment withtype: "mixed"raises aValidationError. Nothing in the call path catches it. The generic exception handler then returns HTTP 500 with the raw Pydantic message, and the caller gets no actionable response. Retry fails only for stored attachments whose type ismixed.Wrap the attachment parse and raise a 422 that tells the user to create a new assessment. The same helper serves
retry_assessmentandretry_assessment_run, so one change covers both.Suggested fix
Add the missing import in
backend/app/services/assessment/service.py. The module does not importValidationErrortoday.from fastapi import HTTPException +from pydantic import ValidationError from sqlmodel import SessionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not changing this: the legacy RUN pipeline, including its retry path, is being removed, so a stored
mixedattachment is not handled here.