Node.js client for the unofficial ChatGPT API.
 
 
 
Go to file
Travis Fischer 33cbc5a6b6 2024-08-17 06:53:23 -05:00
.changeset feat: bump version to 7.0.0 for new major release 2024-08-04 06:50:05 -05:00
.github fix: turbo CI 2024-08-08 00:32:37 -05:00
.husky
docs 2024-08-17 06:53:23 -05:00
examples feat: relax chatFn types 2024-08-07 05:53:39 -05:00
packages feat: bump deps; fix eslint 2024-08-17 04:36:19 -05:00
.editorconfig
.env.example
.eslintrc.json feat: bump deps; fix eslint 2024-08-17 04:36:19 -05:00
.gitignore feat: add EchoAITool and turbo build pipeline 2024-08-03 22:54:04 -05:00
.npmrc
.prettierignore
.prettierrc
license
package.json docs: improve docs 2024-08-17 06:03:17 -05:00
pnpm-lock.yaml docs: improve docs 2024-08-17 06:03:17 -05:00
pnpm-workspace.yaml feat: WIP closer to completing monorepo transition 2024-08-04 01:32:30 -05:00
readme.md 2024-08-17 06:53:23 -05:00
tsup.config.ts feat: WIP refactor to monorepo and separate packages 2024-08-03 21:36:44 -05:00
turbo.json fix: turbo CI 2024-08-08 00:32:37 -05:00
vite.config.ts

readme.md

Agentic

AI agent stdlib that works with any LLM and TypeScript AI SDK.

Build Status NPM MIT License Prettier Code Formatting

Agentic

Intro

Agentic is a standard library of AI functions / tools which are optimized for both normal TS-usage as well as LLM-based usage. Agentic works with all of the major TS AI SDKs (LangChain, LlamaIndex, Vercel AI SDK, OpenAI SDK, etc).

Agentic clients like WeatherClient can be used as normal TS classes:

import { WeatherClient } from '@agentic/stdlib'

// Requires `process.env.WEATHER_API_KEY` (free from weatherapi.com)
const weather = new WeatherClient()

const result = await weather.getCurrentWeather({
  q: 'San Francisco'
})
console.log(result)

Or you can use these clients as LLM-based tools where the LLM decides when and how to invoke the underlying functions for you.

This works across all of the major AI SDKs via adapters. Here's an example using Vercel's AI SDK:

// sdk-specific imports
import { openai } from '@ai-sdk/openai'
import { generateText } from 'ai'
import { createAISDKTools } from '@agentic/ai-sdk'

// sdk-agnostic imports
import { WeatherClient } from '@agentic/stdlib'

const weather = new WeatherClient()

const result = await generateText({
  model: openai('gpt-4o-mini'),
  // this is the key line which uses the `@agentic/ai-sdk` adapter
  tools: createAISDKTools(weather),
  toolChoice: 'required',
  prompt: 'What is the weather in San Francisco?'
})

console.log(result.toolResults[0])

You can use our standard library of thoroughly tested AI functions with your favorite AI SDK – without having to write any glue code!

Here's a slightly more complex example which uses multiple clients and selects a subset of their functions using the AIFunctionSet.pick method:

// sdk-specific imports
import { ChatModel, createAIRunner } from '@dexaai/dexter'
import { createDexterFunctions } from '@agentic/dexter'

// sdk-agnostic imports
import { PerigonClient, SerperClient } from '@agentic/stdlib'

async function main() {
  // Perigon is a news API and Serper is a Google search API
  const perigon = new PerigonClient()
  const serper = new SerperClient()

  const runner = createAIRunner({
    chatModel: new ChatModel({
      params: { model: 'gpt-4o-mini', temperature: 0 }
    }),
    functions: createDexterFunctions(
      perigon.functions.pick('search_news_stories'),
      serper
    ),
    systemMessage: 'You are a helpful assistant. Be as concise as possible.'
  })

  const result = await runner(
    'Summarize the latest news stories about the upcoming US election.'
  )
  console.log(result)
}

Here we've exposed 2 functions to the LLM, search_news_stories (which comes from the PerigonClient.searchStories method) and serper_google_search (which implicitly comes from the SerperClient.search method).

All of the SDK adapters like createDexterFunctions accept very flexible AIFunctionLike objects, which include:

  • AIFunctionSet - Sets of AI functions (like perigon.functions.pick('search_news_stories') or perigon.functions or serper.functions)
  • AIFunctionsProvider - Client classes which expose an AIFunctionSet via the .functions property (like perigon or serper)
  • AIFunction - Individual functions (like perigon.functions.get('search_news_stories') or serper.functions.get('serper_google_search') or AI functions created directly via the createAIFunction utility function)

You can pass as many of these AIFunctionLike objects as you'd like and you can manipulate them as AIFunctionSet sets via .pick, .omit, .get, .map, etc.

Docs

Full docs are available at agentic.so.

Contributors

License

MIT © Travis Fischer

To stay up to date or learn more, follow @transitive_bs on Twitter.