Skip to content

Commit

Permalink
Merge branch 'next' into improve-cloud-telemetry-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDoyle committed Oct 23, 2024
2 parents 1cf8bda + f6e8982 commit 267c193
Show file tree
Hide file tree
Showing 210 changed files with 4,996 additions and 3,340 deletions.
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 v20
- name: Set up node v21
uses: actions/setup-node@v4
with:
node-version: 20.x
node-version: 21.x
cache: 'pnpm'
- name: Install dependencies
run: pnpm install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Set up node v20
uses: actions/setup-node@v4
with:
node-version: 20.x
node-version: 21.x
cache: 'pnpm'
- name: Install dependencies
run: pnpm install
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/formatter.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 v20
- name: Set up node v21
uses: actions/setup-node@v4
with:
node-version: 20.x
node-version: 21.x
cache: 'pnpm'
- name: Install dependencies
run: pnpm install
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.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 v20
- name: Set up node v21
uses: actions/setup-node@v4
with:
node-version: 20.x
node-version: 21.x
cache: 'pnpm'
- name: Install dependencies and build
run: pnpm build:genkit-tools
Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,14 @@ Find excellent examples of community-built plugins for OpenAI, Anthropic, Cohere

## Try Genkit on IDX

<img src="docs/resources/idx-logo.png" width="50" alt="Project IDX logo">

Want to try Genkit without a local setup? [Explore it on Project IDX](https://idx.google.com/new/genkit), Google's AI-assisted workspace for full-stack app development in the cloud.
Want to skip the local setup? Click below to try out Genkit using [Project IDX](https://idx.dev), Google's AI-assisted workspace for full-stack app development in the cloud.

<a href="https://idx.google.com/import?url=">
<img
height="32"
alt="Try in IDX"
src="https://cdn.idx.dev/btn/try_purple_32.svg">
</a>

## Sample apps

Expand Down
8 changes: 4 additions & 4 deletions docs/dotprompt.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const result = await greetingPrompt.generate({
},
});

console.log(result.text());
console.log(result.text);
```

Dotprompt's syntax is based on the [Handlebars](https://handlebarsjs.com/guide/)
Expand Down Expand Up @@ -183,7 +183,7 @@ const myPrompt = promptRef("myPrompt");
const result = await myPrompt.generate<typeof MySchema>({...});
// now strongly typed as MySchema
result.output();
result.output;
```

## Overriding Prompt Metadata
Expand Down Expand Up @@ -237,7 +237,7 @@ const menu = await createMenuPrompt.generate({
},
});
console.log(menu.output());
console.log(menu.output);
```

Output conformance is achieved by inserting additional instructions into the
Expand Down Expand Up @@ -340,7 +340,7 @@ const result = await describeImagePrompt.generate({
},
});
console.log(result.text());
console.log(result.text);
```

## Partials
Expand Down
2 changes: 1 addition & 1 deletion docs/evaluation.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export const synthesizeQuestions = defineFlow(
text: `Generate one question about the text below: ${chunks[i]}`,
},
});
questions.push(qResponse.text());
questions.push(qResponse.text);
}
return questions;
}
Expand Down
2 changes: 1 addition & 1 deletion docs/get-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ so that it can be used outside of a Node project.
// Handle the response from the model API. In this sample, we just convert
// it to a string, but more complicated flows might coerce the response into
// structured output or chain the response into another LLM call, etc.
return llmResponse.text();
return llmResponse.text;
}
);

Expand Down
14 changes: 7 additions & 7 deletions docs/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ configureGenkit(/* ... */);
prompt: 'Invent a menu item for a pirate themed restaurant.',
});

console.log(await llmResponse.text());
console.log(await llmResponse.text);
})();
```

Expand Down Expand Up @@ -339,7 +339,7 @@ object's `output()` method:
```ts
type MenuItem = z.infer<typeof MenuItemSchema>;

const output: MenuItem | null = llmResponse.output();
const output: MenuItem | null = llmResponse.output;
```

#### Handling errors
Expand Down Expand Up @@ -425,7 +425,7 @@ Handle each of these chunks as they become available:
```ts
for await (const responseChunkData of llmResponseStream.stream()) {
const responseChunk = responseChunkData as GenerateResponseChunk;
console.log(responseChunk.text());
console.log(responseChunk.text);
}
```

Expand Down Expand Up @@ -454,7 +454,7 @@ const llmResponseStream = await generateStream({
for await (const responseChunkData of llmResponseStream.stream()) {
const responseChunk = responseChunkData as GenerateResponseChunk<Menu>;
// output() returns an object representing the entire output so far
const output: Menu | null = responseChunk.output();
const output: Menu | null = responseChunk.output;
console.log(output);
}
```
Expand Down Expand Up @@ -605,15 +605,15 @@ your users will not be interacting directly with the model in this way, the
conversational style of prompting is a powerful way to influence the output
generated by an AI model.

