feat: add browserbase example and update deps

pull/643/head^2
Travis Fischer 2024-06-07 00:18:06 -05:00
rodzic efa568f54d
commit 2ff3065b47
7 zmienionych plików z 1654 dodań i 210 usunięć

Wyświetl plik

@ -0,0 +1,26 @@
#!/usr/bin/env node
import 'dotenv/config'
import { openai } from '@ai-sdk/openai'
import { Browserbase, BrowserbaseAISDK } from '@browserbasehq/sdk'
import { generateText } from 'ai'
async function main() {
const browserbase = new Browserbase()
const browserTool = BrowserbaseAISDK(browserbase, { textContent: true })
console.log(browserTool.parameters)
const result = await generateText({
model: openai('gpt-4o'),
tools: { browserTool },
toolChoice: 'required',
temperature: 0,
system: 'You are a helpful assistant. Be as concise as possible.',
prompt: 'What is the weather in San Francisco?'
})
console.log(result.toolResults[0])
}
await main()

Wyświetl plik

@ -69,7 +69,7 @@
], ],
"scripts": { "scripts": {
"preinstall": "npx only-allow pnpm", "preinstall": "npx only-allow pnpm",
"build": "tsc", "build": "tsup",
"clean": "del dist", "clean": "del dist",
"prebuild": "run-s clean", "prebuild": "run-s clean",
"predev": "run-s clean", "predev": "run-s clean",
@ -83,7 +83,7 @@
"test:unit": "vitest run" "test:unit": "vitest run"
}, },
"dependencies": { "dependencies": {
"@nangohq/node": "^0.39.32", "@nangohq/node": "^0.39.33",
"dedent": "^1.5.3", "dedent": "^1.5.3",
"delay": "^6.0.0", "delay": "^6.0.0",
"hash-object": "^5.0.1", "hash-object": "^5.0.1",
@ -94,36 +94,37 @@
"p-map": "^7.0.2", "p-map": "^7.0.2",
"p-throttle": "^6.1.0", "p-throttle": "^6.1.0",
"quick-lru": "^7.0.0", "quick-lru": "^7.0.0",
"type-fest": "^4.18.3", "type-fest": "^4.19.0",
"zod": "^3.23.3", "zod": "^3.23.3",
"zod-to-json-schema": "^3.23.0" "zod-to-json-schema": "^3.23.0"
}, },
"devDependencies": { "devDependencies": {
"@browserbasehq/sdk": "^1.2.1",
"@dexaai/dexter": "^2.0.3", "@dexaai/dexter": "^2.0.3",
"@e2b/code-interpreter": "^0.0.7", "@e2b/code-interpreter": "^0.0.7",
"@fisch0920/eslint-config": "^1.3.3", "@fisch0920/eslint-config": "^1.3.3",
"@genkit-ai/ai": "^0.5.2", "@genkit-ai/ai": "^0.5.2",
"@instructor-ai/instructor": "^1.3.0", "@instructor-ai/instructor": "^1.3.0",
"@langchain/core": "^0.2.5", "@langchain/core": "^0.2.6",
"@total-typescript/ts-reset": "^0.5.1", "@total-typescript/ts-reset": "^0.5.1",
"@types/node": "^20.13.0", "@types/node": "^20.14.2",
"ai": "^3.1.22", "ai": "^3.1.30",
"del-cli": "^5.1.0", "del-cli": "^5.1.0",
"dotenv": "^16.4.5", "dotenv": "^16.4.5",
"eslint": "^8.57.0", "eslint": "^8.57.0",
"expr-eval": "^2.0.2", "expr-eval": "^2.0.2",
"husky": "^9.0.11", "husky": "^9.0.11",
"lint-staged": "^15.2.5", "lint-staged": "^15.2.5",
"llamaindex": "^0.3.15", "llamaindex": "^0.3.16",
"np": "^10.0.5", "np": "^10.0.5",
"npm-run-all2": "^6.2.0", "npm-run-all2": "^6.2.0",
"only-allow": "^1.2.1", "only-allow": "^1.2.1",
"openai-fetch": "^2.0.3", "openai-fetch": "^2.0.3",
"prettier": "^3.2.5", "prettier": "^3.3.1",
"restore-cursor": "^5.0.0", "restore-cursor": "^5.0.0",
"ts-node": "^10.9.2", "ts-node": "^10.9.2",
"tsup": "^8.0.2", "tsup": "^8.1.0",
"tsx": "^4.11.0", "tsx": "^4.13.0",
"twitter-api-sdk": "^1.2.1", "twitter-api-sdk": "^1.2.1",
"typescript": "^5.4.5", "typescript": "^5.4.5",
"vitest": "2.0.0-beta.3" "vitest": "2.0.0-beta.3"

Plik diff jest za duży Load Diff

Wyświetl plik

@ -175,6 +175,7 @@ Note that many of these clients expose multiple AI functions.
- sdks - sdks
- modelfusion - modelfusion
- services - services
- browserbase
- [phantombuster](https://phantombuster.com) - [phantombuster](https://phantombuster.com)
- perplexity - perplexity
- valtown - valtown
@ -186,14 +187,22 @@ Note that many of these clients expose multiple AI functions.
- pull from [nango](https://docs.nango.dev/integrations/overview) - pull from [nango](https://docs.nango.dev/integrations/overview)
- pull from [activepieces](https://github.com/activepieces/activepieces/tree/main/packages/pieces/community) - pull from [activepieces](https://github.com/activepieces/activepieces/tree/main/packages/pieces/community)
- general openapi support ala [workgpt](https://github.com/team-openpm/workgpt) - general openapi support ala [workgpt](https://github.com/team-openpm/workgpt)
- tools / chains / flows / runnables - compound tools / chains / flows / runnables
- market maps - market maps
- https://github.com/causaly/zod-validation-error - incorporate [zod-validation-error](https://github.com/causaly/zod-validation-error)
- investigate [autotool](https://github.com/run-llama/LlamaIndexTS/tree/main/packages/autotool) - investigate [autotool](https://github.com/run-llama/LlamaIndexTS/tree/main/packages/autotool)
- investigate [data connectors](https://github.com/mendableai/data-connectors) - investigate [data connectors](https://github.com/mendableai/data-connectors)
## Contributors
- [Travis Fischer](https://x.com/transitive_bs)
- [Kevin Raheja](https://x.com/crabfisher)
- [David Zhang](https://x.com/dzhng)
- [Philipp Burckhardt](https://x.com/burckhap)
- [Riley Tomasek](https://x.com/rileytomasek)
## License ## License
MIT © [Travis Fischer](https://twitter.com/transitive_bs) MIT © [Travis Fischer](https://x.com/transitive_bs)
To stay up to date or learn more, follow [@transitive_bs](https://twitter.com/transitive_bs) on Twitter. To stay up to date or learn more, follow [@transitive_bs](https://x.com/transitive_bs) on Twitter.

Wyświetl plik

@ -1,5 +1,3 @@
import './symbol-polyfill.js'
import type { z } from 'zod' import type { z } from 'zod'
import type * as types from './types.js' import type * as types from './types.js'
@ -14,6 +12,27 @@ export interface PrivateAIFunctionMetadata {
methodName: string methodName: string
} }
// Polyfill for `Symbol.metadata`
// https://github.com/microsoft/TypeScript/issues/53461
declare global {
interface SymbolConstructor {
readonly metadata: unique symbol
}
}
;(Symbol as any).metadata ??= Symbol.for('Symbol.metadata')
const _metadata = Object.create(null)
if (typeof Symbol === 'function' && Symbol.metadata) {
Object.defineProperty(globalThis, Symbol.metadata, {
enumerable: true,
configurable: true,
writable: true,
value: _metadata
})
}
export abstract class AIFunctionsProvider { export abstract class AIFunctionsProvider {
private _functions?: AIFunctionSet private _functions?: AIFunctionSet
@ -72,6 +91,7 @@ export function aiFunction<
if (!context.metadata.invocables) { if (!context.metadata.invocables) {
context.metadata.invocables = [] context.metadata.invocables = []
} }
;(context.metadata.invocables as PrivateAIFunctionMetadata[]).push({ ;(context.metadata.invocables as PrivateAIFunctionMetadata[]).push({
name: name ?? methodName, name: name ?? methodName,
description, description,
@ -79,12 +99,6 @@ export function aiFunction<
methodName methodName
}) })
// console.log({
// name,
// methodName,
// context
// })
context.addInitializer(function () { context.addInitializer(function () {
;(this as any)[methodName] = (this as any)[methodName].bind(this) ;(this as any)[methodName] = (this as any)[methodName].bind(this)
}) })

Wyświetl plik

@ -1,29 +0,0 @@
// https://github.com/microsoft/TypeScript/issues/53461
// symbol-polyfill.ts
declare global {
interface SymbolConstructor {
readonly metadata: unique symbol
}
}
;(Symbol as any).metadata ??= Symbol.for('Symbol.metadata')
const _metadata = Object.create(null)
if (typeof Symbol === 'function' && Symbol.metadata) {
Object.defineProperty(globalThis, Symbol.metadata, {
enumerable: true,
configurable: true,
writable: true,
value: _metadata
})
}
// export {};
// declare global {
// interface SymbolConstructor {
// readonly metadata: unique symbol
// }
// }
// (Symbol as any).metadata ??= Symbol.for("Symbol.metadata")

Wyświetl plik

@ -122,7 +122,7 @@ export function sanitizeSearchParams(
} }
return [[key, String(value)]] return [[key, String(value)]]
}) }) as [string, string][]
) )
} }