Skip to content

Instantly share code, notes, and snippets.

@colin-ho
Created April 21, 2025 20:36
Show Gist options
  • Save colin-ho/2255c1b8c814155e8c47251c1b67b9ea to your computer and use it in GitHub Desktop.
Save colin-ho/2255c1b8c814155e8c47251c1b67b9ea to your computer and use it in GitHub Desktop.
def pydantic_udf(pydantic_model: pydantic.BaseModel, udf: type, **kwargs):
pyarrow_schema = pydantic_to_pyarrow.get_pyarrow_schema(pydantic_model)
pyarrow_dtype = pa.struct([(c, pyarrow_schema.field(c).type) for c in pyarrow_schema.names])
decorator = daft.udf(return_dtype=daft.DataType.from_arrow_type(pyarrow_dtype), **kwargs)
return decorator(udf)
class CommitQuality(BaseModel):
impact_to_project: int = Field(
ge=1, le=10,
description="Score from 1-10 indicating impact to project.",
)
technical_ability: int = Field(
ge=1, le=10,
description="Score from 1-10 indicating technical ability.",
)
reason: str
analyze_commit_udf = pydantic_udf(CommmitQuality, analyze_commit_message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment