forked from run-llama/LlamaIndexTS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'mfortman11/astra' of github.com:run-llama/LlamaIndexTS …
…into astra
- Loading branch information
Showing
121 changed files
with
4,443 additions
and
618 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"llamaindex": patch | ||
--- | ||
|
||
fix: update `VectorIndexRetriever` constructor parameters' type. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# docs | ||
|
||
## 0.0.2 | ||
|
||
### Patch Changes | ||
|
||
- 0f64084: docs: update API references | ||
|
||
## 0.0.1 | ||
|
||
### Patch Changes | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Agents | ||
|
||
A built-in agent that can take decisions and reasoning based on the tools provided to it. | ||
|
||
## OpenAI Agent | ||
|
||
```ts | ||
import { FunctionTool, OpenAIAgent } from "llamaindex"; | ||
|
||
// Define a function to sum two numbers | ||
function sumNumbers({ a, b }: { a: number; b: number }): number { | ||
return a + b; | ||
} | ||
|
||
// Define a function to divide two numbers | ||
function divideNumbers({ a, b }: { a: number; b: number }): number { | ||
return a / b; | ||
} | ||
|
||
// Define the parameters of the sum function as a JSON schema | ||
const sumJSON = { | ||
type: "object", | ||
properties: { | ||
a: { | ||
type: "number", | ||
description: "The first number", | ||
}, | ||
b: { | ||
type: "number", | ||
description: "The second number", | ||
}, | ||
}, | ||
required: ["a", "b"], | ||
}; | ||
|
||
// Define the parameters of the divide function as a JSON schema | ||
const divideJSON = { | ||
type: "object", | ||
properties: { | ||
a: { | ||
type: "number", | ||
description: "The dividend to divide", | ||
}, | ||
b: { | ||
type: "number", | ||
description: "The divisor to divide by", | ||
}, | ||
}, | ||
required: ["a", "b"], | ||
}; | ||
|
||
async function main() { | ||
// Create a function tool from the sum function | ||
const sumFunctionTool = new FunctionTool(sumNumbers, { | ||
name: "sumNumbers", | ||
description: "Use this function to sum two numbers", | ||
parameters: sumJSON, | ||
}); | ||
|
||
// Create a function tool from the divide function | ||
const divideFunctionTool = new FunctionTool(divideNumbers, { | ||
name: "divideNumbers", | ||
description: "Use this function to divide two numbers" | ||
parameters: divideJSON, | ||
}); | ||
|
||
// Create an OpenAIAgent with the function tools | ||
const agent = new OpenAIAgent({ | ||
tools: [sumFunctionTool, divideFunctionTool], | ||
verbose: true, | ||
}); | ||
|
||
// Chat with the agent | ||
const response = await agent.chat({ | ||
message: "How much is 5 + 5? then divide by 2", | ||
}); | ||
|
||
// Print the response | ||
console.log(String(response)); | ||
} | ||
|
||
main().then(() => { | ||
console.log("Done"); | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
label: "Agents" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Agents | ||
|
||
An “agent” is an automated reasoning and decision engine. It takes in a user input/query and can make internal decisions for executing that query in order to return the correct result. The key agent components can include, but are not limited to: | ||
|
||
- Breaking down a complex question into smaller ones | ||
- Choosing an external Tool to use + coming up with parameters for calling the Tool | ||
- Planning out a set of tasks | ||
- Storing previously completed tasks in a memory module | ||
|
||
## Getting Started | ||
|
||
LlamaIndex.TS comes with a few built-in agents, but you can also create your own. The built-in agents include: | ||
|
||
- [OpenAI Agent](./openai.mdx) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
# OpenAI Agent | ||
|
||
OpenAI API that supports function calling, it’s never been easier to build your own agent! | ||
|
||
In this notebook tutorial, we showcase how to write your own OpenAI agent | ||
|
||
## Setup | ||
|
||
First, you need to install the `llamaindex` package. You can do this by running the following command in your terminal: | ||
|
||
```bash | ||
pnpm i llamaindex | ||
``` | ||
|
||
Then we can define a function to sum two numbers and another function to divide two numbers. | ||
|
||
```ts | ||
function sumNumbers({ a, b }: { a: number; b: number }): number { | ||
return a + b; | ||
} | ||
|
||
// Define a function to divide two numbers | ||
function divideNumbers({ a, b }: { a: number; b: number }): number { | ||
return a / b; | ||
} | ||
``` | ||
|
||
## Create a function tool | ||
|
||
Now we can create a function tool from the sum function and another function tool from the divide function. | ||
|
||
For the parameters of the sum function, we can define a JSON schema. | ||
|
||
### JSON Schema | ||
|
||
```ts | ||
const sumJSON = { | ||
type: "object", | ||
properties: { | ||
a: { | ||
type: "number", | ||
description: "The first number", | ||
}, | ||
b: { | ||
type: "number", | ||
description: "The second number", | ||
}, | ||
}, | ||
required: ["a", "b"], | ||
}; | ||
|
||
const divideJSON = { | ||
type: "object", | ||
properties: { | ||
a: { | ||
type: "number", | ||
description: "The dividend a to divide", | ||
}, | ||
b: { | ||
type: "number", | ||
description: "The divisor b to divide by", | ||
}, | ||
}, | ||
required: ["a", "b"], | ||
}; | ||
|
||
const sumFunctionTool = new FunctionTool(sumNumbers, { | ||
name: "sumNumbers", | ||
description: "Use this function to sum two numbers", | ||
parameters: sumJSON, | ||
}); | ||
|
||
const divideFunctionTool = new FunctionTool(divideNumbers, { | ||
name: "divideNumbers", | ||
description: "Use this function to divide two numbers", | ||
parameters: divideJSON, | ||
}); | ||
``` | ||
|
||
## Create an OpenAIAgent | ||
|
||
Now we can create an OpenAIAgent with the function tools. | ||
|
||
```ts | ||
const worker = new OpenAIAgent({ | ||
tools: [sumFunctionTool, divideFunctionTool], | ||
verbose: true, | ||
}); | ||
``` | ||
|
||
## Chat with the agent | ||
|
||
Now we can chat with the agent. | ||
|
||
```ts | ||
const response = await worker.chat({ | ||
message: "How much is 5 + 5? then divide by 2", | ||
}); | ||
|
||
console.log(String(response)); | ||
``` | ||
|
||
## Full code | ||
|
||
```ts | ||
import { FunctionTool, OpenAIAgent } from "llamaindex"; | ||
|
||
// Define a function to sum two numbers | ||
function sumNumbers({ a, b }: { a: number; b: number }): number { | ||
return a + b; | ||
} | ||
|
||
// Define a function to divide two numbers | ||
function divideNumbers({ a, b }: { a: number; b: number }): number { | ||
return a / b; | ||
} | ||
|
||
// Define the parameters of the sum function as a JSON schema | ||
const sumJSON = { | ||
type: "object", | ||
properties: { | ||
a: { | ||
type: "number", | ||
description: "The first number", | ||
}, | ||
b: { | ||
type: "number", | ||
description: "The second number", | ||
}, | ||
}, | ||
required: ["a", "b"], | ||
}; | ||
|
||
// Define the parameters of the divide function as a JSON schema | ||
const divideJSON = { | ||
type: "object", | ||
properties: { | ||
a: { | ||
type: "number", | ||
description: "The argument a to divide", | ||
}, | ||
b: { | ||
type: "number", | ||
description: "The argument b to divide", | ||
}, | ||
}, | ||
required: ["a", "b"], | ||
}; | ||
|
||
async function main() { | ||
// Create a function tool from the sum function | ||
const sumFunctionTool = new FunctionTool(sumNumbers, { | ||
name: "sumNumbers", | ||
description: "Use this function to sum two numbers", | ||
parameters: sumJSON, | ||
}); | ||
|
||
// Create a function tool from the divide function | ||
const divideFunctionTool = new FunctionTool(divideNumbers, { | ||
name: "divideNumbers", | ||
description: "Use this function to divide two numbers", | ||
parameters: divideJSON, | ||
}); | ||
|
||
// Create an OpenAIAgent with the function tools | ||
const agent = new OpenAIAgent({ | ||
tools: [sumFunctionTool, divideFunctionTool], | ||
verbose: true, | ||
}); | ||
|
||
// Chat with the agent | ||
const response = await agent.chat({ | ||
message: "How much is 5 + 5? then divide by 2", | ||
}); | ||
|
||
// Print the response | ||
console.log(String(response)); | ||
} | ||
|
||
main().then(() => { | ||
console.log("Done"); | ||
}); | ||
``` |
Oops, something went wrong.