-
Notifications
You must be signed in to change notification settings - Fork 167
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(go): Add ai > document #2253
base: main
Are you sure you want to change the base?
Conversation
# TODO(ssbushi): Replace with generated type | ||
class EmbeddingModel(BaseModel): | ||
"""Represents an embedding with metadata.""" | ||
|
||
embedding: Embedding | ||
metadata: dict[str, Any] | None = None | ||
|
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.
This is a placeholder for now, will update with the generated type we should get from tooling.
|
# Copyright 2025 Google LLC | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from __future__ import annotations |
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.
nit: module docstring?
media: None = None | ||
|
||
|
||
class TextPart(BaseModel): |
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.
aren't these defined in typing.py
already?
@@ -0,0 +1,146 @@ | |||
"""Tests for Genkit document.""" |
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.
nit: please run bin/fmt
it automatically formats and adds license headers when run in the pre-commits.
""" | ||
|
||
text: str | ||
media: None = None |
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.
You need to add an annotation with Union, something like " | None". Media should probably be of Media or Media1 format from genkit.core.typing.
metadata: dict[str, Any] | None = None | ||
|
||
|
||
class Document(DocumentData): |
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.
For me it's a bit strange to inherit Pydantic model. Is it possible to use composition over inheritance here?
type Part = TextPart | MediaPart | ||
|
||
|
||
class DocumentData(BaseModel): |
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.
there's already DocumentData in
class DocumentData(BaseModel): |
def data_type(self) -> str | None: | ||
"""Gets the content_type of the data that is returned by data().""" | ||
if self.text(): | ||
return 'text' |
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.
As you've used 'text' several times, I suggest you to add it as a constant or a class field.
Fixes: #2129
Checklist (if applicable):