To generate message history from a model response, call the `toHistory()`
To generate message history from a model response, call the `.messages`
method:

```ts
let response = await generate({
model: gemini15Flash,
prompt: "How do you say 'dog' in French?",
});
let history = response.toHistory();
let history = response.messages;
```

You can serialize this history and persist it in a database or session storage.
Expand All @@ -625,7 +625,7 @@ response = await generate({
prompt: 'How about in Spanish?',
history,
});
history = response.toHistory();
history = response.messages;
```

If the model you're using supports the `system` role, you can use the initial
Expand Down
4 changes: 2 additions & 2 deletions docs/plugin-authoring-evaluator.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ export async function deliciousnessScore<
});

// Parse the output
const parsedResponse = response.output();
const parsedResponse = response.output;
if (!parsedResponse) {
throw new Error(`Unable to parse evaluator response: ${response.text()}`);
throw new Error(`Unable to parse evaluator response: ${response.text}`);
}

// Return a scored response
Expand Down
90 changes: 71 additions & 19 deletions docs/plugins/google-cloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,32 +221,84 @@ Common dimensions include:
- `topK` - the inference topK [value](https://ai.google.dev/docs/concepts#model-parameters).
- `topP` - the inference topP [value](https://ai.google.dev/docs/concepts#model-parameters).

### Flow-level metrics
### Feature-level metrics

Features are the top-level entry-point to your Genkit code. In most cases, this
will be a flow, but if you do not use flows, this will be the top-most span in a trace.

| Name | Type | Description |
| ----------------------- | --------- | ----------------------- |
| genkit/feature/requests | Counter | Number of requests |
| genkit/feature/latency | Histogram | Execution latency in ms |

Each feature-level metric contains the following dimensions:

| Name | Description |
| ------------- | -------------------------------------------------------------------------------- |
| name | The name of the feature. In most cases, this is the top-level Genkit flow |
| status | 'success' or 'failure' depending on whether or not the feature request succeeded |
| error | Only set when `status=failure`. Contains the error type that caused the failure |
| source | The Genkit source language. Eg. 'ts' |
| sourceVersion | The Genkit framework version |

| Name | Dimensions |
| -------------------- | ------------------------------------ |
| genkit/flow/requests | flow_name, error_code, error_message |
| genkit/flow/latency | flow_name |

### Action-level metrics

| Name | Dimensions |
| ---------------------- | ------------------------------------ |
| genkit/action/requests | flow_name, error_code, error_message |
| genkit/action/latency | flow_name |
Actions represent a generic step of execution within Genkit. Each of these steps
will have the following metrics tracked:

| Name | Type | Description |
| ----------------------- | --------- | --------------------------------------------- |
| genkit/action/requests | Counter | Number of times this action has been executed |
| genkit/action/latency | Histogram | Execution latency in ms |

Each action-level metric contains the following dimensions:

| Name | Description |
| ------------- | ---------------------------------------------------------------------------------------------------- |
| name | The name of the action |
| featureName | The name of the parent feature being executed |
| path | The path of execution from the feature root to this action. eg. '/myFeature/parentAction/thisAction' |
| status | 'success' or 'failure' depending on whether or not the action succeeded |
| error | Only set when `status=failure`. Contains the error type that caused the failure |
| source | The Genkit source language. Eg. 'ts' |
| sourceVersion | The Genkit framework version |

### Generate-level metrics

| Name | Dimensions |
| ------------------------------------ | -------------------------------------------------------------------- |
| genkit/ai/generate | flow_path, model, temperature, topK, topP, error_code, error_message |
| genkit/ai/generate/input_tokens | flow_path, model, temperature, topK, topP |
| genkit/ai/generate/output_tokens | flow_path, model, temperature, topK, topP |
| genkit/ai/generate/input_characters | flow_path, model, temperature, topK, topP |
| genkit/ai/generate/output_characters | flow_path, model, temperature, topK, topP |
| genkit/ai/generate/input_images | flow_path, model, temperature, topK, topP |
| genkit/ai/generate/output_images | flow_path, model, temperature, topK, topP |
| genkit/ai/generate/latency | flow_path, model, temperature, topK, topP, error_code, error_message |
These are special action metrics relating to actions that interact with a model.
In addition to requests and latency, input and output are also tracked, with model
specific dimensions that make debugging and configuration tuning easier.

| Name | Type | Description |
| ------------------------------------ | --------- | ------------------------------------------ |
| genkit/ai/generate/requests | Counter | Number of times this model has been called |
| genkit/ai/generate/latency | Histogram | Execution latency in ms |
| genkit/ai/generate/input/tokens | Counter | Input tokens |
| genkit/ai/generate/output/tokens | Counter | Output tokens |
| genkit/ai/generate/input/characters | Counter | Input characters |
| genkit/ai/generate/output/characters | Counter | Output characters |
| genkit/ai/generate/input/images | Counter | Input images |
| genkit/ai/generate/output/images | Counter | Output images |
| genkit/ai/generate/input/audio | Counter | Input audio files |
| genkit/ai/generate/output/audio | Counter | Output audio files |

Each generate-level metric contains the following dimensions:

| Name | Description |
| --------------- | ---------------------------------------------------------------------------------------------------- |
| modelName | The name of the model |
| featureName | The name of the parent feature being executed |
| path | The path of execution from the feature root to this action. eg. '/myFeature/parentAction/thisAction' |
| temperature | The temperature parameter passed to the model |
| maxOutputTokens | The maxOutputTokens parameter passed to the model |
| topK | The topK parameter passed to the model |
| topP | The topP parameter passed to the model |
| latencyMs | The response time taken by the model |
| status | 'success' or 'failure' depending on whether or not the feature request succeeded |
| error | Only set when `status=failure`. Contains the error type that caused the failure |
| source | The Genkit source language. Eg. 'ts' |
| sourceVersion | The Genkit framework version |

Visualizing metrics can be done through the Metrics Explorer. Using the side menu, select 'Logging' and click 'Metrics explorer'

Expand Down
2 changes: 1 addition & 1 deletion docs/prompts.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const response = await (threeGreetingsPrompt.generate<typeof outputSchema>(
{ input: { name: 'Fred' } }
));

response.output()?.likeAPirate
response.output?.likeAPirate
// "Ahoy there, Fred! May the winds be ever in your favor!"
```

