Skip to content
This repository was archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into MichaelDoyle-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
Dabolus authored May 14, 2024
2 parents eca82f5 + 4866d2a commit 02394b5
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 1,520 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"name": "genkit-plugins-root",
"private": true,
"version": "0.1.0",
"version": "0.3.0",
"scripts": {
"build": "yarn workspaces foreach -Rip --from 'genkitx-*' run build",
"test": "yarn workspaces foreach -Rip --from 'genkitx-*' run test"
},
"devDependencies": {
"npm-run-all": "^4.1.5",
"typescript": "^4.9.5"
},
"workspaces": [
Expand Down
10 changes: 10 additions & 0 deletions plugins/anthropic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ pnpm add genkitx-anthropic
yarn add genkitx-anthropic
```

The plugin depends on Genkit core packages, so make sure to have them installed as well:

```bash
npm install @genkit-ai/core @genkit-ai/ai
# or
pnpm add @genkit-ai/core @genkit-ai/ai
# or
yarn add @genkit-ai/core @genkit-ai/ai
```

## Example Claude 3 Haiku flow

```ts
Expand Down
10 changes: 7 additions & 3 deletions plugins/anthropic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"genai",
"generative-ai"
],
"version": "0.2.0",
"version": "0.3.0",
"type": "commonjs",
"repository": {
"type": "git",
Expand All @@ -26,11 +26,15 @@
"license": "Apache-2.0",
"dependencies": {
"@anthropic-ai/sdk": "^0.20.9",
"@genkit-ai/ai": "0.5.0",
"@genkit-ai/core": "0.5.0",
"zod": "^3.23.8"
},
"peerDependencies": {
"@genkit-ai/ai": "^0.5.0",
"@genkit-ai/core": "^0.5.0"
},
"devDependencies": {
"@genkit-ai/ai": "^0.5.0",
"@genkit-ai/core": "^0.5.0",
"@types/node": "^20.12.11",
"npm-run-all": "^4.1.5",
"tsup": "^8.0.2",
Expand Down
12 changes: 6 additions & 6 deletions plugins/anthropic/src/claude.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Message } from '@genkit-ai/ai';
import {
CandidateData,
defineModel,
GenerateRequest,
MessageData,
modelRef,
ModelReference,
Part,
Role,
type CandidateData,
type GenerateRequest,
type MessageData,
type ModelReference,
type Part,
type Role,
} from '@genkit-ai/ai/model';
import Anthropic from '@anthropic-ai/sdk';
import z from 'zod';
Expand Down
2 changes: 1 addition & 1 deletion plugins/anthropic/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { genkitPlugin, Plugin } from '@genkit-ai/core';
import { genkitPlugin, type Plugin } from '@genkit-ai/core';
import Anthropic from '@anthropic-ai/sdk';
import {
claude3Opus,
Expand Down
10 changes: 10 additions & 0 deletions plugins/openai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ pnpm add genkitx-openai
yarn add genkitx-openai
```

The plugin depends on Genkit core packages, so make sure to have them installed as well:

```bash
npm install @genkit-ai/core @genkit-ai/ai
# or
pnpm add @genkit-ai/core @genkit-ai/ai
# or
yarn add @genkit-ai/core @genkit-ai/ai
```

## Example GPT-4 Turbo flow

```ts
Expand Down
10 changes: 7 additions & 3 deletions plugins/openai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"genai",
"generative-ai"
],
"version": "0.2.0",
"version": "0.3.0",
"type": "commonjs",
"repository": {
"type": "git",
Expand All @@ -24,12 +24,16 @@
"author": "Dabolus",
"license": "Apache-2.0",
"dependencies": {
"@genkit-ai/ai": "0.5.0",
"@genkit-ai/core": "0.5.0",
"openai": "^4.43.0",
"zod": "^3.23.8"
},
"peerDependencies": {
"@genkit-ai/ai": "^0.5.0",
"@genkit-ai/core": "^0.5.0",
},
"devDependencies": {
"@genkit-ai/ai": "^0.5.0",
"@genkit-ai/core": "^0.5.0",
"@types/node": "^20.12.11",
"npm-run-all": "^4.1.5",
"tsup": "^8.0.2",
Expand Down
11 changes: 6 additions & 5 deletions plugins/openai/src/dalle.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Message } from '@genkit-ai/ai';
import {
defineModel,
GenerateRequest,
GenerateResponseData,
ModelAction,
modelRef,
type GenerateRequest,
type GenerateResponseData,
type ModelAction,
} from '@genkit-ai/ai/model';
import OpenAI from 'openai';
import {
ImageGenerateParams,
ImagesResponse,
type ImageGenerateParams,
type ImagesResponse,
} from 'openai/resources/images.mjs';
import { z } from 'zod';

Expand All @@ -29,6 +29,7 @@ export const dallE3 = modelRef({
media: false,
output: ['media'],
multiturn: false,
systemRole: false,
tools: false,
},
},
Expand Down
10 changes: 5 additions & 5 deletions plugins/openai/src/embedder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineEmbedder, embedderRef } from '@genkit-ai/ai/embedder';
import OpenAI from 'openai';
import { z } from 'zod';
import { PluginOptions } from '.';
import { type PluginOptions } from './index.js';

export const TextEmbeddingConfigSchema = z.object({
dimensions: z.number().optional(),
Expand Down Expand Up @@ -60,7 +60,7 @@ export function openaiEmbedder(name: string, options?: PluginOptions) {
let apiKey = options?.apiKey || process.env.OPENAI_API_KEY;
if (!apiKey)
throw new Error(
'please pass in the API key or set the OPENAI_API_KEY environment variable'
'please pass in the API key or set the OPENAI_API_KEY environment variable',
);
const model = SUPPORTED_EMBEDDING_MODELS[name];
if (!model) throw new Error(`Unsupported model: ${name}`);
Expand All @@ -75,13 +75,13 @@ export function openaiEmbedder(name: string, options?: PluginOptions) {
async (input, options) => {
const embeddings = await client.embeddings.create({
model: name,
input: input.map((d) => d.text()),
input: input.map(d => d.text()),
dimensions: options?.dimensions,
encoding_format: options?.encodingFormat,
});
return {
embeddings: embeddings.data.map((d) => ({ embedding: d.embedding })),
embeddings: embeddings.data.map(d => ({ embedding: d.embedding })),
};
}
},
);
}
38 changes: 21 additions & 17 deletions plugins/openai/src/gpt.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { Message } from '@genkit-ai/ai';
import {
CandidateData,
defineModel,
GenerateRequest,
MessageData,
modelRef,
Part,
Role,
ToolDefinition,
ToolRequestPart,
type CandidateData,
type GenerateRequest,
type MessageData,
type Part,
type Role,
type ToolDefinition,
type ToolRequestPart,
} from '@genkit-ai/ai/model';
import OpenAI from 'openai';
import {
ChatCompletion,
ChatCompletionChunk,
ChatCompletionContentPart,
ChatCompletionCreateParamsNonStreaming,
ChatCompletionMessageParam,
ChatCompletionMessageToolCall,
ChatCompletionRole,
ChatCompletionTool,
CompletionChoice,
} from 'openai/resources/index';
type ChatCompletion,
type ChatCompletionChunk,
type ChatCompletionContentPart,
type ChatCompletionCreateParamsNonStreaming,
type ChatCompletionMessageParam,
type ChatCompletionMessageToolCall,
type ChatCompletionRole,
type ChatCompletionTool,
type CompletionChoice,
} from 'openai/resources/index.mjs';
import z from 'zod';

const API_NAME_MAP = {
Expand Down Expand Up @@ -60,6 +60,7 @@ export const gpt4Turbo = modelRef({
multiturn: true,
tools: true,
media: false,
systemRole: true,
output: ['text', 'json'],
},
},
Expand All @@ -75,6 +76,7 @@ export const gpt4Vision = modelRef({
multiturn: true,
tools: false,
media: true,
systemRole: true,
output: ['text'],
},
},
Expand All @@ -90,6 +92,7 @@ export const gpt4 = modelRef({
multiturn: true,
tools: true,
media: false,
systemRole: true,
output: ['text'],
},
},
Expand All @@ -105,6 +108,7 @@ export const gpt35Turbo = modelRef({
multiturn: true,
tools: true,
media: false,
systemRole: true,
output: ['json', 'text'],
},
},
Expand Down
2 changes: 1 addition & 1 deletion plugins/openai/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { genkitPlugin, Plugin } from '@genkit-ai/core';
import { genkitPlugin, type Plugin } from '@genkit-ai/core';
import OpenAI from 'openai';
import { dallE3, dallE3Model } from './dalle.js';
import {
Expand Down
Loading

0 comments on commit 02394b5

Please sign in to comment.