feat: add EchoAITool and turbo build pipeline

pull/657/head
Travis Fischer 2024-08-03 22:54:04 -05:00
rodzic 336c758752
commit a7647b893e
14 zmienionych plików z 121 dodań i 95 usunięć

4
.gitignore vendored
Wyświetl plik

@ -10,7 +10,6 @@ node_modules
# next.js
.next/
out/
# production
build/
@ -29,6 +28,9 @@ yarn-error.log*
# local env files
.env*.local
# turbo
.turbo
# vercel
.vercel

Wyświetl plik

@ -14,7 +14,6 @@
"build": "tsc",
"clean": "del dist",
"test": "run-s test:*",
"test:format": "prettier --check \"**/*.{js,ts,tsx}\"",
"test:lint": "eslint .",
"test:typecheck": "tsc --noEmit"
},

Wyświetl plik

@ -13,27 +13,16 @@
},
"type": "module",
"scripts": {
"build": "run-s build:*",
"build:core": "cd packages/core && pnpm build",
"build:ai-sdk": "cd packages/ai-sdk && pnpm build",
"build:weather": "cd packages/weather && pnpm build",
"build:examples": "cd examples/ai-sdk && pnpm build",
"clean": "run-s clean:*",
"clean:core": "cd packages/core && pnpm clean",
"clean:ai-sdk": "cd packages/ai-sdk && pnpm clean",
"clean:weather": "cd packages/weather && pnpm clean",
"clean:examples": "cd examples/ai-sdk && pnpm clean",
"prebuild": "run-s clean",
"precommit": "lint-staged",
"predev": "run-s clean",
"preinstall": "npx only-allow pnpm",
"pretest": "run-s build",
"prepare": "husky",
"test": "run-s test:*",
"build": "turbo build",
"clean": "turbo clean",
"test": "turbo test",
"test:format": "prettier --check \"**/*.{js,ts,tsx}\"",
"test:lint": "eslint .",
"test:typecheck": "tsc --noEmit",
"test:unit": "vitest run"
"test:lint": "turbo test:lint",
"test:typecheck": "turbo test:typecheck",
"test:unit": "turbo test:unit",
"precommit": "lint-staged",
"preinstall": "npx only-allow pnpm",
"prepare": "husky"
},
"devDependencies": {
"@fisch0920/eslint-config": "^1.4.0",

Wyświetl plik

@ -27,7 +27,6 @@
"dev": "tsup --watch",
"clean": "del dist",
"test": "run-s test:*",
"test:format": "prettier --check \"**/*.{js,ts,tsx}\"",
"test:lint": "eslint .",
"test:typecheck": "tsc --noEmit",
"test:unit": "vitest run"

Wyświetl plik

@ -0,0 +1,10 @@
import { EchoAITool } from '@agentic/core'
import { describe, expect, test } from 'vitest'
import { createAISDKTools } from './ai-sdk'
describe('ai-sdk', () => {
test('createAISDKTools', () => {
expect(createAISDKTools(new EchoAITool())).toHaveProperty('echo')
})
})

Wyświetl plik

@ -1,8 +1,7 @@
import { createAIFunction } from '@agentic/core'
import { evaluate } from 'mathjs'
import { z } from 'zod'
import { createAIFunction } from '../create-ai-function'
// TODO: ensure `expr` is sanitized to not run arbitrary code
export const CalculatorInputSchema = z.object({

Wyświetl plik

@ -27,7 +27,6 @@
"dev": "tsup --watch",
"clean": "del dist",
"test": "run-s test:*",
"test:format": "prettier --check \"**/*.{js,ts,tsx}\"",
"test:lint": "eslint .",
"test:typecheck": "tsc --noEmit",
"test:unit": "vitest run"
@ -52,7 +51,8 @@
"zod": "^3.23.3"
},
"devDependencies": {
"@agentic/tsconfig": "workspace:*"
"@agentic/tsconfig": "workspace:*",
"openai-fetch": "^2.0.4"
},
"publishConfig": {
"access": "public"

Wyświetl plik

@ -1,5 +1,3 @@
import 'dotenv/config'
import defaultKy, {
type AfterResponseHook,
type BeforeRequestHook,

Wyświetl plik

@ -2,32 +2,38 @@ import { expect, test } from 'vitest'
import { z } from 'zod'
import { AIFunctionSet } from './ai-function-set'
import { aiFunction, AIFunctionsProvider } from './fns'
import { calculator } from './tools/calculator'
import { createAIFunction } from './create-ai-function'
import { EchoAITool } from './echo'
class MockAITool extends AIFunctionsProvider {
@aiFunction({
name: 'echo',
description: 'Echoes the input.',
inputSchema: z.object({
query: z.string().describe('input query to echo')
})
})
async echo({ query }: { query: string }) {
return query
export const CalculatorInputSchema = z.object({
expr: z.string().describe('mathematical expression to evaluate')
})
export type CalculatorInput = z.infer<typeof CalculatorInputSchema>
const mockCalculator = createAIFunction(
{
name: 'calculator',
description:
'Computes the result of simple mathematical expressions. Handles basic arithmetic operations like addition, subtraction, multiplication, and division. Example expressions: "1 + 2", "3.4 * 5 / 9", "4 - 2"',
inputSchema: CalculatorInputSchema
},
async (input: CalculatorInput) => {
// eslint-disable-next-line no-eval, security/detect-eval-with-expression
const result: number = eval(input.expr)
return result
}
}
)
test('AIFunctionSet constructor', () => {
const mockAITool = new MockAITool()
const s0 = new AIFunctionSet([mockAITool, calculator])
const mockAITool = new EchoAITool()
const s0 = new AIFunctionSet([mockAITool, mockCalculator])
expect(s0.size).toEqual(2)
expect(s0.get('echo')).toBeDefined()
expect(s0.get('calculator')).toBeDefined()
expect([...s0].length).toEqual(2)
const s1 = new AIFunctionSet([s0, mockAITool, calculator, calculator])
const s1 = new AIFunctionSet([s0, mockAITool, mockCalculator, mockCalculator])
expect(s0.size).toEqual(2)
expect(s1.size).toEqual(2)
expect(s1.get('echo')).toBeDefined()
@ -36,9 +42,9 @@ test('AIFunctionSet constructor', () => {
})
test('AIFunctionSet constructor invalid function', () => {
const mockAITool = new MockAITool()
const mockAITool = new EchoAITool()
expect(
() => new AIFunctionSet([mockAITool, calculator, { spec: {} } as any])
() => new AIFunctionSet([mockAITool, mockCalculator, { spec: {} } as any])
).toThrowError('Invalid AIFunctionLike: [object Object]')
})

Wyświetl plik

@ -0,0 +1,30 @@
import { z } from 'zod'
import { createAIFunction } from './create-ai-function'
import { aiFunction, AIFunctionsProvider } from './fns'
export class EchoAITool extends AIFunctionsProvider {
@aiFunction({
name: 'echo',
description: 'Echoes the input.',
inputSchema: z.object({
query: z.string().describe('input query to echo')
})
})
async echo({ query }: { query: string }) {
return query
}
}
export const echoAIFunction = createAIFunction(
{
name: 'echo',
description: 'Echoes the input.',
inputSchema: z.object({
query: z.string().describe('input query to echo')
})
},
({ query }: { query: string }) => {
return query
}
)

Wyświetl plik

@ -1,6 +1,7 @@
export * from './ai-function-set'
export * from './create-ai-chain'
export * from './create-ai-function'
export * from './echo'
export * from './errors'
export * from './extract-object'
export * from './fns'

Wyświetl plik

@ -27,7 +27,6 @@
"dev": "tsup --watch",
"clean": "del dist",
"test": "run-s test:*",
"test:format": "prettier --check \"**/*.{js,ts,tsx}\"",
"test:lint": "eslint .",
"test:typecheck": "tsc --noEmit"
},

Wyświetl plik

@ -158,6 +158,9 @@ importers:
'@agentic/tsconfig':
specifier: workspace:*
version: link:../tsconfig
openai-fetch:
specifier: ^2.0.4
version: 2.0.4
packages/tsconfig: {}
@ -2900,6 +2903,10 @@ packages:
resolution: {integrity: sha512-mnkeQ1qP5Ue2wd+aivTD3NHd/lZ96Lu0jgf0pwktLPtx6cTZiH7tyeGRRHs0zX0rbrahXPnXlUnbeXyaBBuIaw==}
engines: {node: '>=18'}
openai-fetch@2.0.4:
resolution: {integrity: sha512-+1sC+mYpGi79YXaJsySxTtYeWkDULS/fhRCr8PLI+xcpnqFfoFY/VL0f4avQAnJSf1LZRaTrrKOK8yqxrYI5BQ==}
engines: {node: '>=18'}
openai@4.54.0:
resolution: {integrity: sha512-e/12BdtTtj+tXs7iHm+Dm7H7WjEWnw7O52B2wSfCQ6lD5F6cvjzo7cANXy5TJ1Q3/qc8YRPT5wBTTFtP5sBp1g==}
hasBin: true
@ -4393,8 +4400,8 @@ snapshots:
'@typescript-eslint/parser': 7.17.0(eslint@8.57.0)(typescript@5.5.4)
'@typescript-eslint/utils': 7.17.0(eslint@8.57.0)(typescript@5.5.4)
eslint-config-prettier: 9.1.0(eslint@8.57.0)
eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0))(eslint@8.57.0)
eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0)
eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint-plugin-import@2.29.1)(eslint@8.57.0)
eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0)
eslint-plugin-jest: 28.6.0(@typescript-eslint/eslint-plugin@7.17.0(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4)
eslint-plugin-jest-dom: 5.4.0(eslint@8.57.0)
eslint-plugin-jsx-a11y: 6.9.0(eslint@8.57.0)
@ -5629,13 +5636,13 @@ snapshots:
transitivePeerDependencies:
- supports-color
eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0))(eslint@8.57.0):
eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint-plugin-import@2.29.1)(eslint@8.57.0):
dependencies:
debug: 4.3.6
enhanced-resolve: 5.17.1
eslint: 8.57.0
eslint-module-utils: 2.8.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0)
eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0)
eslint-module-utils: 2.8.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint-plugin-import@2.29.1)(eslint@8.57.0))(eslint@8.57.0)
eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0)
fast-glob: 3.3.2
get-tsconfig: 4.7.6
is-core-module: 2.15.0
@ -5646,18 +5653,18 @@ snapshots:
- eslint-import-resolver-webpack
- supports-color
eslint-module-utils@2.8.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0):
eslint-module-utils@2.8.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint-plugin-import@2.29.1)(eslint@8.57.0))(eslint@8.57.0):
dependencies:
debug: 3.2.7
optionalDependencies:
'@typescript-eslint/parser': 7.17.0(eslint@8.57.0)(typescript@5.5.4)
eslint: 8.57.0
eslint-import-resolver-node: 0.3.9
eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0))(eslint@8.57.0)
eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint-plugin-import@2.29.1)(eslint@8.57.0)
transitivePeerDependencies:
- supports-color
eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0):
eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0):
dependencies:
array-includes: 3.1.8
array.prototype.findlastindex: 1.2.5
@ -5667,7 +5674,7 @@ snapshots:
doctrine: 2.1.0
eslint: 8.57.0
eslint-import-resolver-node: 0.3.9
eslint-module-utils: 2.8.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0)
eslint-module-utils: 2.8.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.17.0(eslint@8.57.0)(typescript@5.5.4))(eslint-plugin-import@2.29.1)(eslint@8.57.0))(eslint@8.57.0)
hasown: 2.0.2
is-core-module: 2.15.0
is-glob: 4.0.3
@ -7006,6 +7013,10 @@ snapshots:
is-inside-container: 1.0.0
is-wsl: 3.1.0
openai-fetch@2.0.4:
dependencies:
ky: 1.5.0
openai@4.54.0:
dependencies:
'@types/node': 18.19.43

