feat: add llamaindex sdk adaptor

pull/643/head^2
Travis Fischer 2024-06-04 19:58:50 -05:00
rodzic 7d11f7632a
commit 24857b1b34
7 zmienionych plików z 3126 dodań i 59 usunięć

Wyświetl plik

@ -0,0 +1,26 @@
#!/usr/bin/env node
import 'dotenv/config'
import { OpenAI, OpenAIAgent } from 'llamaindex'
import { WeatherClient } from '../../src/index.js'
import { createLlamaIndexTools } from '../../src/sdks/llamaindex.js'
async function main() {
const weather = new WeatherClient()
const tools = createLlamaIndexTools(weather)
const agent = new OpenAIAgent({
llm: new OpenAI({ model: 'gpt-4o', temperature: 0 }),
systemPrompt: 'You are a helpful assistant. Be as concise as possible.',
tools
})
const response = await agent.chat({
message: 'What is the weather in San Francisco?'
})
console.log(response.response.message.content)
}
await main()

Wyświetl plik

@ -35,6 +35,7 @@
"dotenv": "^16.4.5",
"genkitx-openai": "^0.9.0",
"langchain": "^0.2.4",
"llamaindex": "^0.3.15",
"openai": "^4.47.3",
"zod": "^3.23.3"
}

Wyświetl plik

@ -94,6 +94,7 @@
"expr-eval": "^2.0.2",
"husky": "^9.0.11",
"lint-staged": "^15.2.5",
"llamaindex": "^0.3.15",
"np": "^10.0.5",
"npm-run-all2": "^6.2.0",
"only-allow": "^1.2.1",
@ -111,7 +112,8 @@
"@genkit-ai/ai": "^0.5.2",
"@langchain/core": "^0.2.5",
"ai": "^3.1.22",
"expr-eval": "^2.0.2"
"expr-eval": "^2.0.2",
"llamaindex": "^0.3.15"
},
"peerDependenciesMeta": {
"@dexaai/dexter": {
@ -126,6 +128,9 @@
"expr-eval": {
"optional": true
},
"llamaindex": {
"optional": true
},
"ai": {
"optional": true
}

Plik diff jest za duży Load Diff

Wyświetl plik

@ -141,10 +141,12 @@ The SDK-specific imports are all isolated to keep the main `@agentic/stdlib` as
## AI SDKs
- openai sdk
- vercel ai sdk
- dexa dexter
- firebase genkit
- langchain
- llamaindex
## TODO
@ -168,6 +170,8 @@ The SDK-specific imports are all isolated to keep the main `@agentic/stdlib` as
- tools / chains / flows / runnables
- market maps
- https://github.com/causaly/zod-validation-error
- investigate [autotool](https://github.com/run-llama/LlamaIndexTS/tree/main/packages/autotool)
- investigate [data connectors](https://github.com/mendableai/data-connectors)
## License

Wyświetl plik

@ -0,0 +1,22 @@
import { FunctionTool } from 'llamaindex'
import type { AIFunctionLike } from '../types.js'
import { AIFunctionSet } from '../ai-function-set.js'
/**
* Converts a set of Agentic stdlib AI functions to an array of LlamaIndex-
* compatible tools.
*/
export function createLlamaIndexTools(
...aiFunctionLikeTools: AIFunctionLike[]
) {
const fns = new AIFunctionSet(aiFunctionLikeTools)
return fns.map((fn) =>
FunctionTool.from(fn.impl, {
name: fn.spec.name,
description: fn.spec.description,
parameters: fn.spec.parameters as any
})
)
}

Wyświetl plik

@ -3,6 +3,9 @@ import { z } from 'zod'
import { createAIFunction } from '../create-ai-function.js'
// TODO: consider using https://github.com/josdejong/mathjs
// TODO: ensure `expr` is sanitized to not run arbitrary code
export const CalculatorInputSchema = z.object({
expr: z.string().describe('mathematical expression to evaluate')
})