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(go): Add ai > document #2253

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

feat(go): Add ai > document #2253

wants to merge 2 commits into from

Conversation

ssbushi
Copy link
Contributor

@ssbushi ssbushi commented Mar 5, 2025

Fixes: #2129

Checklist (if applicable):

@github-actions github-actions bot added docs Improvements or additions to documentation python Python root labels Mar 5, 2025
Comment on lines +12 to +18
# TODO(ssbushi): Replace with generated type
class EmbeddingModel(BaseModel):
"""Represents an embedding with metadata."""

embedding: Embedding
metadata: dict[str, Any] | None = None

Copy link
Contributor Author

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.

@ssbushi ssbushi requested review from yesudeep, Irillit and pavelgj March 5, 2025 22:51
@yesudeep
Copy link
Contributor

yesudeep commented Mar 6, 2025

  1. feat(py) ?
  2. Please run bin/fmt to fix formatting issues.

# Copyright 2025 Google LLC
# SPDX-License-Identifier: Apache-2.0

from __future__ import annotations
Copy link
Contributor

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):
Copy link
Contributor

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."""
Copy link
Contributor

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
Copy link
Contributor

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):
Copy link
Contributor

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):
Copy link
Collaborator

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'
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to documentation python Python root
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

[py] ai > document
4 participants