Skip to content

Commit

Permalink
Merge branch 'main' into haguirre/addModelVersions
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoaguirre committed Feb 3, 2025
2 parents 66db208 + 2ebcd72 commit 4251094
Show file tree
Hide file tree
Showing 431 changed files with 74,956 additions and 3,440 deletions.
16 changes: 14 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,21 @@ root = true

[*]
charset = utf-8
indent_style = space
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
max_line_length = 80
trim_trailing_whitespace = true

[*.{js,jsx,ts,tsx}]
quote_type = single

[*.py]
indent_size = 4
indent_style = space
quote_type = single

[{Makefile,go.mod,go.sum,*.go,.gitmodules}]
indent_size = 4
indent_style = tab
105 changes: 105 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Add 'root' label to any root file changes
# Quotation marks are required for the leading asterisk
root:
- changed-files:
- any-glob-to-any-file: '*'

docs:
- changed-files:
- any-glob-to-any-file:
- '**/*.md'
- '**/*.rst'
- 'LICENSE'
- 'docs-go/**'
- 'docs/**'
- 'py/engdocs/**'

go:
- changed-files:
- any-glob-to-any-file:
- '**/*.go'
- '**/go.mod'
- '**/go.sum'
- 'go/**'

python:
- changed-files:
- any-glob-to-any-file:
- '**/*.py'
- '**/pyproject.toml'
- 'py/**'

js:
- changed-files:
- any-glob-to-any-file:
- '**/*.js'
- '**/*.jsx'
- '**/*.ts'
- '**/*.tsx'
- '**/package.json'
- 'js/**'

tooling:
- changed-files:
- any-glob-to-any-file:
- 'genkit-tools/**'

config:
- changed-files:
- any-glob-to-any-file:
- '**/*.toml'
- '**/*.yaml'
- '**/*.yml'
- '**/.editorconfig'
- '**/.github/**'
- '**/.gitignore'
- '**/.npmignore'
- '**/.npmrc'
- '**/.prettierignore'
- '**/package.json'
- '**/tsconfig.*.json'
- '**/tsconfig.json'
- '**/typedoc.json'

sample:
- changed-files:
- any-glob-to-any-file:
- 'samples/**'

dotprompt:
- changed-files:
- any-glob-to-any-file:
- '**/dotprompt/**'

handlebarz:
- changed-files:
- any-glob-to-any-file:
- '**/handlebarz/**'

# Automatically add labels to any PR also based on branch naming conventions.
build:
- head-branch: [^.*/build/.*, build]

chore:
- head-branch: [^.*/chore/.*, chore]

ci:
- head-branch: [^.*/ci/.*, ci]

feature:
- head-branch: [^.*/feat/.*, feature]

fix:
- head-branch: [^.*/fix/.*, fix]

perf:
- head-branch: [^.*/perf/.*, perf]

refactor:
- head-branch: [^.*/refactor/.*, refactor]

style:
- head-branch: [^.*/style/.*, style]

test:
- head-branch: [^.*/test/.*, test]
4 changes: 2 additions & 2 deletions .github/workflows/builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v3
- name: Set up node v21
- name: Set up node v20
uses: actions/setup-node@v4
with:
node-version: 21.x
node-version: 20.x
cache: 'pnpm'
- name: Install dependencies
run: pnpm install
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@

name: Go tests and checks

on:
pull_request:
paths: 'go/**'
on: pull_request

jobs:
tests:
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: "Pull Request Labeler"

on:
- pull_request_target

jobs:
labeler:
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@v5
43 changes: 43 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Python Checks

on: pull_request

jobs:
python-checks:
runs-on: ubuntu-latest
env:
PATH: ${{ github.workspace }}/go/bin:${{ github.workspace }}/.cargo/bin:${{ github.workspace }}/.local/share/pnpm:${{ github.workspace }}/.local/bin:/usr/local/bin:/usr/bin:/bin
strategy:
matrix:
python-version:
- "3.12"
defaults:
run:
working-directory: py

steps:
- uses: actions/checkout@v4

- name: Pre-requisites
run: bin/setup -a ci

- name: Install uv and setup Python version
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
python-version: ${{ matrix.python-version }}

- name: Format check
run: uv run ruff format --check .

- name: Lint with ruff
run: uv run ruff check .

- name: Run tests
run: ./bin/run_tests

- name: Build documentation
run: uv run mkdocs build --strict

- name: Build distributions
run: ./bin/build_dists
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ dist
.vscode
.DS_Store
package-lock.json
!samples/**/package-lock.json
.angular
*.tgz
.pnpm-store
.next
# version file (autogenerated by CLI)
genkit-tools/cli/src/utils/version.ts

Expand All @@ -29,16 +31,18 @@ ui-debug.log
firebase-debug.log
**/*.env
# RAG sample files
!js/testapps/rag/package.json
js/testapps/rag/*.json
!js/testapps/rag/package.json
js/testapps/evals/__db*.json
js/testapps/menu/rag/__db*.json
js/testapps/menu/**/__db*.json
js/testapps/personal-testing

# Test files
last_recording.mp4

# auto-generated
/js/core/src/__codegen
/js/api-refs-js
next-env.d.ts