Wyświetl plik

@ -1,54 +1,37 @@
{
"$schema": "https://turbo.build/schema.json",
"pipeline": {
"ui": "stream",
"tasks": {
"build": {
"dependsOn": ["^build"],
"env": [
"ANTHROPIC_API_KEY",
"AWS_REGION",
"AWS_ACCESS_KEY_ID",
"AWS_SECRET_ACCESS_KEY",
"COHERE_API_KEY",
"FIREWORKS_API_KEY",
"GOOGLE_API_KEY",
"GROQ_API_KEY",
"HUGGINGFACE_API_KEY",
"MISTRAL_API_KEY",
"OPENAI_API_KEY",
"OPENAI_API_BASE",
"PERPLEXITY_API_KEY",
"REPLICATE_API_KEY",
"NODE_ENV",
"ASSISTANT_ID",
"INKEEP_API_KEY",
"INKEEP_INTEGRATION_ID",
"VERCEL_URL"
],
"outputs": ["dist/**"]
},
"lint": {
"dependsOn": ["^lint"]
},
"type-check": {
"dependsOn": ["^build", "build"]
"clean": {
"dependsOn": ["^clean"],
"outputs": ["dist/**"]
},
"test": {
"dependsOn": ["^build", "build"]
"dependsOn": [
"build",
"test:format",
"test:lint",
"test:typecheck",
"test:unit"
]
},
"publint": {
"dependsOn": ["^build", "build"]
"test:lint": {
"dependsOn": ["^test:lint"]
},
"clean": {
"dependsOn": ["^clean"]
"test:typecheck": {
"dependsOn": ["^test:typecheck"]
},
"test:unit": {
"dependsOn": ["^test:unit"]
},
"test:format": {},
"dev": {
"cache": false,
"persistent": true
},
"prettier-check": {},
"integration-test": {
"dependsOn": ["^build", "build"]
}
},
"globalEnv": ["CI", "PORT"]
}
}