Expand Down
6 changes: 3 additions & 3 deletions docs/rag.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ export const menuQAFlow = defineFlow(
context: docs,
});

const output = llmResponse.text();
const output = llmResponse.text;
return output;
}
);
Expand Down Expand Up @@ -333,7 +333,7 @@ defineSimpleRetriever({
// and several keys to use as metadata
metadata: ['from', 'to', 'subject'],
} async (query, config) => {
const result = await searchEmails(query.text(), {limit: config.limit});
const result = await searchEmails(query.text, {limit: config.limit});
return result.data.emails;
});
```
Expand Down Expand Up @@ -433,7 +433,7 @@ export const rerankFlow = defineFlow(
});

return rerankedDocuments.map((doc) => ({
text: doc.text(),
text: doc.text,
score: doc.metadata.score,
}));
}
Expand Down
2 changes: 1 addition & 1 deletion docs/tool-calling.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ while (true) {
throw Error('Tool not found');
}
}));
generateOptions.history = llmResponse.toHistory();
generateOptions.history = llmResponse.messages;
generateOptions.prompt = toolResponses;
}
```
2 changes: 1 addition & 1 deletion genkit-tools/cli/config/firebase.index.ts.template
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ export const menuSuggestionFlow = onFlow(
// convert it to a string, but more complicated flows might coerce the
// response into structured output or chain the response into another
// LLM call, etc.
return llmResponse.text();
return llmResponse.text;
}
);
2 changes: 1 addition & 1 deletion genkit-tools/cli/config/nextjs.genkit.ts.template
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const menuSuggestionFlow = ai.defineFlow(
// convert it to a string, but more complicated flows might coerce the
// response into structured output or chain the response into another
// LLM call, etc.
return llmResponse.text();
return llmResponse.text;
}
);

Expand Down
2 changes: 1 addition & 1 deletion genkit-tools/cli/config/nodejs.index.ts.template
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ export const menuSuggestionFlow = ai.defineFlow(
// Handle the response from the model API. In this sample, we just convert
// it to a string, but more complicated flows might coerce the response into
// structured output or chain the response into another LLM call, etc.
return llmResponse.text();
return llmResponse.text;
}
);
4 changes: 2 additions & 2 deletions genkit-tools/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "genkit-cli",
"version": "0.6.0-dev.2",
"version": "0.9.0-dev.1",
"description": "CLI for interacting with the Google Genkit AI framework",
"license": "Apache-2.0",
"keywords": [
Expand Down Expand Up @@ -28,7 +28,7 @@
"dependencies": {
"@genkit-ai/tools-common": "workspace:*",
"@genkit-ai/telemetry-server": "workspace:*",
"axios": "^1.6.7",
"axios": "^1.7.7",
"colorette": "^2.0.20",
"commander": "^11.1.0",
"extract-zip": "^2.0.1",
Expand Down
Loading

0 comments on commit 267c193

Please sign in to comment.