!samples/chatbot/server/genkit-ai-vertexai-*.tgz
10 changes: 6 additions & 4 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
go/
public/
.github/
.mypy_cache/*
.prettierrc.yaml
pnpm-lock.yaml
docs/*
docs-go/*
docs/*
genkit-tools/genkit-schema.json
go/
pnpm-lock.yaml
public/
py/*
3 changes: 1 addition & 2 deletions docs/evaluation.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,7 @@ and is only enforced if a schema is specified on the target flow.
control for advanced use cases (e.g. providing model parameters, message
history, tools, etc). You can find the full schema for `GenerateRequest` in
our [API reference
docs](https://genkit-js-api.web.app/interfaces/genkit._.GenerateRequest.html).
<!-- TODO(thedmail): Update link to API reference once formally published -->
docs](https://js.api.genkit.dev/interfaces/genkit._.GenerateRequest.html).
Note: Schema validation is a helper tool for editing examples, but it is
possible to save an example with invalid schema. These examples may fail when
Expand Down
3 changes: 2 additions & 1 deletion docs/firebase.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ as callable functions using the Cloud Functions client libraries.

## Before you begin

* Install the [Firebase CLI](/docs/cli).
* You should be familiar with Genkit's concept of [flows](flows), and how to
write them. The instructions on this page assume that you already have some
flows defined, which you want to deploy.
Expand All @@ -24,6 +23,8 @@ up, follow these steps:
1. Upgrade the project to the Blaze plan, which is required to deploy Cloud
Functions.

1. Install the [Firebase CLI](/docs/cli).

1. Log in with the Firebase CLI:

```posix-terminal
Expand Down
22 changes: 21 additions & 1 deletion docs/plugins/vertex-ai.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,26 @@ const embedding = await ai.embed({
});
```

This plugin can also handle multimodal embeddings:

```ts
const ai = genkit({
plugins: [vertextAI({location: 'us-central1' })],
});

const embeddings = await ai.embed({
embedder: multimodalEmbedding001,
content: {
content: [{
"media": {
"url": "gs://cloud-samples-data/generative-ai/video/pixel8.mp4",
"contentType": "video/mp4"
}
}]
}
});
```

Imagen3 model allows generating images from user prompt:

```ts
Expand Down Expand Up @@ -573,6 +593,6 @@ const llmResponse = await ai.generate({

Only specific models, such as `gemini15Flash` and `gemini15Pro`, support context caching, and currently only on version numbers `001`. If an unsupported model is used, an error will be raised, indicating that caching cannot be applied.

### Further Reading
### Further Reading

See more information regarding context caching on Vertex AI in their [documentation](https://cloud.google.com/vertex-ai/generative-ai/docs/context-cache/context-cache-overview).
17 changes: 14 additions & 3 deletions docs/rag.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,12 @@ export const indexMenu = ai.defineFlow(
filePath = path.resolve(filePath);

// Read the pdf.
const pdfTxt = await run('extract-text', () =>
const pdfTxt = await ai.run('extract-text', () =>
extractTextFromPdf(filePath)
);

// Divide the pdf text into segments.
const chunks = await run('chunk-it', async () =>
const chunks = await ai.run('chunk-it', async () =>
chunk(pdfTxt, chunkingConfig)
);

Expand Down Expand Up @@ -266,12 +266,13 @@ which you should not use in production.

```ts
import { devLocalRetrieverRef } from '@genkit-ai/dev-local-vectorstore';
import { gemini } from '@genkit-ai/vertexai';

// Define the retriever reference
export const menuRetriever = devLocalRetrieverRef('menuQA');

export const menuQAFlow = ai.defineFlow(
{ name: 'menuQA', inputSchema: z.string(), outputSchema: z.string() },
{ name: "menuQA", inputSchema: z.string(), outputSchema: z.string() },
async (input: string) => {
// retrieve relevant documents
const docs = await ai.retrieve({
Expand All @@ -282,6 +283,7 @@ export const menuQAFlow = ai.defineFlow(

// generate a response
const { text } = await ai.generate({
model: gemini('gemini-1.5-flash'),
prompt: `
You are acting as a helpful AI assistant that can answer
questions about the food available on the menu at Genkit Grub Pub.
Expand All @@ -299,6 +301,15 @@ Question: ${input}`,
);
```

#### Run the retriever flow

```posix-terminal
genkit flow:run menuQA '"Recommend a dessert from the menu while avoiding dairy and nuts"'
```

The output for this command should contain a response from the model, grounded
in the indexed `menu.pdf` file.

## Write your own indexers and retrievers

It's also possible to create your own retriever. This is useful if your
Expand Down
2 changes: 1 addition & 1 deletion genkit-tools/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "genkit-cli",
"version": "1.0.0-rc.7",
"version": "1.0.0-rc.14",
"description": "CLI for interacting with the Google Genkit AI framework",
"license": "Apache-2.0",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion genkit-tools/common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@genkit-ai/tools-common",
"version": "1.0.0-rc.7",
"version": "1.0.0-rc.14",
"scripts": {
"compile": "tsc -b ./tsconfig.cjs.json ./tsconfig.esm.json ./tsconfig.types.json",
"build:clean": "rimraf ./lib",
Expand Down
Loading

0 comments on commit 4251094

Please sign in to comment.