Skip to content

Commit

Permalink
Merge branch 'xavier/genkit-09' into dependabot/npm_and_yarn/typescri…
Browse files Browse the repository at this point in the history
…pt-eslint-8.14.0
  • Loading branch information
xavidop authored Nov 13, 2024
2 parents aaff6f1 + 1c5ef1a commit b258f9e
Show file tree
Hide file tree
Showing 7 changed files with 285 additions and 91 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/depsreview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/dependency-review-action@v4
- uses: actions/dependency-review-action@v4.3.3
with:
allow-licenses: BSD-2-Clause, BSD-3-Clause, MIT, Apache-2.0, MPL-2.0, ISC, LGPL-3.0, 0BSD
allow-licenses: BSD-2-Clause, MIT, Apache-2.0, MPL-2.0, ISC, LGPL-3.0, 0BSD, BSD-3-Clause, BSD-3-Clause AND BSD-3-Clause-Clear
46 changes: 25 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,43 @@ Install the plugin in your project with your favorite package manager:
- `npm install genkitx-github`
- `pnpm add genkitx-github`

### Versions

if you are using Genkit version `<v0.9.0` or lower, please use the plugin version `v1.9.0`. If you are using Genkit `>=v0.9.0`, please use the plugin version `v2.0.0`.

## Usage

### Configuration

To use the plugin, you need to configure it with your GitHub Token key. You can do this by calling the `configureGenkit` function:
To use the plugin, you need to configure it with your GitHub Token key. You can do this by calling the `genkit` function:

```typescript
import { genkit, z } from 'genkit';
import {github, openAIGpt4o} from "genkitx-github";

configureGenkit({
const ai = genkit({
plugins: [
github({
githubToken: '<my-github-token>',
}),
],
logLevel: "debug",
enableTracingAndMetrics: true,
model: openAIGpt4o,
]
});
```

You can also intialize the plugin in this way if you have set the `GITHUB_TOKEN` environment variable:

```typescript
import { genkit, z } from 'genkit';
import {github, openAIGpt4o} from "genkitx-github";

configureGenkit({
const ai = genkit({
plugins: [
github({}),
],
logLevel: "debug",
enableTracingAndMetrics: true,
github({
githubToken: '<my-github-token>',
}),
model: openAIGpt4o,
]
});
```

Expand All @@ -72,35 +78,34 @@ configureGenkit({
The simplest way to call the text generation model is by using the helper function `generate`:

```typescript
import { genkit, z } from 'genkit';
import {github, openAIGpt4o} from "genkitx-github";

// Basic usage of an LLM
const response = await generate({
model: openAIGpt4o, // model imported from genkitx-github
const response = await ai.generate({
prompt: 'Tell me a joke.',
});

console.log(await response.text());
console.log(await response.text);
```

### Within a flow

```typescript
// ...configure Genkit (as shown above)...

export const myFlow = defineFlow(
export const myFlow = ai.defineFlow(
{
name: 'menuSuggestionFlow',
inputSchema: z.string(),
outputSchema: z.string(),
},
async (subject) => {
const llmResponse = await generate({
const llmResponse = await ai.generate({
prompt: `Suggest an item for the menu of a ${subject} themed restaurant`,
model: openAIGpt4o,
});

return llmResponse.text();
return llmResponse.text;
}
);
```
Expand All @@ -111,7 +116,7 @@ export const myFlow = defineFlow(
// ...configure Genkit (as shown above)...

const specialToolInputSchema = z.object({ meal: z.enum(["breakfast", "lunch", "dinner"]) });
const specialTool = defineTool(
const specialTool = ai.defineTool(
{
name: "specialTool",
description: "Retrieves today's special for the given meal",
Expand All @@ -125,13 +130,12 @@ const specialTool = defineTool(
}
);

const result = generate({
model: openAIGpt4o,
const result = ai.generate({
tools: [specialTool],
prompt: "What's for breakfast?",
});

console.log(result.then((res) => res.text()));
console.log(result.then((res) => res.text));
```

For more detailed examples and the explanation of other functionalities, refer to the [official Genkit documentation](https://firebase.google.com/docs/genkit/get-started).
Expand Down
Loading

0 comments on commit b258f9e

Please sign in to comment.