⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2b70949
fix(py): add more flows to genai sample
MengqinShen-GL Jan 13, 2026
88db98e
fix(py): add more flows to genai sample
MengqinShen-GL Jan 13, 2026
5ce1052
fix(py): update with gemini comments
MengqinShen-GL Jan 14, 2026
2b42f60
fix(py): update README for vertexai-image sample (#4081)
MengqinShen Jan 9, 2026
4908c65
fix(go/plugins/anthropic): update schema config (#4080)
hugoaguirre Jan 9, 2026
1604f90
chore(go): added Godocs to generated types (#4075)
apascal07 Jan 9, 2026
f37ea15
feat(py): Implemented deepseek plugin (#4051)
zarinn3pal Jan 9, 2026
6a5576c
feat(py/genkit): add define_partial for Handlebars partials (#4088)
yesudeep Jan 10, 2026
561631c
fix(py/genkit): tox coverage failure and formatting (#4089)
yesudeep Jan 10, 2026
664162f
fix(py/genkit): re-enable some disabled tests and fix test capture in…
yesudeep Jan 10, 2026
0c12f94
fix(py): resolve pyproject.toml license deprecation warnings (#4092)
yesudeep Jan 10, 2026
73da68c
fix(py/genkit): resolve Pydantic serialization warnings in resources …
yesudeep Jan 10, 2026
5ac3483
build(py/genkit): switch to ty for stricter and faster type checks (#…
yesudeep Jan 10, 2026
5f9c5c6
fix(py/genkit): fix type errors reported by ty in typing sanitizer (#…
yesudeep Jan 10, 2026
ae24868
fix(go): fixed panic when stream value is nil (#4102)
apascal07 Jan 11, 2026
fd55a05
chore(go): improved the Genkit Go package docs (#4086)
apascal07 Jan 12, 2026
74b1ae7
fix(go): fixed bad dotprompt output format parsing (#4109)
apascal07 Jan 12, 2026
c5e906f
feat(go): added support for sessions (#4067)
apascal07 Jan 12, 2026
f8f7181
fix(go): fixed missing thought signatures on tool responses (#4115)
apascal07 Jan 13, 2026
41bcfdf
refactor(js/plugins/anthropic): extract out some shared converters (…
cabljac Jan 13, 2026
890f37d
fix(py): add more flows to genai sample
MengqinShen-GL Jan 13, 2026
556621b
fix(py): update with gemini comments
MengqinShen-GL Jan 14, 2026
7187cb9
fix(py): fix AssertionError in test_googlegenai_gemini.py
MengqinShen-GL Jan 14, 2026
0420a05
fix(py): resolve validation errors and config issues
MengqinShen-GL Jan 14, 2026
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
12 changes: 12 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,23 @@ jobs:
- name: Lint with ruff
run: uv run --directory py ruff check --select I .

- name: Type check with Ty
run: uv run --directory py ty check --exit-zero .

- name: Check licenses
run: ./bin/check_license

- name: Run Python tests
run: uv run --python ${{ matrix.python-version }} --active --isolated --directory py pytest -xvs --log-level=DEBUG .

- name: Run Python tests (tox)
run: |
clean_version=$(echo "${{ matrix.python-version }}" | tr -d '.')
uv run --directory py tox -e "py$clean_version"

- name: Run Python tests (nox)
run: |
uv run --directory py nox -s "tests-${{ matrix.python-version }}"

- name: Build distributions
run: ./py/bin/build_dists
2 changes: 1 addition & 1 deletion bin/run_lint
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ PY_DIR="${TOP_DIR}/py"
JS_DIR="${TOP_DIR}/js"j

uv run --directory "${PY_DIR}" ruff check --select I --fix --preview --unsafe-fixes .
uv run --directory "${PY_DIR}" mypy .
uv run --directory "${PY_DIR}" ty check --exclude samples .

# Disabled because there are many lint errors.
#pushd "${GO_DIR}" &>/dev/null
Expand Down
160 changes: 160 additions & 0 deletions go/ai/example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0

// Package ai_test provides examples for ai package helper functions.
//
// The ai package contains helper types and functions used with genkit.
// Most generation and definition functions are in the genkit package;
// see that package for the primary API documentation.
package ai_test

import (
"fmt"

"github.com/firebase/genkit/go/ai"
)

// This example demonstrates creating different types of message parts.
func ExampleNewTextPart() {
// Create a text part
part := ai.NewTextPart("Hello, world!")
fmt.Println(part.Text)
// Output: Hello, world!
}

// This example demonstrates creating a message with text content.
func ExampleNewUserTextMessage() {
// Create a user message with text
msg := ai.NewUserTextMessage("What is the capital of France?")
fmt.Println("Role:", msg.Role)
fmt.Println("Text:", msg.Content[0].Text)
// Output:
// Role: user
// Text: What is the capital of France?
}

// This example demonstrates creating system and model messages.
func ExampleNewSystemTextMessage() {
// Create a system message
sysMsg := ai.NewSystemTextMessage("You are a helpful assistant.")
fmt.Println("System role:", sysMsg.Role)

// Create a model response message
modelMsg := ai.NewModelTextMessage("I'm here to help!")
fmt.Println("Model role:", modelMsg.Role)
// Output:
// System role: system
// Model role: model
}

// This example demonstrates creating a data part for raw string content.
func ExampleNewDataPart() {
// Create a data part with raw string content
part := ai.NewDataPart(`{"name": "Alice", "age": 30}`)
fmt.Println("Is data part:", part.IsData())
fmt.Println("Content:", part.Text)
// Output:
// Is data part: true
// Content: {"name": "Alice", "age": 30}
}

// This example demonstrates accessing text from a Part.
func ExamplePart_Text() {
// Create a part with text
part := ai.NewTextPart("Sample text content")

// Access the text field directly
fmt.Println(part.Text)
// Output: Sample text content
}

// This example demonstrates the Document type used in RAG applications.
func ExampleDocument() {
// Create a document with text content
doc := &ai.Document{
Content: []*ai.Part{
ai.NewTextPart("This is the document content."),
},
Metadata: map[string]any{
"source": "knowledge-base",
"page": 42,
},
}

fmt.Println("Content:", doc.Content[0].Text)
fmt.Println("Source:", doc.Metadata["source"])
// Output:
// Content: This is the document content.
// Source: knowledge-base
}

// This example demonstrates creating an Embedding for vector search.
func ExampleEmbedding() {
// Create an embedding (typically returned by an embedder)
embedding := &ai.Embedding{
Embedding: []float32{0.1, 0.2, 0.3, 0.4, 0.5},
Metadata: map[string]any{
"source": "document-1",
},
}

fmt.Printf("Embedding dimensions: %d\n", len(embedding.Embedding))
fmt.Printf("First value: %.1f\n", embedding.Embedding[0])
// Output:
// Embedding dimensions: 5
// First value: 0.1
}

// This example demonstrates creating a media part for images or other media.
func ExampleNewMediaPart() {
// Create a media part with base64-encoded image data
// In practice, you would encode actual image bytes
imageData := "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJ..."
part := ai.NewMediaPart("image/png", imageData)

fmt.Println("Is media:", part.IsMedia())
fmt.Println("Content type:", part.ContentType)
// Output:
// Is media: true
// Content type: image/png
}

// This example demonstrates creating a model reference with configuration.
func ExampleNewModelRef() {
// Create a reference to a model with custom configuration
// The config type depends on the model provider
modelRef := ai.NewModelRef("googleai/gemini-2.5-flash", map[string]any{
"temperature": 0.7,
})

fmt.Println("Model name:", modelRef.Name())
// Output: Model name: googleai/gemini-2.5-flash
}

// This example demonstrates building a multi-turn conversation.
func ExampleNewUserMessage() {
// Build a conversation with multiple parts
userMsg := ai.NewUserMessage(
ai.NewTextPart("What's in this image?"),
ai.NewMediaPart("image/jpeg", "base64data..."),
)

fmt.Println("Role:", userMsg.Role)
fmt.Println("Parts:", len(userMsg.Content))
// Output:
// Role: user
// Parts: 2
}
Loading
Loading