feat: add genkit

pull/643/head^2
Travis Fischer 2024-06-02 02:30:50 -05:00
rodzic 1d953a0ed2
commit e6263fbeac
12 zmienionych plików z 1257 dodań i 59 usunięć

Wyświetl plik

@ -0,0 +1,37 @@
#!/usr/bin/env node
import 'dotenv/config'
import { generate } from '@genkit-ai/ai'
import { configureGenkit } from '@genkit-ai/core'
import { gpt4o, openAI } from 'genkitx-openai'
import { WeatherClient } from '../../src/index.js'
import { tools } from '../../src/sdks/genkit.js'
async function main() {
const weather = new WeatherClient()
configureGenkit({
plugins: [openAI()]
})
const result = await generate({
model: gpt4o,
tools: tools(weather),
history: [
{
role: 'system',
content: [
{
text: 'You are a weather assistant. Be as concise as possible.'
}
]
}
],
prompt: [{ text: 'What is the weather in San Francisco?' }]
})
console.log(result)
}
await main()

Wyświetl plik

@ -24,10 +24,13 @@
"test:typecheck": "tsc --noEmit" "test:typecheck": "tsc --noEmit"
}, },
"dependencies": { "dependencies": {
"ai": "^3.1.22",
"@ai-sdk/openai": "^0.0.18", "@ai-sdk/openai": "^0.0.18",
"@dexaai/dexter": "^2.0.3", "@dexaai/dexter": "^2.0.3",
"@genkit-ai/ai": "^0.5.2",
"@genkit-ai/core": "^0.5.2",
"ai": "^3.1.22",
"dotenv": "^16.4.5", "dotenv": "^16.4.5",
"genkitx-openai": "^0.9.0",
"zod": "^3.23.3" "zod": "^3.23.3"
} }
} }

Wyświetl plik

@ -32,6 +32,11 @@
"types": "./dist/sdks/dexter.d.ts", "types": "./dist/sdks/dexter.d.ts",
"import": "./dist/sdks/dexter.js", "import": "./dist/sdks/dexter.js",
"default": "./dist/sdks/dexter.js" "default": "./dist/sdks/dexter.js"
},
"./genkit": {
"types": "./dist/sdks/genkit.d.ts",
"import": "./dist/sdks/genkit.js",
"default": "./dist/sdks/genkit.js"
} }
}, },
"files": [ "files": [
@ -68,6 +73,7 @@
"devDependencies": { "devDependencies": {
"@dexaai/dexter": "^2.0.3", "@dexaai/dexter": "^2.0.3",
"@fisch0920/eslint-config": "^1.3.1", "@fisch0920/eslint-config": "^1.3.1",
"@genkit-ai/ai": "^0.5.2",
"@total-typescript/ts-reset": "^0.5.1", "@total-typescript/ts-reset": "^0.5.1",
"@types/node": "^20.12.7", "@types/node": "^20.12.7",
"ai": "^3.1.22", "ai": "^3.1.22",

Plik diff jest za duży Load Diff

Wyświetl plik

@ -44,6 +44,12 @@
- move out to a separate project - move out to a separate project
- agentic - agentic
- walter - walter
- sdks
- ai sdk
- dexter
- genkit
- langchain
- instructor-js
- services - services
- wolfram alpha - wolfram alpha
- midjourney - midjourney

Wyświetl plik

@ -10,7 +10,7 @@ import { assert } from './utils.js'
export interface Invocable { export interface Invocable {
name: string name: string
description?: string description: string
inputSchema: z.AnyZodObject inputSchema: z.AnyZodObject
methodName: string methodName: string
} }
@ -59,7 +59,7 @@ export function aiFunction<
inputSchema inputSchema
}: { }: {
name?: string name?: string
description?: string description: string
inputSchema: InputSchema inputSchema: InputSchema
}) { }) {
return ( return (

Wyświetl plik

@ -3,6 +3,10 @@ import { tool } from 'ai'
import type { AIFunctionSet } from '../ai-function-set.js' import type { AIFunctionSet } from '../ai-function-set.js'
import { AIToolsProvider } from '../fns.js' import { AIToolsProvider } from '../fns.js'
/**
* Converts a set of Agentic stdlib AI functions to an object compatible with
* the Vercel AI SDK's `tools` parameter.
*/
export function tools(tools: AIToolsProvider | AIFunctionSet) { export function tools(tools: AIToolsProvider | AIFunctionSet) {
const fns = tools instanceof AIToolsProvider ? tools.functions : tools const fns = tools instanceof AIToolsProvider ? tools.functions : tools

Wyświetl plik

@ -3,6 +3,10 @@ import { createAIFunction } from '@dexaai/dexter'
import type { AIFunctionSet } from '../ai-function-set.js' import type { AIFunctionSet } from '../ai-function-set.js'
import { AIToolsProvider } from '../fns.js' import { AIToolsProvider } from '../fns.js'
/**
* Converts a set of Agentic stdlib AI functions to an array of Dexter-
* compatible AI functions.
*/
export function functions(input: AIToolsProvider | AIFunctionSet) { export function functions(input: AIToolsProvider | AIFunctionSet) {
const fns = input instanceof AIToolsProvider ? input.functions : input const fns = input instanceof AIToolsProvider ? input.functions : input

25
src/sdks/genkit.ts 100644
Wyświetl plik

@ -0,0 +1,25 @@
import { defineTool } from '@genkit-ai/ai'
import { z } from 'zod'
import type { AIFunctionSet } from '../ai-function-set.js'
import { AIToolsProvider } from '../fns.js'
/**
* Converts a set of Agentic stdlib AI functions to an array of Genkit-
* compatible tools.
*/
export function tools(input: AIToolsProvider | AIFunctionSet) {
const fns = input instanceof AIToolsProvider ? input.functions : input
return fns.map((fn) =>
defineTool(
{
name: fn.spec.name,
description: fn.spec.description,
inputSchema: fn.inputSchema,
outputSchema: z.any()
},
fn.impl
)
)
}

Wyświetl plik

@ -7,8 +7,5 @@ test('WeatherClient.functions', () => {
apiKey: 'sk-test' apiKey: 'sk-test'
}) })
const fns = [...weather.functions] expect(weather.functions.get('get_current_weather')).toBeTruthy()
console.log(fns)
expect(weather.functions.get('getCurrentWeather')).toBeTruthy()
}) })

Wyświetl plik

@ -13,7 +13,7 @@ export type RelaxedJsonifiable = Jsonifiable | Record<string, Jsonifiable>
export interface AIFunctionSpec { export interface AIFunctionSpec {
name: string name: string
description?: string description: string
parameters: Record<string, unknown> parameters: Record<string, unknown>
} }

Wyświetl plik

@ -2,7 +2,12 @@ import { defineConfig } from 'tsup'
export default defineConfig([ export default defineConfig([
{ {
entry: ['src/index.ts', 'src/sdks/ai-sdk.ts', 'src/sdks/dexter.ts'], entry: [
'src/index.ts',
'src/sdks/ai-sdk.ts',
'src/sdks/dexter.ts',
'src/sdks/genkit.ts'
],
outDir: 'dist', outDir: 'dist',
target: 'node18', target: 'node18',
platform: 'node', platform: 'node',