mirror of
https://github.com/run-llama/LlamaIndexTS.git
synced 2026-07-19 18:43:34 -04:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 37dcf37625 | |||
| a8c0637d11 | |||
| 387a19284d | |||
| a654f580cf | |||
| 68ea7ec6a5 | |||
| 2d11ffbaea | |||
| 1587e48a14 | |||
| bd239aaf2d | |||
| 98eebf7277 |
+46
-13
@@ -14,13 +14,14 @@ There are some important folders in the repository:
|
|||||||
all JS runtime environments.
|
all JS runtime environments.
|
||||||
- `env`: The environment package of LlamaIndex.TS, which contains the environment-specific classes and interfaces. It
|
- `env`: The environment package of LlamaIndex.TS, which contains the environment-specific classes and interfaces. It
|
||||||
includes compatibility layers for Node.js, Deno, Vercel Edge Runtime, Cloudflare Workers...
|
includes compatibility layers for Node.js, Deno, Vercel Edge Runtime, Cloudflare Workers...
|
||||||
|
- `providers/*`: The providers package of LlamaIndex.TS, which contains the providers for LLM and other services.
|
||||||
- `apps/*`: The applications based on LlamaIndex.TS.
|
- `apps/*`: The applications based on LlamaIndex.TS.
|
||||||
- `next`: Our documentation website based on Next.js.
|
- `next`: Our documentation website based on Next.js.
|
||||||
- `examples`: The code examples of LlamaIndex.TS using Node.js.
|
- `examples`: The code examples of LlamaIndex.TS using Node.js.
|
||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
|
|
||||||
Make sure you have Node.js LIS (Long-term Support) installed. You can check your Node.js version by running:
|
Make sure you have Node.js LTS (Long-term Support) installed. You can check your Node.js version by running:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
node -v
|
node -v
|
||||||
@@ -30,7 +31,7 @@ node -v
|
|||||||
### Use pnpm
|
### Use pnpm
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
corepack enable
|
npm install -g pnpm
|
||||||
```
|
```
|
||||||
|
|
||||||
### Install dependencies
|
### Install dependencies
|
||||||
@@ -41,33 +42,65 @@ pnpm install
|
|||||||
|
|
||||||
### Build the packages
|
### Build the packages
|
||||||
|
|
||||||
You'll need Turbo to build the packages. If you don't have it, you can run it with `pnpx`.
|
|
||||||
|
|
||||||
To build all packages, run:
|
To build all packages, run:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
# Build all packages
|
pnpm build
|
||||||
pnpx turbo build --filter "./packages/*"
|
|
||||||
|
|
||||||
# Or if you have turbo installed, you can run:
|
|
||||||
turbo build --filter "./packages/*"
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Run tests
|
||||||
|
|
||||||
|
#### Unit tests
|
||||||
|
|
||||||
|
After build, to run all unit tests, call:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
pnpm test
|
||||||
|
```
|
||||||
|
|
||||||
|
Unit tests are located in the `tests` folder of each package. They are using their own package (e.g. `@llamaindex/core-tests` for `@llamaindex/core`). The tests are importing the package under test and the test package is not published.
|
||||||
|
|
||||||
|
#### E2E tests
|
||||||
|
|
||||||
|
To run all E2E tests, call:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
pnpm e2e
|
||||||
|
```
|
||||||
|
|
||||||
|
All E2E tests are in the `e2e` folder.
|
||||||
|
|
||||||
### Docs
|
### Docs
|
||||||
|
|
||||||
See the [docs](./apps/next/README.md) for more information.
|
See the [docs](./apps/next/README.md) for more information.
|
||||||
|
|
||||||
## Changeset
|
## Adding a new package
|
||||||
|
|
||||||
|
Please follow these steps to add a new package:
|
||||||
|
|
||||||
|
1. Only add new packages to the `packages/providers` folder.
|
||||||
|
2. Use the `package.json` and `tsconfig.json` of an existing packages as template.
|
||||||
|
3. Reference your new package in the root `tsconfig.json` file
|
||||||
|
4. Add your package to the `examples/package.json` file if you add a new example.
|
||||||
|
|
||||||
|
## Before sending a PR
|
||||||
|
|
||||||
|
Before sending a PR, make sure of the following:
|
||||||
|
|
||||||
|
1. Tests are all running and you added meaningful tests for your change.
|
||||||
|
2. If you have a new feature, document it in the `apps/next` docs folder.
|
||||||
|
3. If you have a new feature, add a new example in the `examples` folder.
|
||||||
|
4. You have a descriptive changeset for each PR:
|
||||||
|
|
||||||
|
### Changesets
|
||||||
|
|
||||||
We use [changesets](https://github.com/changesets/changesets) for managing versions and changelogs. To create a new
|
We use [changesets](https://github.com/changesets/changesets) for managing versions and changelogs. To create a new
|
||||||
changeset, run in the root folder:
|
changeset, run in the root folder:
|
||||||
|
|
||||||
```
|
```shell
|
||||||
pnpm changeset
|
pnpm changeset
|
||||||
```
|
```
|
||||||
|
|
||||||
Please send a descriptive changeset for each PR.
|
|
||||||
|
|
||||||
## Publishing (maintainers only)
|
## Publishing (maintainers only)
|
||||||
|
|
||||||
The [Release Github Action](.github/workflows/release.yml) is automatically generating and updating a
|
The [Release Github Action](.github/workflows/release.yml) is automatically generating and updating a
|
||||||
|
|||||||
@@ -1,5 +1,17 @@
|
|||||||
# @llamaindex/doc
|
# @llamaindex/doc
|
||||||
|
|
||||||
|
## 0.1.11
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- a8c0637: feat: simplify to provide base URL to OpenAI
|
||||||
|
- a654f58: Added docs for using perplexity
|
||||||
|
- 98eebf7: Add RequestOptions parameter passing to support Gemini proxy calls.
|
||||||
|
Add a usage example for the RequestOptions parameter.
|
||||||
|
- Updated dependencies [a8c0637]
|
||||||
|
- @llamaindex/openai@0.1.61
|
||||||
|
- llamaindex@0.9.11
|
||||||
|
|
||||||
## 0.1.10
|
## 0.1.10
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
+1
-2
@@ -6,8 +6,7 @@ This is a Next.js application generated with
|
|||||||
Run development server:
|
Run development server:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
turbo run dev
|
pnpm run dev
|
||||||
# turbo will build all required packages before running the dev server
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Learn More
|
## Learn More
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/doc",
|
"name": "@llamaindex/doc",
|
||||||
"version": "0.1.10",
|
"version": "0.1.11",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"postinstall": "fumadocs-mdx",
|
"postinstall": "fumadocs-mdx",
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ export default function HomePage() {
|
|||||||
icon={Footprints}
|
icon={Footprints}
|
||||||
subheading="Progressive"
|
subheading="Progressive"
|
||||||
heading="From the simplest to the most complex"
|
heading="From the simplest to the most complex"
|
||||||
description="LlamaIndex.TS is designed to be simple to get started, but powerful enough to build complex, agentic AI applications."
|
description="LlamaIndex.TS is designed to be simple to get started, but powerful enough to build complex, agentic AI applications using multi-agents."
|
||||||
>
|
>
|
||||||
<Suspense
|
<Suspense
|
||||||
fallback={
|
fallback={
|
||||||
@@ -76,44 +76,48 @@ export default function HomePage() {
|
|||||||
>
|
>
|
||||||
<MagicMove
|
<MagicMove
|
||||||
code={[
|
code={[
|
||||||
`import { OpenAI } from "@llamaindex/openai";
|
`import { openai } from "@llamaindex/openai";
|
||||||
|
|
||||||
const llm = new OpenAI();
|
const llm = openai();
|
||||||
const response = await llm.complete({ prompt: "How are you?" });`,
|
const response = await llm.complete({ prompt: "How are you?" });`,
|
||||||
`import { OpenAI } from "@llamaindex/openai";
|
`import { openai } from "@llamaindex/openai";
|
||||||
|
|
||||||
const llm = new OpenAI();
|
const llm = openai();
|
||||||
const response = await llm.chat({
|
const response = await llm.chat({
|
||||||
messages: [{ content: "Tell me a joke.", role: "user" }],
|
messages: [{ content: "Tell me a joke.", role: "user" }],
|
||||||
});`,
|
});`,
|
||||||
`import { ChatMemoryBuffer } from "llamaindex";
|
`import { agent } from "llamaindex";
|
||||||
import { OpenAI } from "@llamaindex/openai";
|
import { openai } from "@llamaindex/openai";
|
||||||
|
|
||||||
const llm = new OpenAI({ model: 'gpt4o-turbo' });
|
const analyseAgent = agent({
|
||||||
const buffer = new ChatMemoryBuffer({
|
llm: openai({ model: "gpt-4o" }),
|
||||||
tokenLimit: 128_000,
|
tools: [analyseTools],
|
||||||
})
|
|
||||||
buffer.put({ content: "Tell me a joke.", role: "user" })
|
|
||||||
const response = await llm.chat({
|
|
||||||
messages: buffer.getMessages(),
|
|
||||||
stream: true
|
|
||||||
});`,
|
|
||||||
`import { ChatMemoryBuffer } from "llamaindex";
|
|
||||||
import { OpenAIAgent } from "@llamaindex/openai";
|
|
||||||
|
|
||||||
const agent = new OpenAIAgent({
|
|
||||||
llm,
|
|
||||||
tools: [...myTools]
|
|
||||||
systemPrompt,
|
systemPrompt,
|
||||||
});
|
});
|
||||||
const buffer = new ChatMemoryBuffer({
|
const response = await analyseAgent.run(\`Analyse the given data:
|
||||||
tokenLimit: 128_000,
|
\${data}\`);`,
|
||||||
})
|
`import { agent, multiAgent } from "llamaindex";
|
||||||
buffer.put({ content: "Analysis the data based on the given data.", role: "user" })
|
import { openai } from "@llamaindex/openai";
|
||||||
buffer.put({ content: \`\${data}\`, role: "user" })
|
|
||||||
const response = await agent.chat({
|
const analyseAgent = agent({
|
||||||
message: buffer.getMessages(),
|
name: "AnalyseAgent",
|
||||||
});`,
|
llm: openai({ model: "gpt-4o" }),
|
||||||
|
tools: [analyseTools],
|
||||||
|
});
|
||||||
|
const reporterAgent = agent({
|
||||||
|
name: "ReporterAgent",
|
||||||
|
llm: openai({ model: "gpt-4o" }),
|
||||||
|
tools: [reporterTools],
|
||||||
|
canHandoffTo: [analyseAgent],
|
||||||
|
});
|
||||||
|
|
||||||
|
const agents = multiAgent({
|
||||||
|
agents: [analyseAgent, reporterAgent],
|
||||||
|
rootAgent: reporterAgent,
|
||||||
|
});
|
||||||
|
|
||||||
|
const response = await agents.run(\`Analyse the given data:
|
||||||
|
\${data}\`);`,
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
@@ -125,20 +129,20 @@ const response = await agent.chat({
|
|||||||
description="Truly powerful retrieval-augmented generation applications use agentic techniques, and LlamaIndex.TS makes it easy to build them."
|
description="Truly powerful retrieval-augmented generation applications use agentic techniques, and LlamaIndex.TS makes it easy to build them."
|
||||||
>
|
>
|
||||||
<CodeBlock
|
<CodeBlock
|
||||||
code={`import { agent } from "llamaindex";
|
code={`import { agent, SimpleDirectoryReader, VectorStoreIndex } from "llamaindex";
|
||||||
import { OpenAI } from "@llamaindex/openai";
|
import { openai } from "@llamaindex/openai";
|
||||||
|
|
||||||
// using a previously created LlamaIndex index to query information from
|
// load documents from current directoy into an index
|
||||||
const queryTool = index.queryTool();
|
const reader = new SimpleDirectoryReader();
|
||||||
|
const documents = await reader.loadData(currentDir);
|
||||||
|
const index = await VectorStoreIndex.fromDocuments(documents);
|
||||||
|
|
||||||
const agent = agent({
|
const myAgent = agent({
|
||||||
llm: new OpenAI({
|
llm: openai({ model: "gpt-4o" }),
|
||||||
model: "gpt-4o",
|
tools: [index.queryTool()],
|
||||||
}),
|
|
||||||
tools: [queryTool],
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await agent.run('...');`}
|
await myAgent.run('...');`}
|
||||||
lang="ts"
|
lang="ts"
|
||||||
/>
|
/>
|
||||||
</Feature>
|
</Feature>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import CodeSource from "!raw-loader!../../../../../../../examples/mistral";
|
|||||||
|
|
||||||
By default LlamaIndex.TS uses OpenAI's LLMs and embedding models, but we support [lots of other LLMs](../modules/llms) including models from Mistral (Mistral, Mixtral), Anthropic (Claude) and Google (Gemini).
|
By default LlamaIndex.TS uses OpenAI's LLMs and embedding models, but we support [lots of other LLMs](../modules/llms) including models from Mistral (Mistral, Mixtral), Anthropic (Claude) and Google (Gemini).
|
||||||
|
|
||||||
If you don't want to use an API at all you can [run a local model](../../examples/local_llm).
|
If you don't want to use an API at all you can [run a local model](./local_llm).
|
||||||
|
|
||||||
This example runs you through the process of setting up a Mistral model:
|
This example runs you through the process of setting up a Mistral model:
|
||||||
|
|
||||||
|
|||||||
@@ -106,21 +106,38 @@ Some modules uses `Web Stream` API like `ReadableStream` and `WritableStream`, y
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
```ts twoslash
|
```typescript
|
||||||
import { OpenAIAgent } from '@llamaindex/openai'
|
import { agent, tool } from 'llamaindex'
|
||||||
|
import { openai } from "@llamaindex/openai";
|
||||||
|
|
||||||
const agent = new OpenAIAgent({
|
Settings.llm = openai({
|
||||||
tools: []
|
model: "gpt-4o-mini",
|
||||||
})
|
});
|
||||||
|
|
||||||
const response = await agent.chat({
|
const addTool = tool({
|
||||||
message: 'Hello, how are you?',
|
name: "add",
|
||||||
stream: true
|
description: "Adds two numbers",
|
||||||
})
|
parameters: z.object({x: z.number(), y: z.number()}),
|
||||||
for await (const _ of response) {
|
execute: ({ x, y }) => x + y,
|
||||||
//^?
|
});
|
||||||
// ...
|
|
||||||
|
const myAgent = agent({
|
||||||
|
tools: [addTool],
|
||||||
|
});
|
||||||
|
|
||||||
|
// Chat with the agent
|
||||||
|
const context = myAgent.run("Hello, how are you?");
|
||||||
|
|
||||||
|
for await (const event of context) {
|
||||||
|
if (event instanceof AgentStream) {
|
||||||
|
for (const chunk of event.data.delta) {
|
||||||
|
process.stdout.write(chunk); // stream response
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log(event); // other events
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Run TypeScript Script in Node.js
|
## Run TypeScript Script in Node.js
|
||||||
|
|||||||
@@ -25,15 +25,21 @@ npx tsx example.ts
|
|||||||
First we'll need to pull in our dependencies. These are:
|
First we'll need to pull in our dependencies. These are:
|
||||||
|
|
||||||
- The OpenAI class to use the OpenAI LLM
|
- The OpenAI class to use the OpenAI LLM
|
||||||
- FunctionTool to provide tools to our agent
|
- tool to provide tools to our agent
|
||||||
- OpenAIAgent to create the agent itself
|
- agent to create the single agent
|
||||||
- Settings to define some global settings for the library
|
- Settings to define some global settings for the library
|
||||||
- Dotenv to load our API key from the .env file
|
- Dotenv to load our API key from the .env file
|
||||||
|
- Zod to define the schema for our tool
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
import { FunctionTool, Settings } from "llamaindex";
|
|
||||||
import { OpenAI, OpenAIAgent } from "@llamaindex/openai";
|
|
||||||
import "dotenv/config";
|
import "dotenv/config";
|
||||||
|
import {
|
||||||
|
agent,
|
||||||
|
AgentStream,
|
||||||
|
tool,
|
||||||
|
openai,
|
||||||
|
Settings,
|
||||||
|
} from "llamaindex";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -42,25 +48,12 @@ import { z } from "zod";
|
|||||||
We need to tell our OpenAI class where its API key is, and which of OpenAI's models to use. We'll be using `gpt-4o`, which is capable while still being pretty cheap. This is a global setting, so anywhere an LLM is needed will use the same model.
|
We need to tell our OpenAI class where its API key is, and which of OpenAI's models to use. We'll be using `gpt-4o`, which is capable while still being pretty cheap. This is a global setting, so anywhere an LLM is needed will use the same model.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
Settings.llm = new OpenAI({
|
Settings.llm = openai({
|
||||||
apiKey: process.env.OPENAI_API_KEY,
|
apiKey: process.env.OPENAI_API_KEY,
|
||||||
model: "gpt-4o",
|
model: "gpt-4o",
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### Turn on logging
|
|
||||||
|
|
||||||
We want to see what our agent is up to, so we're going to hook into some events that the library generates and print them out. There are several events possible, but we'll specifically tune in to `llm-tool-call` (when a tool is called) and `llm-tool-result` (when it responds).
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
Settings.callbackManager.on("llm-tool-call", (event) => {
|
|
||||||
console.log(event.detail);
|
|
||||||
});
|
|
||||||
Settings.callbackManager.on("llm-tool-result", (event) => {
|
|
||||||
console.log(event.detail);
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
### Create a function
|
### Create a function
|
||||||
|
|
||||||
We're going to create a very simple function that adds two numbers together. This will be the tool we ask our agent to use.
|
We're going to create a very simple function that adds two numbers together. This will be the tool we ask our agent to use.
|
||||||
@@ -75,7 +68,7 @@ Note that we're passing in an object with two named parameters, `a` and `b`. Thi
|
|||||||
|
|
||||||
### Turn the function into a tool for the agent
|
### Turn the function into a tool for the agent
|
||||||
|
|
||||||
This is the most complicated part of creating an agent. We need to define a `FunctionTool`. We have to pass in:
|
This is the most complicated part of creating an agent. We need to define a `tool`. We have to pass in:
|
||||||
|
|
||||||
- The function itself (`sumNumbers`)
|
- The function itself (`sumNumbers`)
|
||||||
- A name for the function, which the LLM will use to call it
|
- A name for the function, which the LLM will use to call it
|
||||||
@@ -84,7 +77,7 @@ This is the most complicated part of creating an agent. We need to define a `Fun
|
|||||||
- You can see [more examples of function schemas](https://cookbook.openai.com/examples/how_to_call_functions_with_chat_models).
|
- You can see [more examples of function schemas](https://cookbook.openai.com/examples/how_to_call_functions_with_chat_models).
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const tool = FunctionTool.from(sumNumbers, {
|
const addTool = tool({
|
||||||
name: "sumNumbers",
|
name: "sumNumbers",
|
||||||
description: "Use this function to sum two numbers",
|
description: "Use this function to sum two numbers",
|
||||||
parameters: z.object({
|
parameters: z.object({
|
||||||
@@ -95,13 +88,14 @@ const tool = FunctionTool.from(sumNumbers, {
|
|||||||
description: "Second number to sum",
|
description: "Second number to sum",
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
|
execute: sumNumbers,
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
We then wrap up the tools into an array. We could provide lots of tools this way, but for this example we're just using the one.
|
We then wrap up the tools into an array. We could provide lots of tools this way, but for this example we're just using the one.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const tools = [tool];
|
const tools = [addTool];
|
||||||
```
|
```
|
||||||
|
|
||||||
### Create the agent
|
### Create the agent
|
||||||
@@ -109,7 +103,7 @@ const tools = [tool];
|
|||||||
With your LLM already set up and your tools defined, creating an agent is simple:
|
With your LLM already set up and your tools defined, creating an agent is simple:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const agent = new OpenAIAgent({ tools });
|
const myAgent = agent({ tools });
|
||||||
```
|
```
|
||||||
|
|
||||||
### Ask the agent a question
|
### Ask the agent a question
|
||||||
@@ -117,61 +111,109 @@ const agent = new OpenAIAgent({ tools });
|
|||||||
We can use the `chat` interface to ask our agent a question, and it will use the tools we've defined to find an answer.
|
We can use the `chat` interface to ask our agent a question, and it will use the tools we've defined to find an answer.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
let response = await agent.chat({
|
const context = myAgent.run("Sum 101 and 303");
|
||||||
message: "Add 101 and 303",
|
const result = await context;
|
||||||
});
|
console.log(result.data);
|
||||||
|
```
|
||||||
|
You will see the following output:
|
||||||
|
|
||||||
console.log(response);
|
**_Output_**
|
||||||
|
|
||||||
|
```
|
||||||
|
{ result: 'The sum of 101 and 303 is 404.' }
|
||||||
|
```
|
||||||
|
|
||||||
|
To stream the response, you can use the `AgentStream` event which provides chunks of the response as they become available. This allows you to display the response incrementally rather than waiting for the full response:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const context = myAgent.run("Add 101 and 303");
|
||||||
|
for await (const event of context) {
|
||||||
|
if (event instanceof AgentStream) {
|
||||||
|
process.stdout.write(event.data.delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**_Streaming Output_**
|
||||||
|
|
||||||
|
```
|
||||||
|
The sum of 101 and 303 is 404.
|
||||||
|
```
|
||||||
|
|
||||||
|
### Logging workflow events
|
||||||
|
|
||||||
|
To log the workflow events, you can check the event type and log the event data.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const context = myAgent.run("Sum 202 and 404");
|
||||||
|
for await (const event of context) {
|
||||||
|
if (event instanceof AgentStream) {
|
||||||
|
// Stream the response
|
||||||
|
for (const chunk of event.data.delta) {
|
||||||
|
process.stdout.write(chunk);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Log other events
|
||||||
|
console.log("\nWorkflow event:", JSON.stringify(event, null, 2));
|
||||||
|
}
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Let's see what running this looks like using `npx tsx agent.ts`
|
Let's see what running this looks like using `npx tsx agent.ts`
|
||||||
|
|
||||||
**_Output_**
|
**_Output_**
|
||||||
|
|
||||||
```javascript
|
```
|
||||||
{
|
Workflow event: {
|
||||||
toolCall: {
|
"data": {
|
||||||
id: 'call_ze6A8C3mOUBG4zmXO8Z4CPB5',
|
"userInput": "Sum 202 and 404"
|
||||||
name: 'sumNumbers',
|
|
||||||
input: { a: 101, b: 303 }
|
|
||||||
},
|
},
|
||||||
toolResult: {
|
"displayName": "StartEvent"
|
||||||
tool: FunctionTool { _fn: [Function: sumNumbers], _metadata: [Object] },
|
|
||||||
input: { a: 101, b: 303 },
|
|
||||||
output: '404',
|
|
||||||
isError: false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Workflow event: {
|
||||||
|
"data": {
|
||||||
|
"input": [
|
||||||
|
{
|
||||||
|
"role": "user",
|
||||||
|
"content": "Sum 202 and 404"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"currentAgentName": "Agent"
|
||||||
|
},
|
||||||
|
"displayName": "AgentInput"
|
||||||
|
}
|
||||||
|
|
||||||
|
Workflow event: {
|
||||||
|
"data": {
|
||||||
|
"input": [
|
||||||
|
{
|
||||||
|
"role": "system",
|
||||||
|
"content": "You are a helpful assistant. Use the provided tools to answer questions."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "user",
|
||||||
|
"content": "Sum 202 and 404"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"currentAgentName": "Agent"
|
||||||
|
},
|
||||||
|
"displayName": "AgentSetup"
|
||||||
|
}
|
||||||
|
|
||||||
|
....
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```javascript
|
We're seeing several workflow events being logged:
|
||||||
{
|
|
||||||
response: {
|
|
||||||
raw: {
|
|
||||||
id: 'chatcmpl-9KwauZku3QOvH78MNvxJs81mDvQYK',
|
|
||||||
object: 'chat.completion',
|
|
||||||
created: 1714778824,
|
|
||||||
model: 'gpt-4-turbo-2024-04-09',
|
|
||||||
choices: [Array],
|
|
||||||
usage: [Object],
|
|
||||||
system_fingerprint: 'fp_ea6eb70039'
|
|
||||||
},
|
|
||||||
message: {
|
|
||||||
content: 'The sum of 101 and 303 is 404.',
|
|
||||||
role: 'assistant',
|
|
||||||
options: {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
sources: [Getter]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
We're seeing two pieces of output here. The first is our callback firing when the tool is called. You can see in `toolResult` that the LLM has correctly passed `101` and `303` to our `sumNumbers` function, which adds them up and returns `404`.
|
1. `AgentToolCall` - Shows the agent preparing to call our tool with the numbers 202 and 404
|
||||||
|
2. `AgentToolCallResult` - Shows the result of calling the tool, which returned "606"
|
||||||
|
3. `AgentInput` - Shows the original user input
|
||||||
|
4. `AgentOutput` - Shows the agent's response
|
||||||
|
|
||||||
The second piece of output is the response from the LLM itself, where the `message.content` key is giving us the answer.
|
Great! We've built an agent that can understand requests and use tools to fulfill them. Next you can:
|
||||||
|
|
||||||
Great! We've built an agent with tool use! Next you can:
|
- [See the full code](https://github.com/run-llama/LlamaIndexTS/blob/main/examples/agentworkflow/blog-writer.ts)
|
||||||
|
|
||||||
- [See the full code](https://github.com/run-llama/ts-agents/blob/main/1_agent/agent.ts)
|
|
||||||
- [Switch to a local LLM](3_local_model)
|
- [Switch to a local LLM](3_local_model)
|
||||||
- Move on to [add Retrieval-Augmented Generation to your agent](4_agentic_rag)
|
- Move on to [add Retrieval-Augmented Generation to your agent](4_agentic_rag)
|
||||||
|
|||||||
@@ -23,70 +23,27 @@ The first time you run it will also automatically download and install the model
|
|||||||
There are two changes you need to make to the code we already wrote in `1_agent` to get Mixtral 8x7b to work. First, you need to switch to that model. Replace the call to `Settings.llm` with this:
|
There are two changes you need to make to the code we already wrote in `1_agent` to get Mixtral 8x7b to work. First, you need to switch to that model. Replace the call to `Settings.llm` with this:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
Settings.llm = new Ollama({
|
Settings.llm = ollama({
|
||||||
model: "mixtral:8x7b",
|
model: "mixtral:8x7b",
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### Swap to a ReActAgent
|
### Run local agent
|
||||||
|
|
||||||
In our original code we used a specific OpenAIAgent, so we'll need to switch to a more generic agent pattern, the ReAct pattern. This is simple: change the `const agent` line in your code to read
|
You can also create local agent by importing `agent` from `llamaindex`.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const agent = new ReActAgent({ tools });
|
import { agent } from "llamaindex";
|
||||||
|
|
||||||
|
const workflow = agent({
|
||||||
|
tools: [getWeatherTool],
|
||||||
|
});
|
||||||
|
|
||||||
|
const workflowContext = workflow.run(
|
||||||
|
"What's the weather like in San Francisco?",
|
||||||
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
(You will also need to bring in `Ollama` and `ReActAgent` in your imports)
|
|
||||||
|
|
||||||
### Run your totally local agent
|
|
||||||
|
|
||||||
Because your embeddings were already local, your agent can now run entirely locally without making any API calls.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
node agent.mjs
|
|
||||||
```
|
|
||||||
|
|
||||||
Note that your model will probably run a lot slower than OpenAI, so be prepared to wait a while!
|
|
||||||
|
|
||||||
**_Output_**
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
{
|
|
||||||
response: {
|
|
||||||
message: {
|
|
||||||
role: 'assistant',
|
|
||||||
content: ' Thought: I need to use a tool to add the numbers 101 and 303.\n' +
|
|
||||||
'Action: sumNumbers\n' +
|
|
||||||
'Action Input: {"a": 101, "b": 303}\n' +
|
|
||||||
'\n' +
|
|
||||||
'Observation: 404\n' +
|
|
||||||
'\n' +
|
|
||||||
'Thought: I can answer without using any more tools.\n' +
|
|
||||||
'Answer: The sum of 101 and 303 is 404.'
|
|
||||||
},
|
|
||||||
raw: {
|
|
||||||
model: 'mixtral:8x7b',
|
|
||||||
created_at: '2024-05-09T00:24:30.339473Z',
|
|
||||||
message: [Object],
|
|
||||||
done: true,
|
|
||||||
total_duration: 64678371209,
|
|
||||||
load_duration: 57394551334,
|
|
||||||
prompt_eval_count: 475,
|
|
||||||
prompt_eval_duration: 4163981000,
|
|
||||||
eval_count: 94,
|
|
||||||
eval_duration: 3116692000
|
|
||||||
}
|
|
||||||
},
|
|
||||||
sources: [Getter]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Tada! You can see all of this in the folder `1a_mixtral`.
|
|
||||||
|
|
||||||
### Extending to other examples
|
|
||||||
|
|
||||||
You can use a ReActAgent instead of an OpenAIAgent in any of the further examples below, but keep in mind that GPT-4 is a lot more capable than Mixtral 8x7b, so you may see more errors or failures in reasoning if you are using an entirely local setup.
|
|
||||||
|
|
||||||
### Next steps
|
### Next steps
|
||||||
|
|
||||||
Now you've got a local agent, you can [add Retrieval-Augmented Generation to your agent](4_agentic_rag).
|
Now you've got a local agent, you can [add Retrieval-Augmented Generation to your agent](4_agentic_rag).
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ import { Tab, Tabs } from "fumadocs-ui/components/tabs";
|
|||||||
We'll be bringing in `SimpleDirectoryReader`, `HuggingFaceEmbedding`, `VectorStoreIndex`, and `QueryEngineTool`, `OpenAIContextAwareAgent` from LlamaIndex.TS, as well as the dependencies we previously used.
|
We'll be bringing in `SimpleDirectoryReader`, `HuggingFaceEmbedding`, `VectorStoreIndex`, and `QueryEngineTool`, `OpenAIContextAwareAgent` from LlamaIndex.TS, as well as the dependencies we previously used.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
import { FunctionTool, QueryEngineTool, Settings, VectorStoreIndex } from "llamaindex";
|
import { QueryEngineTool, Settings, VectorStoreIndex } from "llamaindex";
|
||||||
import { OpenAI, OpenAIAgent } from "@llamaindex/openai";
|
import { OpenAI, OpenAIAgent } from "@llamaindex/openai";
|
||||||
import { HuggingFaceEmbedding } from "@llamaindex/huggingface";
|
import { HuggingFaceEmbedding } from "@llamaindex/huggingface";
|
||||||
import { SimpleDirectoryReader } from "@llamaindex/readers/directory";
|
import { SimpleDirectoryReader } from "@llamaindex/readers/directory";
|
||||||
@@ -115,10 +115,8 @@ The total budget for the City and County of San Francisco for the fiscal year 20
|
|||||||
If you prefer more flexibility and don't mind additional complexity, you can create a `QueryEngineTool`. This approach allows you to define the query logic, providing a more tailored way to interact with the data, but note that it introduces a delay due to the extra tool call.
|
If you prefer more flexibility and don't mind additional complexity, you can create a `QueryEngineTool`. This approach allows you to define the query logic, providing a more tailored way to interact with the data, but note that it introduces a delay due to the extra tool call.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const queryEngine = await index.asQueryEngine({ retriever });
|
|
||||||
const tools = [
|
const tools = [
|
||||||
new QueryEngineTool({
|
index.queryTool({
|
||||||
queryEngine: queryEngine,
|
|
||||||
metadata: {
|
metadata: {
|
||||||
name: "san_francisco_budget_tool",
|
name: "san_francisco_budget_tool",
|
||||||
description: `This tool can answer detailed questions about the individual components of the budget of San Francisco in 2023-2024.`,
|
description: `This tool can answer detailed questions about the individual components of the budget of San Francisco in 2023-2024.`,
|
||||||
@@ -127,11 +125,9 @@ const tools = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
// Create an agent using the tools array
|
// Create an agent using the tools array
|
||||||
const agent = new OpenAIAgent({ tools });
|
const myAgent = agent({ tools });
|
||||||
|
|
||||||
let toolResponse = await agent.chat({
|
let toolResponse = await myAgent.run("What's the budget of San Francisco in 2023-2024?");
|
||||||
message: "What's the budget of San Francisco in 2023-2024?",
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(toolResponse);
|
console.log(toolResponse);
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -7,14 +7,13 @@ In [our third iteration of the agent](https://github.com/run-llama/ts-agents/blo
|
|||||||
```javascript
|
```javascript
|
||||||
// define the query engine as a tool
|
// define the query engine as a tool
|
||||||
const tools = [
|
const tools = [
|
||||||
new QueryEngineTool({
|
index.queryTool({
|
||||||
queryEngine: queryEngine,
|
|
||||||
metadata: {
|
metadata: {
|
||||||
name: "san_francisco_budget_tool",
|
name: "san_francisco_budget_tool",
|
||||||
description: `This tool can answer detailed questions about the individual components of the budget of San Francisco in 2023-2024.`,
|
description: `This tool can answer detailed questions about the individual components of the budget of San Francisco in 2023-2024.`,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
FunctionTool.from(sumNumbers, {
|
tool({
|
||||||
name: "sumNumbers",
|
name: "sumNumbers",
|
||||||
description: "Use this function to sum two numbers",
|
description: "Use this function to sum two numbers",
|
||||||
parameters: z.object({
|
parameters: z.object({
|
||||||
@@ -25,14 +24,15 @@ const tools = [
|
|||||||
description: "Second number to sum",
|
description: "Second number to sum",
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
|
execute: ({ a, b }) => `${a + b}`,
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also use JSON Schema to define the tool parameters as an alternative to Zod.
|
You can also use JSON Schema to define the tool parameters as an alternative to Zod.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
FunctionTool.from(sumNumbers, {
|
tool(sumNumbers, {
|
||||||
name: "sumNumbers",
|
name: "sumNumbers",
|
||||||
description: "Use this function to sum two numbers",
|
description: "Use this function to sum two numbers",
|
||||||
parameters: {
|
parameters: {
|
||||||
@@ -56,22 +56,13 @@ FunctionTool.from(sumNumbers, {
|
|||||||
These tool descriptions are identical to the ones we previously defined. Now let's ask it 3 questions in a row:
|
These tool descriptions are identical to the ones we previously defined. Now let's ask it 3 questions in a row:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
let response = await agent.chat({
|
let response = await agent.run("What's the budget of San Francisco for community health in 2023-24?");
|
||||||
message:
|
|
||||||
"What's the budget of San Francisco for community health in 2023-24?",
|
|
||||||
});
|
|
||||||
console.log(response);
|
console.log(response);
|
||||||
|
|
||||||
let response2 = await agent.chat({
|
let response2 = await agent.run("What's the budget of San Francisco for public protection in 2023-24?");
|
||||||
message:
|
|
||||||
"What's the budget of San Francisco for public protection in 2023-24?",
|
|
||||||
});
|
|
||||||
console.log(response2);
|
console.log(response2);
|
||||||
|
|
||||||
let response3 = await agent.chat({
|
let response3 = await agent.run("What's the combined budget of San Francisco for community health and public protection in 2023-24?");
|
||||||
message:
|
|
||||||
"What's the combined budget of San Francisco for community health and public protection in 2023-24?",
|
|
||||||
});
|
|
||||||
console.log(response3);
|
console.log(response3);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,6 @@
|
|||||||
title: Agent Workflow
|
title: Agent Workflow
|
||||||
---
|
---
|
||||||
|
|
||||||
import { DynamicCodeBlock } from 'fumadocs-ui/components/dynamic-codeblock';
|
|
||||||
import CodeSource from "!raw-loader!../../../../../../../examples/agentworkflow/blog-writer.ts";
|
|
||||||
import { Tab, Tabs } from "fumadocs-ui/components/tabs";
|
|
||||||
|
|
||||||
Agent Workflows are a powerful system that enables you to create and orchestrate one or multiple agents with tools to perform specific tasks. It's built on top of the base `Workflow` system and provides a streamlined interface for agent interactions.
|
Agent Workflows are a powerful system that enables you to create and orchestrate one or multiple agents with tools to perform specific tasks. It's built on top of the base `Workflow` system and provides a streamlined interface for agent interactions.
|
||||||
|
|
||||||
@@ -15,11 +12,11 @@ Agent Workflows are a powerful system that enables you to create and orchestrate
|
|||||||
The simplest use case is creating a single agent with specific tools. Here's an example of creating an assistant that tells jokes:
|
The simplest use case is creating a single agent with specific tools. Here's an example of creating an assistant that tells jokes:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { agent, FunctionTool } from "llamaindex";
|
import { agent, tool } from "llamaindex";
|
||||||
import { OpenAI } from "@llamaindex/openai";
|
import { openai } from "@llamaindex/openai";
|
||||||
|
|
||||||
// Define a joke-telling tool
|
// Define a joke-telling tool
|
||||||
const jokeTool = FunctionTool.from(
|
const jokeTool = tool(
|
||||||
() => "Baby Llama is called cria",
|
() => "Baby Llama is called cria",
|
||||||
{
|
{
|
||||||
name: "joke",
|
name: "joke",
|
||||||
@@ -28,15 +25,13 @@ const jokeTool = FunctionTool.from(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Create an single agent workflow with the tool
|
// Create an single agent workflow with the tool
|
||||||
const workflow = agent({
|
const jokeAgent = agent({
|
||||||
tools: [jokeTool],
|
tools: [jokeTool],
|
||||||
llm: new OpenAI({
|
llm: openai({ model: "gpt-4o-mini" }),
|
||||||
model: "gpt-4o-mini",
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Run the workflow
|
// Run the workflow
|
||||||
const result = await workflow.run("Tell me something funny");
|
const result = await jokeAgent.run("Tell me something funny");
|
||||||
console.log(result); // Baby Llama is called cria
|
console.log(result); // Baby Llama is called cria
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -73,8 +68,8 @@ An Agent Workflow can orchestrate multiple agents, enabling complex interactions
|
|||||||
Here's an example of a multi-agent system that combines joke-telling and weather information:
|
Here's an example of a multi-agent system that combines joke-telling and weather information:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { multiAgent, agent, FunctionTool } from "llamaindex";
|
import { multiAgent, agent, tool } from "llamaindex";
|
||||||
import { OpenAI } from "@llamaindex/openai";
|
import { openai } from "@llamaindex/openai";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
// Create a weather agent
|
// Create a weather agent
|
||||||
@@ -82,18 +77,18 @@ const weatherAgent = agent({
|
|||||||
name: "WeatherAgent",
|
name: "WeatherAgent",
|
||||||
description: "Provides weather information for any city",
|
description: "Provides weather information for any city",
|
||||||
tools: [
|
tools: [
|
||||||
FunctionTool.from(
|
tool(
|
||||||
({ city }: { city: string }) => `The weather in ${city} is sunny`,
|
|
||||||
{
|
{
|
||||||
name: "fetchWeather",
|
name: "fetchWeather",
|
||||||
description: "Get weather information for a city",
|
description: "Get weather information for a city",
|
||||||
parameters: z.object({
|
parameters: z.object({
|
||||||
city: z.string(),
|
city: z.string(),
|
||||||
}),
|
}),
|
||||||
|
execute: ({ city }) => `The weather in ${city} is sunny`,
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
llm: new OpenAI({ model: "gpt-4o-mini" }),
|
llm: openai({ model: "gpt-4o-mini" }),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create a joke-telling agent
|
// Create a joke-telling agent
|
||||||
@@ -101,18 +96,18 @@ const jokeAgent = agent({
|
|||||||
name: "JokeAgent",
|
name: "JokeAgent",
|
||||||
description: "Tells jokes and funny stories",
|
description: "Tells jokes and funny stories",
|
||||||
tools: [jokeTool], // Using the joke tool defined earlier
|
tools: [jokeTool], // Using the joke tool defined earlier
|
||||||
llm: new OpenAI({ model: "gpt-4o-mini" }),
|
llm: openai({ model: "gpt-4o-mini" }),
|
||||||
canHandoffTo: [weatherAgent], // Can hand off to the weather agent
|
canHandoffTo: [weatherAgent], // Can hand off to the weather agent
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create the multi-agent workflow
|
// Create the multi-agent workflow
|
||||||
const workflow = multiAgent({
|
const agents = multiAgent({
|
||||||
agents: [jokeAgent, weatherAgent],
|
agents: [jokeAgent, weatherAgent],
|
||||||
rootAgent: jokeAgent, // Start with the joke agent
|
rootAgent: jokeAgent, // Start with the joke agent
|
||||||
});
|
});
|
||||||
|
|
||||||
// Run the workflow
|
// Run the workflow
|
||||||
const result = await workflow.run(
|
const result = await agents.run(
|
||||||
"Give me a morning greeting with a joke and the weather in San Francisco"
|
"Give me a morning greeting with a joke and the weather in San Francisco"
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -31,6 +31,20 @@ Settings.llm = new Gemini({
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Usage with Proxy
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { Gemini, GEMINI_MODEL } from "@llamaindex/google";
|
||||||
|
import { Settings } from "llamaindex";
|
||||||
|
|
||||||
|
Settings.llm = new Gemini({
|
||||||
|
model: GEMINI_MODEL.GEMINI_PRO,
|
||||||
|
requestOptions: {
|
||||||
|
baseUrl: <YOUR_PROXY_URL> // optional, but useful for custom endpoints
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
### Usage with Vertex AI
|
### Usage with Vertex AI
|
||||||
|
|
||||||
To use Gemini via Vertex AI you can use `GeminiVertexSession`.
|
To use Gemini via Vertex AI you can use `GeminiVertexSession`.
|
||||||
|
|||||||
@@ -34,6 +34,18 @@ You can setup the apiKey on the environment variables, like:
|
|||||||
export OPENAI_API_KEY="<YOUR_API_KEY>"
|
export OPENAI_API_KEY="<YOUR_API_KEY>"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You can optionally set a custom base URL, like:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export OPENAI_BASE_URL="https://api.scaleway.ai/v1"
|
||||||
|
```
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
```ts
|
||||||
|
Settings.llm = new OpenAI({ model: "gpt-3.5-turbo", temperature: 0, apiKey: <YOUR_API_KEY>, baseURL: "https://api.scaleway.ai/v1" });
|
||||||
|
```
|
||||||
|
|
||||||
## Load and index documents
|
## Load and index documents
|
||||||
|
|
||||||
For this example, we will use a single document. In a real-world scenario, you would have multiple documents to index.
|
For this example, we will use a single document. In a real-world scenario, you would have multiple documents to index.
|
||||||
|
|||||||
@@ -0,0 +1,116 @@
|
|||||||
|
---
|
||||||
|
title: Perplexity LLM
|
||||||
|
---
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { Settings } from "llamaindex";
|
||||||
|
import { perplexity } from "@llamaindex/perplexity";
|
||||||
|
Settings.llm = perplexity({
|
||||||
|
apiKey: "<YOUR_API_KEY>",
|
||||||
|
model: "sonar", // or available models
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { perplexity } from "@llamaindex/perplexity";
|
||||||
|
|
||||||
|
const perplexityLlm = perplexity({
|
||||||
|
apiKey: "<YOUR_API_KEY>",
|
||||||
|
model: "sonar", // or avaiable models
|
||||||
|
});
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
const response = await perplexityLlm.chat({
|
||||||
|
messages: [
|
||||||
|
{
|
||||||
|
role: "system",
|
||||||
|
content: "You are an AI assistant",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
role: "user",
|
||||||
|
content: "Tell me about San Francisco",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
stream: false,
|
||||||
|
});
|
||||||
|
console.log(response);
|
||||||
|
|
||||||
|
const stream = await perplexityLlm.chat({
|
||||||
|
messages: [
|
||||||
|
{
|
||||||
|
role: "system",
|
||||||
|
content: "You are a creative AI assistant that tells engaging stories",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
role: "user",
|
||||||
|
content: "Tell me a short story",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
stream: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("\nStreaming response:");
|
||||||
|
for await (const chunk of stream) {
|
||||||
|
process.stdout.write(chunk.delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Full Example
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { perplexity } from "@llamaindex/perplexity";
|
||||||
|
import { Document, Settings, VectorStoreIndex } from "llamaindex";
|
||||||
|
|
||||||
|
// Use the perplexity LLM
|
||||||
|
Settings.llm = perplexity({ model: "sonar", apiKey: "<YOUR_API_KEY>" });
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
const document = new Document({ text: essay, id_: "essay" });
|
||||||
|
|
||||||
|
// Load and index documents
|
||||||
|
const index = await VectorStoreIndex.fromDocuments([document]);
|
||||||
|
|
||||||
|
// get retriever
|
||||||
|
const retriever = index.asRetriever();
|
||||||
|
|
||||||
|
// Create a query engine
|
||||||
|
const queryEngine = index.asQueryEngine({
|
||||||
|
retriever,
|
||||||
|
});
|
||||||
|
|
||||||
|
const query = "What is the meaning of life?";
|
||||||
|
|
||||||
|
// Query
|
||||||
|
const response = await queryEngine.query({
|
||||||
|
query,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Log the response
|
||||||
|
console.log(response.response);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Available Models
|
||||||
|
|
||||||
|
The following models are available:
|
||||||
|
|
||||||
|
- `sonar`: 128k context window
|
||||||
|
- `sonar-pro`: 200k context window
|
||||||
|
- `sonar-deep-research`: 128k context window
|
||||||
|
- `sonar-reasoning`: 128k context window
|
||||||
|
- `sonar-reasoning-pro`: 128k context window
|
||||||
|
- `r1-1776`: 128k context window
|
||||||
|
|
||||||
|
|
||||||
|
# Limitations
|
||||||
|
|
||||||
|
Currently does not support function calling.
|
||||||
|
|
||||||
|
## API Reference
|
||||||
|
|
||||||
|
- [Perplexity](/docs/api/classes/Perplexity)
|
||||||
@@ -29,6 +29,8 @@ Note: calling the `bind` method will return a new `FunctionTool` instance, witho
|
|||||||
|
|
||||||
Example to pass a `userToken` as additional argument:
|
Example to pass a `userToken` as additional argument:
|
||||||
```ts
|
```ts
|
||||||
|
import { agent, tool } from "llamaindex";
|
||||||
|
|
||||||
// first arg is LLM input, second is bound arg
|
// first arg is LLM input, second is bound arg
|
||||||
const queryKnowledgeBase = async ({ question }, { userToken }) => {
|
const queryKnowledgeBase = async ({ question }, { userToken }) => {
|
||||||
const response = await fetch(`https://knowledge-base.com?token=${userToken}&query=${question}`);
|
const response = await fetch(`https://knowledge-base.com?token=${userToken}&query=${question}`);
|
||||||
@@ -36,7 +38,7 @@ const queryKnowledgeBase = async ({ question }, { userToken }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// define tool as usual
|
// define tool as usual
|
||||||
const kbTool = FunctionTool.from(queryKnowledgeBase, {
|
const kbTool = tool(queryKnowledgeBase, {
|
||||||
name: 'queryKnowledgeBase',
|
name: 'queryKnowledgeBase',
|
||||||
description: 'Query knowledge base',
|
description: 'Query knowledge base',
|
||||||
parameters: z.object({
|
parameters: z.object({
|
||||||
@@ -48,7 +50,7 @@ const kbTool = FunctionTool.from(queryKnowledgeBase, {
|
|||||||
|
|
||||||
// create an agent
|
// create an agent
|
||||||
const additionalArg = { userToken: 'abcd1234' };
|
const additionalArg = { userToken: 'abcd1234' };
|
||||||
const kbAgent = new LLMAgent({
|
const workflow = agent({
|
||||||
tools: [kbTool.bind(additionalArg)],
|
tools: [kbTool.bind(additionalArg)],
|
||||||
// llm, systemPrompt etc
|
// llm, systemPrompt etc
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
# @llamaindex/cloudflare-worker-agent-test
|
# @llamaindex/cloudflare-worker-agent-test
|
||||||
|
|
||||||
|
## 0.0.145
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- llamaindex@0.9.11
|
||||||
|
|
||||||
## 0.0.144
|
## 0.0.144
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/cloudflare-worker-agent-test",
|
"name": "@llamaindex/cloudflare-worker-agent-test",
|
||||||
"version": "0.0.144",
|
"version": "0.0.145",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
# @llamaindex/next-agent-test
|
# @llamaindex/next-agent-test
|
||||||
|
|
||||||
|
## 0.1.145
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- llamaindex@0.9.11
|
||||||
|
|
||||||
## 0.1.144
|
## 0.1.144
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/next-agent-test",
|
"name": "@llamaindex/next-agent-test",
|
||||||
"version": "0.1.144",
|
"version": "0.1.145",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
# test-edge-runtime
|
# test-edge-runtime
|
||||||
|
|
||||||
|
## 0.1.144
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- llamaindex@0.9.11
|
||||||
|
|
||||||
## 0.1.143
|
## 0.1.143
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/nextjs-edge-runtime-test",
|
"name": "@llamaindex/nextjs-edge-runtime-test",
|
||||||
"version": "0.1.143",
|
"version": "0.1.144",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
# @llamaindex/next-node-runtime
|
# @llamaindex/next-node-runtime
|
||||||
|
|
||||||
|
## 0.1.11
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- llamaindex@0.9.11
|
||||||
|
- @llamaindex/huggingface@0.0.45
|
||||||
|
|
||||||
## 0.1.10
|
## 0.1.10
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/next-node-runtime-test",
|
"name": "@llamaindex/next-node-runtime-test",
|
||||||
"version": "0.1.10",
|
"version": "0.1.11",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
# vite-import-llamaindex
|
# vite-import-llamaindex
|
||||||
|
|
||||||
|
## 0.0.11
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- llamaindex@0.9.11
|
||||||
|
|
||||||
## 0.0.10
|
## 0.0.10
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "vite-import-llamaindex",
|
"name": "vite-import-llamaindex",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.0.10",
|
"version": "0.0.11",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
# @llamaindex/waku-query-engine-test
|
# @llamaindex/waku-query-engine-test
|
||||||
|
|
||||||
|
## 0.0.145
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- llamaindex@0.9.11
|
||||||
|
|
||||||
## 0.0.144
|
## 0.0.144
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/waku-query-engine-test",
|
"name": "@llamaindex/waku-query-engine-test",
|
||||||
"version": "0.0.144",
|
"version": "0.0.145",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -1,5 +1,29 @@
|
|||||||
# examples
|
# examples
|
||||||
|
|
||||||
|
## 0.2.10
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 1587e48: Added support for Perplexity api
|
||||||
|
- Updated dependencies [387a192]
|
||||||
|
- Updated dependencies [a8c0637]
|
||||||
|
- Updated dependencies [1587e48]
|
||||||
|
- Updated dependencies [98eebf7]
|
||||||
|
- @llamaindex/mistral@0.0.14
|
||||||
|
- @llamaindex/openai@0.1.61
|
||||||
|
- @llamaindex/perplexity@0.0.2
|
||||||
|
- @llamaindex/google@0.1.2
|
||||||
|
- llamaindex@0.9.11
|
||||||
|
- @llamaindex/clip@0.0.45
|
||||||
|
- @llamaindex/deepinfra@0.0.45
|
||||||
|
- @llamaindex/deepseek@0.0.5
|
||||||
|
- @llamaindex/fireworks@0.0.5
|
||||||
|
- @llamaindex/groq@0.0.60
|
||||||
|
- @llamaindex/huggingface@0.0.45
|
||||||
|
- @llamaindex/jinaai@0.0.5
|
||||||
|
- @llamaindex/together@0.0.5
|
||||||
|
- @llamaindex/vllm@0.0.31
|
||||||
|
|
||||||
## 0.2.9
|
## 0.2.9
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,41 +1,31 @@
|
|||||||
import { FunctionTool } from "llamaindex";
|
import { tool } from "llamaindex";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
export const getCurrentIDTool = FunctionTool.from(
|
export const getCurrentIDTool = tool({
|
||||||
() => {
|
name: "get_user_id",
|
||||||
|
description: "Get a random user id",
|
||||||
|
parameters: z.object({}),
|
||||||
|
execute: () => {
|
||||||
console.log("Getting user id...");
|
console.log("Getting user id...");
|
||||||
return crypto.randomUUID();
|
return crypto.randomUUID();
|
||||||
},
|
},
|
||||||
{
|
});
|
||||||
name: "get_user_id",
|
|
||||||
description: "Get a random user id",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
export const getUserInfoTool = FunctionTool.from(
|
export const getUserInfoTool = tool({
|
||||||
({ userId }: { userId: string }) => {
|
name: "get_user_info",
|
||||||
console.log("Getting user info...", userId);
|
description: "Get user info",
|
||||||
return `Name: Alex; Address: 1234 Main St, CA; User ID: ${userId}`;
|
parameters: z.object({
|
||||||
},
|
userId: z.string().describe("The user id"),
|
||||||
{
|
}),
|
||||||
name: "get_user_info",
|
execute: ({ userId }) =>
|
||||||
description: "Get user info",
|
`Name: Alex; Address: 1234 Main St, CA; User ID: ${userId}`,
|
||||||
parameters: z.object({
|
});
|
||||||
userId: z.string().describe("The user id"),
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
export const getWeatherTool = FunctionTool.from(
|
export const getWeatherTool = tool({
|
||||||
({ address }: { address: string }) => {
|
name: "get_weather",
|
||||||
console.log("Getting weather...", address);
|
description: "Get the current weather for a location",
|
||||||
return `${address} is in a sunny location!`;
|
parameters: z.object({
|
||||||
},
|
address: z.string().describe("The address"),
|
||||||
{
|
}),
|
||||||
name: "get_weather",
|
execute: ({ address }) => `${address} is in a sunny location!`,
|
||||||
description: "Get the current weather for a location",
|
});
|
||||||
parameters: z.object({
|
|
||||||
address: z.string().describe("The address"),
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { ollama } from "@llamaindex/ollama";
|
||||||
|
import { agent } from "llamaindex";
|
||||||
|
import { getWeatherTool } from "../agent/utils/tools";
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
const myAgent = agent({
|
||||||
|
tools: [getWeatherTool],
|
||||||
|
verbose: false,
|
||||||
|
llm: ollama({ model: "granite3.2:2b" }),
|
||||||
|
});
|
||||||
|
|
||||||
|
const sfResult = await myAgent.run(
|
||||||
|
"What's the weather like in San Francisco?",
|
||||||
|
);
|
||||||
|
// The weather in San Francisco, CA is currently sunny.
|
||||||
|
console.log(`${JSON.stringify(sfResult, null, 2)}`);
|
||||||
|
|
||||||
|
// Reuse the context from the previous run
|
||||||
|
const caResult = await myAgent.run("Compare it with California?");
|
||||||
|
|
||||||
|
// Both San Francisco and California are currently experiencing sunny weather.
|
||||||
|
console.log(`${JSON.stringify(caResult, null, 2)}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
main().catch(console.error);
|
||||||
+19
-31
@@ -1,43 +1,31 @@
|
|||||||
import { Anthropic, AnthropicAgent } from "@llamaindex/anthropic";
|
import { anthropic } from "@llamaindex/anthropic";
|
||||||
import { FunctionTool, Settings } from "llamaindex";
|
import { agent, tool } from "llamaindex";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { WikipediaTool } from "../wiki";
|
import { WikipediaTool } from "../wiki";
|
||||||
|
|
||||||
Settings.callbackManager.on("llm-tool-call", (event) => {
|
const workflow = agent({
|
||||||
console.log("llm-tool-call", event.detail.toolCall);
|
|
||||||
});
|
|
||||||
|
|
||||||
const anthropic = new Anthropic({
|
|
||||||
apiKey: process.env.ANTHROPIC_API_KEY,
|
|
||||||
model: "claude-3-7-sonnet",
|
|
||||||
});
|
|
||||||
|
|
||||||
const agent = new AnthropicAgent({
|
|
||||||
llm: anthropic,
|
|
||||||
tools: [
|
tools: [
|
||||||
FunctionTool.from(
|
tool({
|
||||||
(query) => {
|
name: "weather",
|
||||||
return `The weather in ${query.location} is sunny`;
|
description: "Get the weather",
|
||||||
},
|
parameters: z.object({
|
||||||
{
|
location: z.string().describe("The location to get the weather for"),
|
||||||
name: "weather",
|
}),
|
||||||
description: "Get the weather",
|
execute: ({ location }) => `The weather in ${location} is sunny`,
|
||||||
parameters: z.object({
|
}),
|
||||||
location: z.string().describe("The location to get the weather for"),
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
new WikipediaTool(),
|
new WikipediaTool(),
|
||||||
],
|
],
|
||||||
|
llm: anthropic({
|
||||||
|
apiKey: process.env.ANTHROPIC_API_KEY,
|
||||||
|
model: "claude-3-7-sonnet",
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const { message } = await agent.chat({
|
const result = await workflow.run(
|
||||||
message:
|
"What is the weather in New York? What's the history of New York from Wikipedia in 3 sentences?",
|
||||||
"What is the weather in New York? What's the history of New York from Wikipedia in 3 sentences?",
|
);
|
||||||
});
|
console.log(result.data);
|
||||||
|
|
||||||
console.log(message.content);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void main();
|
void main();
|
||||||
|
|||||||
+33
-51
@@ -1,65 +1,47 @@
|
|||||||
import { Gemini, GEMINI_MODEL } from "@llamaindex/google";
|
import { gemini, GEMINI_MODEL } from "@llamaindex/google";
|
||||||
import { FunctionTool, LLMAgent, Settings } from "llamaindex";
|
import { agent, tool } from "llamaindex";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
Settings.callbackManager.on("llm-tool-call", (event) => {
|
const sumNumbers = tool({
|
||||||
console.log(event.detail);
|
name: "sumNumbers",
|
||||||
|
description: "Use this function to sum two numbers",
|
||||||
|
parameters: z.object({
|
||||||
|
a: z.number().describe("The first number"),
|
||||||
|
b: z.number().describe("The second number"),
|
||||||
|
}),
|
||||||
|
execute: ({ a, b }) => `${a + b}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
Settings.callbackManager.on("llm-tool-result", (event) => {
|
const divideNumbers = tool({
|
||||||
console.log(event.detail);
|
name: "divideNumbers",
|
||||||
|
description: "Use this function to divide two numbers",
|
||||||
|
parameters: z.object({
|
||||||
|
a: z.number().describe("The dividend a to divide"),
|
||||||
|
b: z.number().describe("The divisor b to divide by"),
|
||||||
|
}),
|
||||||
|
execute: ({ a, b }) => `${a / b}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
const sumNumbers = FunctionTool.from(
|
const subtractNumbers = tool({
|
||||||
({ a, b }: { a: number; b: number }) => `${a + b}`,
|
name: "subtractNumbers",
|
||||||
{
|
description: "Use this function to subtract two numbers",
|
||||||
name: "sumNumbers",
|
parameters: z.object({
|
||||||
description: "Use this function to sum two numbers",
|
a: z.number().describe("The number to subtract from"),
|
||||||
parameters: z.object({
|
b: z.number().describe("The number to subtract"),
|
||||||
a: z.number().describe("The first number"),
|
}),
|
||||||
b: z.number().describe("The second number"),
|
execute: ({ a, b }) => `${a - b}`,
|
||||||
}),
|
});
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
const divideNumbers = FunctionTool.from(
|
|
||||||
({ a, b }: { a: number; b: number }) => `${a / b}`,
|
|
||||||
{
|
|
||||||
name: "divideNumbers",
|
|
||||||
description: "Use this function to divide two numbers",
|
|
||||||
parameters: z.object({
|
|
||||||
a: z.number().describe("The dividend a to divide"),
|
|
||||||
b: z.number().describe("The divisor b to divide by"),
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
const subtractNumbers = FunctionTool.from(
|
|
||||||
({ a, b }: { a: number; b: number }) => `${a - b}`,
|
|
||||||
{
|
|
||||||
name: "subtractNumbers",
|
|
||||||
description: "Use this function to subtract two numbers",
|
|
||||||
parameters: z.object({
|
|
||||||
a: z.number().describe("The number to subtract from"),
|
|
||||||
b: z.number().describe("The number to subtract"),
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const gemini = new Gemini({
|
const myAgent = agent({
|
||||||
model: GEMINI_MODEL.GEMINI_PRO,
|
|
||||||
});
|
|
||||||
const agent = new LLMAgent({
|
|
||||||
llm: gemini,
|
|
||||||
tools: [sumNumbers, divideNumbers, subtractNumbers],
|
tools: [sumNumbers, divideNumbers, subtractNumbers],
|
||||||
|
llm: gemini({ model: GEMINI_MODEL.GEMINI_PRO }),
|
||||||
});
|
});
|
||||||
|
|
||||||
const response = await agent.chat({
|
const result = await myAgent.run(
|
||||||
message: "How much is 5 + 5? then divide by 2 then subtract 1",
|
"How much is 5 + 5? then divide by 2 then subtract 1",
|
||||||
});
|
);
|
||||||
|
console.log(result.data);
|
||||||
console.log(response.message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void main().then(() => {
|
void main().then(() => {
|
||||||
|
|||||||
+15
-14
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/examples",
|
"name": "@llamaindex/examples",
|
||||||
"version": "0.2.9",
|
"version": "0.2.10",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
@@ -15,23 +15,23 @@
|
|||||||
"@llamaindex/astra": "^0.0.13",
|
"@llamaindex/astra": "^0.0.13",
|
||||||
"@llamaindex/azure": "^0.1.8",
|
"@llamaindex/azure": "^0.1.8",
|
||||||
"@llamaindex/chroma": "^0.0.13",
|
"@llamaindex/chroma": "^0.0.13",
|
||||||
"@llamaindex/clip": "^0.0.44",
|
"@llamaindex/clip": "^0.0.45",
|
||||||
"@llamaindex/cloud": "^3.0.9",
|
"@llamaindex/cloud": "^3.0.9",
|
||||||
"@llamaindex/cohere": "^0.0.13",
|
"@llamaindex/cohere": "^0.0.13",
|
||||||
"@llamaindex/core": "^0.5.8",
|
"@llamaindex/core": "^0.5.8",
|
||||||
"@llamaindex/deepinfra": "^0.0.44",
|
"@llamaindex/deepinfra": "^0.0.45",
|
||||||
"@llamaindex/env": "^0.1.29",
|
"@llamaindex/env": "^0.1.29",
|
||||||
"@llamaindex/firestore": "^1.0.6",
|
"@llamaindex/firestore": "^1.0.6",
|
||||||
"@llamaindex/google": "^0.1.1",
|
"@llamaindex/google": "^0.1.2",
|
||||||
"@llamaindex/groq": "^0.0.59",
|
"@llamaindex/groq": "^0.0.60",
|
||||||
"@llamaindex/huggingface": "^0.0.44",
|
"@llamaindex/huggingface": "^0.0.45",
|
||||||
"@llamaindex/milvus": "^0.1.8",
|
"@llamaindex/milvus": "^0.1.8",
|
||||||
"@llamaindex/mistral": "^0.0.13",
|
"@llamaindex/mistral": "^0.0.14",
|
||||||
"@llamaindex/mixedbread": "^0.0.13",
|
"@llamaindex/mixedbread": "^0.0.13",
|
||||||
"@llamaindex/mongodb": "^0.0.13",
|
"@llamaindex/mongodb": "^0.0.13",
|
||||||
"@llamaindex/node-parser": "^1.0.8",
|
"@llamaindex/node-parser": "^1.0.8",
|
||||||
"@llamaindex/ollama": "^0.0.48",
|
"@llamaindex/ollama": "^0.0.48",
|
||||||
"@llamaindex/openai": "^0.1.60",
|
"@llamaindex/openai": "^0.1.61",
|
||||||
"@llamaindex/pinecone": "^0.0.13",
|
"@llamaindex/pinecone": "^0.0.13",
|
||||||
"@llamaindex/portkey-ai": "^0.0.41",
|
"@llamaindex/portkey-ai": "^0.0.41",
|
||||||
"@llamaindex/postgres": "^0.0.41",
|
"@llamaindex/postgres": "^0.0.41",
|
||||||
@@ -40,14 +40,15 @@
|
|||||||
"@llamaindex/replicate": "^0.0.41",
|
"@llamaindex/replicate": "^0.0.41",
|
||||||
"@llamaindex/upstash": "^0.0.13",
|
"@llamaindex/upstash": "^0.0.13",
|
||||||
"@llamaindex/vercel": "^0.0.19",
|
"@llamaindex/vercel": "^0.0.19",
|
||||||
"@llamaindex/vllm": "^0.0.30",
|
"@llamaindex/vllm": "^0.0.31",
|
||||||
"@llamaindex/voyage-ai": "^1.0.5",
|
"@llamaindex/voyage-ai": "^1.0.5",
|
||||||
"@llamaindex/weaviate": "^0.0.13",
|
"@llamaindex/weaviate": "^0.0.13",
|
||||||
"@llamaindex/workflow": "^0.0.16",
|
"@llamaindex/workflow": "^0.0.16",
|
||||||
"@llamaindex/deepseek": "^0.0.4",
|
"@llamaindex/deepseek": "^0.0.5",
|
||||||
"@llamaindex/fireworks": "^0.0.4",
|
"@llamaindex/fireworks": "^0.0.5",
|
||||||
"@llamaindex/together": "^0.0.4",
|
"@llamaindex/together": "^0.0.5",
|
||||||
"@llamaindex/jinaai": "^0.0.4",
|
"@llamaindex/jinaai": "^0.0.5",
|
||||||
|
"@llamaindex/perplexity": "^0.0.2",
|
||||||
"@notionhq/client": "^2.2.15",
|
"@notionhq/client": "^2.2.15",
|
||||||
"@pinecone-database/pinecone": "^4.0.0",
|
"@pinecone-database/pinecone": "^4.0.0",
|
||||||
"@vercel/postgres": "^0.10.0",
|
"@vercel/postgres": "^0.10.0",
|
||||||
@@ -56,7 +57,7 @@
|
|||||||
"commander": "^12.1.0",
|
"commander": "^12.1.0",
|
||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.4.5",
|
||||||
"js-tiktoken": "^1.0.14",
|
"js-tiktoken": "^1.0.14",
|
||||||
"llamaindex": "^0.9.10",
|
"llamaindex": "^0.9.11",
|
||||||
"mongodb": "6.7.0",
|
"mongodb": "6.7.0",
|
||||||
"postgres": "^3.4.4",
|
"postgres": "^3.4.4",
|
||||||
"wikipedia": "^2.1.2",
|
"wikipedia": "^2.1.2",
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
import { perplexity } from "@llamaindex/perplexity";
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
const perplexityLLM = perplexity({
|
||||||
|
apiKey: process.env.PERPLEXITY_API_KEY!,
|
||||||
|
model: "sonar",
|
||||||
|
});
|
||||||
|
|
||||||
|
// Chat API example
|
||||||
|
const response = await perplexityLLM.chat({
|
||||||
|
messages: [
|
||||||
|
{
|
||||||
|
role: "system",
|
||||||
|
content:
|
||||||
|
"You are a helpful AI assistant that provides accurate and concise answers",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
role: "user",
|
||||||
|
content: "What is the capital of France?",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
console.log("Chat response:", response.message.content);
|
||||||
|
|
||||||
|
// Streaming example
|
||||||
|
const stream = await perplexityLLM.chat({
|
||||||
|
messages: [
|
||||||
|
{
|
||||||
|
role: "system",
|
||||||
|
content: "You are a creative AI assistant that tells engaging stories",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
role: "user",
|
||||||
|
content: "Tell me a short story",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
stream: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("\nStreaming response:");
|
||||||
|
for await (const chunk of stream) {
|
||||||
|
process.stdout.write(chunk.delta);
|
||||||
|
}
|
||||||
|
})();
|
||||||
@@ -1,5 +1,11 @@
|
|||||||
# @llamaindex/autotool
|
# @llamaindex/autotool
|
||||||
|
|
||||||
|
## 6.0.11
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- llamaindex@0.9.11
|
||||||
|
|
||||||
## 6.0.10
|
## 6.0.10
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
# @llamaindex/autotool-01-node-example
|
# @llamaindex/autotool-01-node-example
|
||||||
|
|
||||||
|
## 0.0.92
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- llamaindex@0.9.11
|
||||||
|
- @llamaindex/autotool@6.0.11
|
||||||
|
|
||||||
## 0.0.91
|
## 0.0.91
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -13,5 +13,5 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node --import tsx --import @llamaindex/autotool/node ./src/index.ts"
|
"start": "node --import tsx --import @llamaindex/autotool/node ./src/index.ts"
|
||||||
},
|
},
|
||||||
"version": "0.0.91"
|
"version": "0.0.92"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
"url": "git+https://github.com/run-llama/LlamaIndexTS.git",
|
"url": "git+https://github.com/run-llama/LlamaIndexTS.git",
|
||||||
"directory": "packages/autotool"
|
"directory": "packages/autotool"
|
||||||
},
|
},
|
||||||
"version": "6.0.10",
|
"version": "6.0.11",
|
||||||
"description": "auto transpile your JS function to LLM Agent compatible",
|
"description": "auto transpile your JS function to LLM Agent compatible",
|
||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"dist",
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
# @llamaindex/experimental
|
# @llamaindex/experimental
|
||||||
|
|
||||||
|
## 0.0.161
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- llamaindex@0.9.11
|
||||||
|
|
||||||
## 0.0.160
|
## 0.0.160
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/experimental",
|
"name": "@llamaindex/experimental",
|
||||||
"description": "Experimental package for LlamaIndexTS",
|
"description": "Experimental package for LlamaIndexTS",
|
||||||
"version": "0.0.160",
|
"version": "0.0.161",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"types": "dist/type/index.d.ts",
|
"types": "dist/type/index.d.ts",
|
||||||
"main": "dist/cjs/index.js",
|
"main": "dist/cjs/index.js",
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
# llamaindex
|
# llamaindex
|
||||||
|
|
||||||
|
## 0.9.11
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [a8c0637]
|
||||||
|
- @llamaindex/openai@0.1.61
|
||||||
|
|
||||||
## 0.9.10
|
## 0.9.10
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "llamaindex",
|
"name": "llamaindex",
|
||||||
"version": "0.9.10",
|
"version": "0.9.11",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
# @llamaindex/clip
|
# @llamaindex/clip
|
||||||
|
|
||||||
|
## 0.0.45
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [a8c0637]
|
||||||
|
- @llamaindex/openai@0.1.61
|
||||||
|
|
||||||
## 0.0.44
|
## 0.0.44
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/clip",
|
"name": "@llamaindex/clip",
|
||||||
"description": "Clip Embedding Adapter for LlamaIndex",
|
"description": "Clip Embedding Adapter for LlamaIndex",
|
||||||
"version": "0.0.44",
|
"version": "0.0.45",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
"main": "dist/index.cjs",
|
"main": "dist/index.cjs",
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
# @llamaindex/deepinfra
|
# @llamaindex/deepinfra
|
||||||
|
|
||||||
|
## 0.0.45
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [a8c0637]
|
||||||
|
- @llamaindex/openai@0.1.61
|
||||||
|
|
||||||
## 0.0.44
|
## 0.0.44
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/deepinfra",
|
"name": "@llamaindex/deepinfra",
|
||||||
"description": "Deepinfra Adapter for LlamaIndex",
|
"description": "Deepinfra Adapter for LlamaIndex",
|
||||||
"version": "0.0.44",
|
"version": "0.0.45",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./dist/index.cjs",
|
"main": "./dist/index.cjs",
|
||||||
"module": "./dist/index.js",
|
"module": "./dist/index.js",
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
# @llamaindex/deepseek
|
# @llamaindex/deepseek
|
||||||
|
|
||||||
|
## 0.0.5
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [a8c0637]
|
||||||
|
- @llamaindex/openai@0.1.61
|
||||||
|
|
||||||
## 0.0.4
|
## 0.0.4
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/deepseek",
|
"name": "@llamaindex/deepseek",
|
||||||
"description": "DeepSeek Adapter for LlamaIndex",
|
"description": "DeepSeek Adapter for LlamaIndex",
|
||||||
"version": "0.0.4",
|
"version": "0.0.5",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./dist/index.cjs",
|
"main": "./dist/index.cjs",
|
||||||
"module": "./dist/index.js",
|
"module": "./dist/index.js",
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
# @llamaindex/fireworks
|
# @llamaindex/fireworks
|
||||||
|
|
||||||
|
## 0.0.5
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [a8c0637]
|
||||||
|
- @llamaindex/openai@0.1.61
|
||||||
|
|
||||||
## 0.0.4
|
## 0.0.4
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/fireworks",
|
"name": "@llamaindex/fireworks",
|
||||||
"description": "Fireworks Adapter for LlamaIndex",
|
"description": "Fireworks Adapter for LlamaIndex",
|
||||||
"version": "0.0.4",
|
"version": "0.0.5",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./dist/index.cjs",
|
"main": "./dist/index.cjs",
|
||||||
"module": "./dist/index.js",
|
"module": "./dist/index.js",
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
# @llamaindex/google
|
# @llamaindex/google
|
||||||
|
|
||||||
|
## 0.1.2
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 98eebf7: Add RequestOptions parameter passing to support Gemini proxy calls.
|
||||||
|
Add a usage example for the RequestOptions parameter.
|
||||||
|
|
||||||
## 0.1.1
|
## 0.1.1
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/google",
|
"name": "@llamaindex/google",
|
||||||
"description": "Google Adapter for LlamaIndex",
|
"description": "Google Adapter for LlamaIndex",
|
||||||
"version": "0.1.1",
|
"version": "0.1.2",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./dist/index.cjs",
|
"main": "./dist/index.cjs",
|
||||||
"module": "./dist/index.js",
|
"module": "./dist/index.js",
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
type EnhancedGenerateContentResponse,
|
type EnhancedGenerateContentResponse,
|
||||||
type FunctionCall,
|
type FunctionCall,
|
||||||
type ModelParams as GoogleModelParams,
|
type ModelParams as GoogleModelParams,
|
||||||
|
type RequestOptions as GoogleRequestOptions,
|
||||||
type GenerateContentStreamResult as GoogleStreamGenerateContentResult,
|
type GenerateContentStreamResult as GoogleStreamGenerateContentResult,
|
||||||
} from "@google/generative-ai";
|
} from "@google/generative-ai";
|
||||||
|
|
||||||
@@ -86,6 +87,7 @@ const DEFAULT_GEMINI_PARAMS = {
|
|||||||
|
|
||||||
export type GeminiConfig = Partial<typeof DEFAULT_GEMINI_PARAMS> & {
|
export type GeminiConfig = Partial<typeof DEFAULT_GEMINI_PARAMS> & {
|
||||||
session?: IGeminiSession;
|
session?: IGeminiSession;
|
||||||
|
requestOptions?: GoogleRequestOptions;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -104,11 +106,17 @@ export class GeminiSession implements IGeminiSession {
|
|||||||
this.gemini = new GoogleGenerativeAI(options.apiKey);
|
this.gemini = new GoogleGenerativeAI(options.apiKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
getGenerativeModel(metadata: GoogleModelParams): GoogleGenerativeModel {
|
getGenerativeModel(
|
||||||
return this.gemini.getGenerativeModel({
|
metadata: GoogleModelParams,
|
||||||
safetySettings: DEFAULT_SAFETY_SETTINGS,
|
requestOpts?: GoogleRequestOptions,
|
||||||
...metadata,
|
): GoogleGenerativeModel {
|
||||||
});
|
return this.gemini.getGenerativeModel(
|
||||||
|
{
|
||||||
|
safetySettings: DEFAULT_SAFETY_SETTINGS,
|
||||||
|
...metadata,
|
||||||
|
},
|
||||||
|
requestOpts,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
getResponseText(response: EnhancedGenerateContentResponse): string {
|
getResponseText(response: EnhancedGenerateContentResponse): string {
|
||||||
@@ -173,6 +181,9 @@ export class GeminiSessionStore {
|
|||||||
o1: GeminiSessionOptions,
|
o1: GeminiSessionOptions,
|
||||||
o2: GeminiSessionOptions,
|
o2: GeminiSessionOptions,
|
||||||
): boolean {
|
): boolean {
|
||||||
|
// #TODO: check if the session is matched
|
||||||
|
// Q: should we check the requestOptions?
|
||||||
|
// A: wait for confirmation from author
|
||||||
return (
|
return (
|
||||||
GeminiSessionStore.getSessionId(o1) ===
|
GeminiSessionStore.getSessionId(o1) ===
|
||||||
GeminiSessionStore.getSessionId(o2)
|
GeminiSessionStore.getSessionId(o2)
|
||||||
@@ -205,6 +216,7 @@ export class Gemini extends ToolCallLLM<GeminiAdditionalChatOptions> {
|
|||||||
temperature: number;
|
temperature: number;
|
||||||
topP: number;
|
topP: number;
|
||||||
maxTokens?: number | undefined;
|
maxTokens?: number | undefined;
|
||||||
|
#requestOptions?: GoogleRequestOptions | undefined;
|
||||||
session: IGeminiSession;
|
session: IGeminiSession;
|
||||||
|
|
||||||
constructor(init?: GeminiConfig) {
|
constructor(init?: GeminiConfig) {
|
||||||
@@ -214,6 +226,7 @@ export class Gemini extends ToolCallLLM<GeminiAdditionalChatOptions> {
|
|||||||
this.topP = init?.topP ?? 1;
|
this.topP = init?.topP ?? 1;
|
||||||
this.maxTokens = init?.maxTokens ?? undefined;
|
this.maxTokens = init?.maxTokens ?? undefined;
|
||||||
this.session = init?.session ?? GeminiSessionStore.get();
|
this.session = init?.session ?? GeminiSessionStore.get();
|
||||||
|
this.#requestOptions = init?.requestOptions ?? undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
get supportToolCall(): boolean {
|
get supportToolCall(): boolean {
|
||||||
@@ -260,7 +273,10 @@ export class Gemini extends ToolCallLLM<GeminiAdditionalChatOptions> {
|
|||||||
params: GeminiChatParamsNonStreaming,
|
params: GeminiChatParamsNonStreaming,
|
||||||
): Promise<GeminiChatNonStreamResponse> {
|
): Promise<GeminiChatNonStreamResponse> {
|
||||||
const context = getChatContext(params);
|
const context = getChatContext(params);
|
||||||
const client = this.session.getGenerativeModel(this.metadata);
|
const client = this.session.getGenerativeModel(
|
||||||
|
this.metadata,
|
||||||
|
this.#requestOptions,
|
||||||
|
);
|
||||||
const chat = client.startChat(this.createStartChatParams(params));
|
const chat = client.startChat(this.createStartChatParams(params));
|
||||||
const { response } = await chat.sendMessage(context.message);
|
const { response } = await chat.sendMessage(context.message);
|
||||||
const topCandidate = response.candidates![0]!;
|
const topCandidate = response.candidates![0]!;
|
||||||
@@ -286,7 +302,10 @@ export class Gemini extends ToolCallLLM<GeminiAdditionalChatOptions> {
|
|||||||
params: GeminiChatParamsStreaming,
|
params: GeminiChatParamsStreaming,
|
||||||
): GeminiChatStreamResponse {
|
): GeminiChatStreamResponse {
|
||||||
const context = getChatContext(params);
|
const context = getChatContext(params);
|
||||||
const client = this.session.getGenerativeModel(this.metadata);
|
const client = this.session.getGenerativeModel(
|
||||||
|
this.metadata,
|
||||||
|
this.#requestOptions,
|
||||||
|
);
|
||||||
const chat = client.startChat(this.createStartChatParams(params));
|
const chat = client.startChat(this.createStartChatParams(params));
|
||||||
const result = await chat.sendMessageStream(context.message);
|
const result = await chat.sendMessageStream(context.message);
|
||||||
yield* this.session.getChatStream(result);
|
yield* this.session.getChatStream(result);
|
||||||
@@ -314,8 +333,10 @@ export class Gemini extends ToolCallLLM<GeminiAdditionalChatOptions> {
|
|||||||
params: LLMCompletionParamsStreaming | LLMCompletionParamsNonStreaming,
|
params: LLMCompletionParamsStreaming | LLMCompletionParamsNonStreaming,
|
||||||
): Promise<CompletionResponse | AsyncIterable<CompletionResponse>> {
|
): Promise<CompletionResponse | AsyncIterable<CompletionResponse>> {
|
||||||
const { prompt, stream } = params;
|
const { prompt, stream } = params;
|
||||||
const client = this.session.getGenerativeModel(this.metadata);
|
const client = this.session.getGenerativeModel(
|
||||||
|
this.metadata,
|
||||||
|
this.#requestOptions,
|
||||||
|
);
|
||||||
if (stream) {
|
if (stream) {
|
||||||
const result = await client.generateContentStream(
|
const result = await client.generateContentStream(
|
||||||
getPartsText(
|
getPartsText(
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
type InlineDataPart as GoogleInlineFileDataPart,
|
type InlineDataPart as GoogleInlineFileDataPart,
|
||||||
type ModelParams as GoogleModelParams,
|
type ModelParams as GoogleModelParams,
|
||||||
type Part as GooglePart,
|
type Part as GooglePart,
|
||||||
|
type RequestOptions as GoogleRequestOptions,
|
||||||
type GenerateContentStreamResult as GoogleStreamGenerateContentResult,
|
type GenerateContentStreamResult as GoogleStreamGenerateContentResult,
|
||||||
} from "@google/generative-ai";
|
} from "@google/generative-ai";
|
||||||
|
|
||||||
@@ -35,6 +36,8 @@ import type {
|
|||||||
ToolCallLLMMessageOptions,
|
ToolCallLLMMessageOptions,
|
||||||
} from "@llamaindex/core/llms";
|
} from "@llamaindex/core/llms";
|
||||||
|
|
||||||
|
export { type RequestOptions as GoogleRequestOptions } from "@google/generative-ai";
|
||||||
|
|
||||||
export enum GEMINI_BACKENDS {
|
export enum GEMINI_BACKENDS {
|
||||||
GOOGLE = "google",
|
GOOGLE = "google",
|
||||||
VERTEX = "vertex",
|
VERTEX = "vertex",
|
||||||
@@ -121,7 +124,10 @@ export type GeminiChatNonStreamResponse =
|
|||||||
ChatResponse<ToolCallLLMMessageOptions>;
|
ChatResponse<ToolCallLLMMessageOptions>;
|
||||||
|
|
||||||
export interface IGeminiSession {
|
export interface IGeminiSession {
|
||||||
getGenerativeModel(metadata: ModelParams): GenerativeModel;
|
getGenerativeModel(
|
||||||
|
metadata: ModelParams,
|
||||||
|
requestOptions?: GoogleRequestOptions,
|
||||||
|
): GenerativeModel;
|
||||||
getResponseText(
|
getResponseText(
|
||||||
response: EnhancedGenerateContentResponse | GenerateContentResponse,
|
response: EnhancedGenerateContentResponse | GenerateContentResponse,
|
||||||
): string;
|
): string;
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
# @llamaindex/groq
|
# @llamaindex/groq
|
||||||
|
|
||||||
|
## 0.0.60
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [a8c0637]
|
||||||
|
- @llamaindex/openai@0.1.61
|
||||||
|
|
||||||
## 0.0.59
|
## 0.0.59
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/groq",
|
"name": "@llamaindex/groq",
|
||||||
"description": "Groq Adapter for LlamaIndex",
|
"description": "Groq Adapter for LlamaIndex",
|
||||||
"version": "0.0.59",
|
"version": "0.0.60",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./dist/index.cjs",
|
"main": "./dist/index.cjs",
|
||||||
"module": "./dist/index.js",
|
"module": "./dist/index.js",
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
# @llamaindex/huggingface
|
# @llamaindex/huggingface
|
||||||
|
|
||||||
|
## 0.0.45
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [a8c0637]
|
||||||
|
- @llamaindex/openai@0.1.61
|
||||||
|
|
||||||
## 0.0.44
|
## 0.0.44
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/huggingface",
|
"name": "@llamaindex/huggingface",
|
||||||
"description": "Huggingface Adapter for LlamaIndex",
|
"description": "Huggingface Adapter for LlamaIndex",
|
||||||
"version": "0.0.44",
|
"version": "0.0.45",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
"main": "dist/index.cjs",
|
"main": "dist/index.cjs",
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
# @llamaindex/jinaai
|
# @llamaindex/jinaai
|
||||||
|
|
||||||
|
## 0.0.5
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [a8c0637]
|
||||||
|
- @llamaindex/openai@0.1.61
|
||||||
|
|
||||||
## 0.0.4
|
## 0.0.4
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/jinaai",
|
"name": "@llamaindex/jinaai",
|
||||||
"description": "JinaAI Adapter for LlamaIndex",
|
"description": "JinaAI Adapter for LlamaIndex",
|
||||||
"version": "0.0.4",
|
"version": "0.0.5",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./dist/index.cjs",
|
"main": "./dist/index.cjs",
|
||||||
"module": "./dist/index.js",
|
"module": "./dist/index.js",
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
# @llamaindex/mistral
|
# @llamaindex/mistral
|
||||||
|
|
||||||
|
## 0.0.14
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 387a192: Update mistral package for mistral API 1.5.1
|
||||||
|
|
||||||
## 0.0.13
|
## 0.0.13
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/mistral",
|
"name": "@llamaindex/mistral",
|
||||||
"description": "Mistral Adapter for LlamaIndex",
|
"description": "Mistral Adapter for LlamaIndex",
|
||||||
"version": "0.0.13",
|
"version": "0.0.14",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./dist/index.cjs",
|
"main": "./dist/index.cjs",
|
||||||
"module": "./dist/index.js",
|
"module": "./dist/index.js",
|
||||||
@@ -35,6 +35,6 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@llamaindex/core": "workspace:*",
|
"@llamaindex/core": "workspace:*",
|
||||||
"@llamaindex/env": "workspace:*",
|
"@llamaindex/env": "workspace:*",
|
||||||
"@mistralai/mistralai": "^1.3.4"
|
"@mistralai/mistralai": "^1.5.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,12 +19,12 @@ export class MistralAIEmbedding extends BaseEmbedding {
|
|||||||
|
|
||||||
private async getMistralAIEmbedding(input: string) {
|
private async getMistralAIEmbedding(input: string) {
|
||||||
const client = await this.session.getClient();
|
const client = await this.session.getClient();
|
||||||
const { data } = await client.embeddings({
|
const { data } = await client.embeddings.create({
|
||||||
model: this.model,
|
model: this.model,
|
||||||
input: [input],
|
inputs: [input],
|
||||||
});
|
});
|
||||||
|
|
||||||
return data[0].embedding;
|
return data[0]?.embedding ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTextEmbedding(text: string): Promise<number[]> {
|
async getTextEmbedding(text: string): Promise<number[]> {
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import {
|
|||||||
type LLMChatParamsStreaming,
|
type LLMChatParamsStreaming,
|
||||||
} from "@llamaindex/core/llms";
|
} from "@llamaindex/core/llms";
|
||||||
import { getEnv } from "@llamaindex/env";
|
import { getEnv } from "@llamaindex/env";
|
||||||
|
import { type Mistral } from "@mistralai/mistralai";
|
||||||
|
import type { ContentChunk } from "@mistralai/mistralai/models/components";
|
||||||
|
|
||||||
export const ALL_AVAILABLE_MISTRAL_MODELS = {
|
export const ALL_AVAILABLE_MISTRAL_MODELS = {
|
||||||
"mistral-tiny": { contextWindow: 32000 },
|
"mistral-tiny": { contextWindow: 32000 },
|
||||||
@@ -30,7 +32,7 @@ export class MistralAISession {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getClient() {
|
async getClient(): Promise<Mistral> {
|
||||||
const { Mistral } = await import("@mistralai/mistralai");
|
const { Mistral } = await import("@mistralai/mistralai");
|
||||||
if (!this.client) {
|
if (!this.client) {
|
||||||
this.client = new Mistral({
|
this.client = new Mistral({
|
||||||
@@ -105,11 +107,21 @@ export class MistralAI extends BaseLLM {
|
|||||||
}
|
}
|
||||||
// Non-streaming
|
// Non-streaming
|
||||||
const client = await this.session.getClient();
|
const client = await this.session.getClient();
|
||||||
const response = await client.chat(this.buildParams(messages));
|
const response = await client.chat.complete(this.buildParams(messages));
|
||||||
const message = response.choices[0].message;
|
|
||||||
|
if (!response || !response.choices || !response.choices[0]) {
|
||||||
|
throw new Error("Unexpected response format from Mistral API");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the content from the message response
|
||||||
|
const content = response.choices[0].message.content;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
raw: response,
|
raw: response,
|
||||||
message,
|
message: {
|
||||||
|
role: "assistant",
|
||||||
|
content: this.extractContentAsString(content),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,23 +129,32 @@ export class MistralAI extends BaseLLM {
|
|||||||
messages,
|
messages,
|
||||||
}: LLMChatParamsStreaming): AsyncIterable<ChatResponseChunk> {
|
}: LLMChatParamsStreaming): AsyncIterable<ChatResponseChunk> {
|
||||||
const client = await this.session.getClient();
|
const client = await this.session.getClient();
|
||||||
const chunkStream = await client.chatStream(this.buildParams(messages));
|
const chunkStream = await client.chat.stream(this.buildParams(messages));
|
||||||
|
|
||||||
//Indices
|
for await (const chunk of chunkStream) {
|
||||||
let idx_counter: number = 0;
|
if (!chunk.data || !chunk.data.choices || !chunk.data.choices.length)
|
||||||
for await (const part of chunkStream) {
|
continue;
|
||||||
if (!part.choices.length) continue;
|
|
||||||
|
|
||||||
part.choices[0].index = idx_counter;
|
const choice = chunk.data.choices[0];
|
||||||
|
if (!choice) continue;
|
||||||
idx_counter++;
|
|
||||||
|
|
||||||
yield {
|
yield {
|
||||||
raw: part,
|
raw: chunk.data,
|
||||||
delta: part.choices[0].delta.content ?? "",
|
delta: this.extractContentAsString(choice.delta.content),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return;
|
}
|
||||||
|
|
||||||
|
private extractContentAsString(
|
||||||
|
content: string | ContentChunk[] | null | undefined,
|
||||||
|
): string {
|
||||||
|
if (Array.isArray(content)) {
|
||||||
|
return content
|
||||||
|
.map((chunk) => (chunk.type === "text" ? chunk.text : undefined))
|
||||||
|
.filter(Boolean)
|
||||||
|
.join("");
|
||||||
|
}
|
||||||
|
return content ?? "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
# @llamaindex/openai
|
# @llamaindex/openai
|
||||||
|
|
||||||
|
## 0.1.61
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- a8c0637: feat: simplify to provide base URL to OpenAI
|
||||||
|
|
||||||
## 0.1.60
|
## 0.1.60
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/openai",
|
"name": "@llamaindex/openai",
|
||||||
"description": "OpenAI Adapter for LlamaIndex",
|
"description": "OpenAI Adapter for LlamaIndex",
|
||||||
"version": "0.1.60",
|
"version": "0.1.61",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./dist/index.cjs",
|
"main": "./dist/index.cjs",
|
||||||
"module": "./dist/index.js",
|
"module": "./dist/index.js",
|
||||||
|
|||||||
@@ -36,7 +36,10 @@ export const ALL_OPENAI_EMBEDDING_MODELS = {
|
|||||||
|
|
||||||
type ModelKeys = keyof typeof ALL_OPENAI_EMBEDDING_MODELS;
|
type ModelKeys = keyof typeof ALL_OPENAI_EMBEDDING_MODELS;
|
||||||
|
|
||||||
type LLMInstance = Pick<AzureOpenAILLM | OpenAILLM, "embeddings" | "apiKey">;
|
type LLMInstance = Pick<
|
||||||
|
AzureOpenAILLM | OpenAILLM,
|
||||||
|
"embeddings" | "apiKey" | "baseURL"
|
||||||
|
>;
|
||||||
|
|
||||||
export class OpenAIEmbedding extends BaseEmbedding {
|
export class OpenAIEmbedding extends BaseEmbedding {
|
||||||
/** embeddding model. defaults to "text-embedding-ada-002" */
|
/** embeddding model. defaults to "text-embedding-ada-002" */
|
||||||
@@ -48,6 +51,8 @@ export class OpenAIEmbedding extends BaseEmbedding {
|
|||||||
|
|
||||||
/** api key */
|
/** api key */
|
||||||
apiKey?: string | undefined = undefined;
|
apiKey?: string | undefined = undefined;
|
||||||
|
/** base url */
|
||||||
|
baseURL?: string | undefined = undefined;
|
||||||
/** maximum number of retries, default 10 */
|
/** maximum number of retries, default 10 */
|
||||||
maxRetries: number;
|
maxRetries: number;
|
||||||
/** timeout in ms, default 60 seconds */
|
/** timeout in ms, default 60 seconds */
|
||||||
@@ -104,6 +109,10 @@ export class OpenAIEmbedding extends BaseEmbedding {
|
|||||||
};
|
};
|
||||||
this.apiKey =
|
this.apiKey =
|
||||||
init?.session?.apiKey ?? azureConfig.apiKey ?? getEnv("OPENAI_API_KEY");
|
init?.session?.apiKey ?? azureConfig.apiKey ?? getEnv("OPENAI_API_KEY");
|
||||||
|
this.baseURL =
|
||||||
|
init?.session?.baseURL ??
|
||||||
|
azureConfig.baseURL ??
|
||||||
|
getEnv("OPENAI_BASE_URL");
|
||||||
this.lazySession = async () =>
|
this.lazySession = async () =>
|
||||||
import("openai").then(async ({ AzureOpenAI }) => {
|
import("openai").then(async ({ AzureOpenAI }) => {
|
||||||
AzureOpenAI = AzureOpenAIWithUserAgent(AzureOpenAI);
|
AzureOpenAI = AzureOpenAIWithUserAgent(AzureOpenAI);
|
||||||
@@ -121,12 +130,15 @@ export class OpenAIEmbedding extends BaseEmbedding {
|
|||||||
} else {
|
} else {
|
||||||
this.apiKey =
|
this.apiKey =
|
||||||
init?.session?.apiKey ?? init?.apiKey ?? getEnv("OPENAI_API_KEY");
|
init?.session?.apiKey ?? init?.apiKey ?? getEnv("OPENAI_API_KEY");
|
||||||
|
this.baseURL =
|
||||||
|
init?.session?.baseURL ?? init?.baseURL ?? getEnv("OPENAI_BASE_URL");
|
||||||
this.lazySession = async () =>
|
this.lazySession = async () =>
|
||||||
import("openai").then(({ OpenAI }) => {
|
import("openai").then(({ OpenAI }) => {
|
||||||
return (
|
return (
|
||||||
init?.session ??
|
init?.session ??
|
||||||
new OpenAI({
|
new OpenAI({
|
||||||
apiKey: this.apiKey,
|
apiKey: this.apiKey,
|
||||||
|
baseURL: this.baseURL,
|
||||||
maxRetries: this.maxRetries,
|
maxRetries: this.maxRetries,
|
||||||
timeout: this.timeout!,
|
timeout: this.timeout!,
|
||||||
...this.additionalSessionOptions,
|
...this.additionalSessionOptions,
|
||||||
|
|||||||
@@ -182,7 +182,10 @@ export type OpenAIAdditionalChatOptions = Omit<
|
|||||||
| "toolChoice"
|
| "toolChoice"
|
||||||
>;
|
>;
|
||||||
|
|
||||||
type LLMInstance = Pick<AzureOpenAILLM | OpenAILLM, "chat" | "apiKey">;
|
type LLMInstance = Pick<
|
||||||
|
AzureOpenAILLM | OpenAILLM,
|
||||||
|
"chat" | "apiKey" | "baseURL"
|
||||||
|
>;
|
||||||
|
|
||||||
export class OpenAI extends ToolCallLLM<OpenAIAdditionalChatOptions> {
|
export class OpenAI extends ToolCallLLM<OpenAIAdditionalChatOptions> {
|
||||||
model:
|
model:
|
||||||
@@ -197,6 +200,7 @@ export class OpenAI extends ToolCallLLM<OpenAIAdditionalChatOptions> {
|
|||||||
|
|
||||||
// OpenAI session params
|
// OpenAI session params
|
||||||
apiKey?: string | undefined = undefined;
|
apiKey?: string | undefined = undefined;
|
||||||
|
baseURL?: string | undefined = undefined;
|
||||||
maxRetries: number;
|
maxRetries: number;
|
||||||
timeout?: number;
|
timeout?: number;
|
||||||
additionalSessionOptions?:
|
additionalSessionOptions?:
|
||||||
@@ -234,6 +238,8 @@ export class OpenAI extends ToolCallLLM<OpenAIAdditionalChatOptions> {
|
|||||||
this.additionalSessionOptions = init?.additionalSessionOptions;
|
this.additionalSessionOptions = init?.additionalSessionOptions;
|
||||||
this.apiKey =
|
this.apiKey =
|
||||||
init?.session?.apiKey ?? init?.apiKey ?? getEnv("OPENAI_API_KEY");
|
init?.session?.apiKey ?? init?.apiKey ?? getEnv("OPENAI_API_KEY");
|
||||||
|
this.baseURL =
|
||||||
|
init?.session?.baseURL ?? init?.baseURL ?? getEnv("OPENAI_BASE_URL");
|
||||||
|
|
||||||
if (init?.azure || shouldUseAzure()) {
|
if (init?.azure || shouldUseAzure()) {
|
||||||
const azureConfig = {
|
const azureConfig = {
|
||||||
@@ -261,6 +267,7 @@ export class OpenAI extends ToolCallLLM<OpenAIAdditionalChatOptions> {
|
|||||||
import("openai").then(({ OpenAI }) => {
|
import("openai").then(({ OpenAI }) => {
|
||||||
return new OpenAI({
|
return new OpenAI({
|
||||||
apiKey: this.apiKey,
|
apiKey: this.apiKey,
|
||||||
|
baseURL: this.baseURL,
|
||||||
maxRetries: this.maxRetries,
|
maxRetries: this.maxRetries,
|
||||||
timeout: this.timeout!,
|
timeout: this.timeout!,
|
||||||
...this.additionalSessionOptions,
|
...this.additionalSessionOptions,
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# @llamaindex/perplexity
|
||||||
|
|
||||||
|
## 0.0.2
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 1587e48: Added support for Perplexity api
|
||||||
|
- Updated dependencies [a8c0637]
|
||||||
|
- @llamaindex/openai@0.1.61
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
{
|
||||||
|
"name": "@llamaindex/perplexity",
|
||||||
|
"description": "Perplexity Adapter for LlamaIndex",
|
||||||
|
"version": "0.0.2",
|
||||||
|
"type": "module",
|
||||||
|
"main": "./dist/index.cjs",
|
||||||
|
"module": "./dist/index.js",
|
||||||
|
"exports": {
|
||||||
|
".": {
|
||||||
|
"require": {
|
||||||
|
"types": "./dist/index.d.cts",
|
||||||
|
"default": "./dist/index.cjs"
|
||||||
|
},
|
||||||
|
"import": {
|
||||||
|
"types": "./dist/index.d.ts",
|
||||||
|
"default": "./dist/index.js"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"dist"
|
||||||
|
],
|
||||||
|
"scripts": {
|
||||||
|
"build": "bunchee",
|
||||||
|
"dev": "bunchee --watch"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"bunchee": "6.4.0"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"@llamaindex/core": "workspace:*",
|
||||||
|
"@llamaindex/env": "workspace:*",
|
||||||
|
"@llamaindex/openai": "workspace:*"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export * from "./llm";
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
import { getEnv } from "@llamaindex/env";
|
||||||
|
import { Tokenizers } from "@llamaindex/env/tokenizers";
|
||||||
|
import { OpenAI } from "@llamaindex/openai";
|
||||||
|
|
||||||
|
export const PERPLEXITY_MODELS = {
|
||||||
|
"sonar-deep-research": {
|
||||||
|
contextWindow: 128000,
|
||||||
|
},
|
||||||
|
"sonar-reasoning-pro": {
|
||||||
|
contextWindow: 128000,
|
||||||
|
},
|
||||||
|
"sonar-reasoning": {
|
||||||
|
contextWindow: 128000,
|
||||||
|
},
|
||||||
|
"sonar-pro": {
|
||||||
|
contextWindow: 200000,
|
||||||
|
},
|
||||||
|
sonar: {
|
||||||
|
contextWindow: 128000,
|
||||||
|
},
|
||||||
|
"r1-1776": {
|
||||||
|
contextWindow: 128000,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
type PerplexityModelName = keyof typeof PERPLEXITY_MODELS;
|
||||||
|
const DEFAULT_MODEL: PerplexityModelName = "sonar";
|
||||||
|
|
||||||
|
export class Perplexity extends OpenAI {
|
||||||
|
constructor(
|
||||||
|
init?: Omit<Partial<OpenAI>, "session"> & { model?: PerplexityModelName },
|
||||||
|
) {
|
||||||
|
const {
|
||||||
|
apiKey = getEnv("PERPLEXITY_API_KEY"),
|
||||||
|
additionalSessionOptions = {},
|
||||||
|
model = DEFAULT_MODEL,
|
||||||
|
...rest
|
||||||
|
} = init ?? {};
|
||||||
|
|
||||||
|
if (!apiKey) {
|
||||||
|
throw new Error("Perplexity API key is required");
|
||||||
|
}
|
||||||
|
|
||||||
|
additionalSessionOptions.baseURL =
|
||||||
|
additionalSessionOptions.baseURL ?? "https://api.perplexity.ai/";
|
||||||
|
|
||||||
|
super({
|
||||||
|
apiKey,
|
||||||
|
additionalSessionOptions,
|
||||||
|
model,
|
||||||
|
...rest,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
get supportToolCall() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
get metadata() {
|
||||||
|
return {
|
||||||
|
model: this.model,
|
||||||
|
temperature: this.temperature,
|
||||||
|
topP: this.topP,
|
||||||
|
contextWindow:
|
||||||
|
PERPLEXITY_MODELS[this.model as PerplexityModelName]?.contextWindow,
|
||||||
|
tokenizer: Tokenizers.CL100K_BASE,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience function to create a new Perplexity instance.
|
||||||
|
* @param init - Optional initialization parameters for the Perplexity instance.
|
||||||
|
* @returns A new Perplexity instance.
|
||||||
|
*/
|
||||||
|
export const perplexity = (
|
||||||
|
init?: ConstructorParameters<typeof Perplexity>[0],
|
||||||
|
) => new Perplexity(init);
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../../tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ESNext",
|
||||||
|
"module": "ESNext",
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"outDir": "./lib",
|
||||||
|
"tsBuildInfoFile": "./lib/.tsbuildinfo"
|
||||||
|
},
|
||||||
|
"include": ["./src", "package.json"],
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"path": "../../core/tsconfig.json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "../../env/tsconfig.json"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1,5 +1,12 @@
|
|||||||
# @llamaindex/together
|
# @llamaindex/together
|
||||||
|
|
||||||
|
## 0.0.5
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [a8c0637]
|
||||||
|
- @llamaindex/openai@0.1.61
|
||||||
|
|
||||||
## 0.0.4
|
## 0.0.4
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/together",
|
"name": "@llamaindex/together",
|
||||||
"description": "Together Adapter for LlamaIndex",
|
"description": "Together Adapter for LlamaIndex",
|
||||||
"version": "0.0.4",
|
"version": "0.0.5",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./dist/index.cjs",
|
"main": "./dist/index.cjs",
|
||||||
"module": "./dist/index.js",
|
"module": "./dist/index.js",
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
# @llamaindex/vllm
|
# @llamaindex/vllm
|
||||||
|
|
||||||
|
## 0.0.31
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [a8c0637]
|
||||||
|
- @llamaindex/openai@0.1.61
|
||||||
|
|
||||||
## 0.0.30
|
## 0.0.30
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/vllm",
|
"name": "@llamaindex/vllm",
|
||||||
"description": "vLLM Adapter for LlamaIndex",
|
"description": "vLLM Adapter for LlamaIndex",
|
||||||
"version": "0.0.30",
|
"version": "0.0.31",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./dist/index.cjs",
|
"main": "./dist/index.cjs",
|
||||||
"module": "./dist/index.js",
|
"module": "./dist/index.js",
|
||||||
|
|||||||
Generated
+37
-18
@@ -597,7 +597,7 @@ importers:
|
|||||||
specifier: ^0.0.13
|
specifier: ^0.0.13
|
||||||
version: link:../packages/providers/storage/chroma
|
version: link:../packages/providers/storage/chroma
|
||||||
'@llamaindex/clip':
|
'@llamaindex/clip':
|
||||||
specifier: ^0.0.44
|
specifier: ^0.0.45
|
||||||
version: link:../packages/providers/clip
|
version: link:../packages/providers/clip
|
||||||
'@llamaindex/cloud':
|
'@llamaindex/cloud':
|
||||||
specifier: ^3.0.9
|
specifier: ^3.0.9
|
||||||
@@ -609,10 +609,10 @@ importers:
|
|||||||
specifier: ^0.5.8
|
specifier: ^0.5.8
|
||||||
version: link:../packages/core
|
version: link:../packages/core
|
||||||
'@llamaindex/deepinfra':
|
'@llamaindex/deepinfra':
|
||||||
specifier: ^0.0.44
|
specifier: ^0.0.45
|
||||||
version: link:../packages/providers/deepinfra
|
version: link:../packages/providers/deepinfra
|
||||||
'@llamaindex/deepseek':
|
'@llamaindex/deepseek':
|
||||||
specifier: ^0.0.4
|
specifier: ^0.0.5
|
||||||
version: link:../packages/providers/deepseek
|
version: link:../packages/providers/deepseek
|
||||||
'@llamaindex/env':
|
'@llamaindex/env':
|
||||||
specifier: ^0.1.29
|
specifier: ^0.1.29
|
||||||
@@ -621,25 +621,25 @@ importers:
|
|||||||
specifier: ^1.0.6
|
specifier: ^1.0.6
|
||||||
version: link:../packages/providers/storage/firestore
|
version: link:../packages/providers/storage/firestore
|
||||||
'@llamaindex/fireworks':
|
'@llamaindex/fireworks':
|
||||||
specifier: ^0.0.4
|
specifier: ^0.0.5
|
||||||
version: link:../packages/providers/fireworks
|
version: link:../packages/providers/fireworks
|
||||||
'@llamaindex/google':
|
'@llamaindex/google':
|
||||||
specifier: ^0.1.1
|
specifier: ^0.1.2
|
||||||
version: link:../packages/providers/google
|
version: link:../packages/providers/google
|
||||||
'@llamaindex/groq':
|
'@llamaindex/groq':
|
||||||
specifier: ^0.0.59
|
specifier: ^0.0.60
|
||||||
version: link:../packages/providers/groq
|
version: link:../packages/providers/groq
|
||||||
'@llamaindex/huggingface':
|
'@llamaindex/huggingface':
|
||||||
specifier: ^0.0.44
|
specifier: ^0.0.45
|
||||||
version: link:../packages/providers/huggingface
|
version: link:../packages/providers/huggingface
|
||||||
'@llamaindex/jinaai':
|
'@llamaindex/jinaai':
|
||||||
specifier: ^0.0.4
|
specifier: ^0.0.5
|
||||||
version: link:../packages/providers/jinaai
|
version: link:../packages/providers/jinaai
|
||||||
'@llamaindex/milvus':
|
'@llamaindex/milvus':
|
||||||
specifier: ^0.1.8
|
specifier: ^0.1.8
|
||||||
version: link:../packages/providers/storage/milvus
|
version: link:../packages/providers/storage/milvus
|
||||||
'@llamaindex/mistral':
|
'@llamaindex/mistral':
|
||||||
specifier: ^0.0.13
|
specifier: ^0.0.14
|
||||||
version: link:../packages/providers/mistral
|
version: link:../packages/providers/mistral
|
||||||
'@llamaindex/mixedbread':
|
'@llamaindex/mixedbread':
|
||||||
specifier: ^0.0.13
|
specifier: ^0.0.13
|
||||||
@@ -654,8 +654,11 @@ importers:
|
|||||||
specifier: ^0.0.48
|
specifier: ^0.0.48
|
||||||
version: link:../packages/providers/ollama
|
version: link:../packages/providers/ollama
|
||||||
'@llamaindex/openai':
|
'@llamaindex/openai':
|
||||||
specifier: ^0.1.60
|
specifier: ^0.1.61
|
||||||
version: link:../packages/providers/openai
|
version: link:../packages/providers/openai
|
||||||
|
'@llamaindex/perplexity':
|
||||||
|
specifier: ^0.0.2
|
||||||
|
version: link:../packages/providers/perplexity
|
||||||
'@llamaindex/pinecone':
|
'@llamaindex/pinecone':
|
||||||
specifier: ^0.0.13
|
specifier: ^0.0.13
|
||||||
version: link:../packages/providers/storage/pinecone
|
version: link:../packages/providers/storage/pinecone
|
||||||
@@ -675,7 +678,7 @@ importers:
|
|||||||
specifier: ^0.0.41
|
specifier: ^0.0.41
|
||||||
version: link:../packages/providers/replicate
|
version: link:../packages/providers/replicate
|
||||||
'@llamaindex/together':
|
'@llamaindex/together':
|
||||||
specifier: ^0.0.4
|
specifier: ^0.0.5
|
||||||
version: link:../packages/providers/together
|
version: link:../packages/providers/together
|
||||||
'@llamaindex/upstash':
|
'@llamaindex/upstash':
|
||||||
specifier: ^0.0.13
|
specifier: ^0.0.13
|
||||||
@@ -684,7 +687,7 @@ importers:
|
|||||||
specifier: ^0.0.19
|
specifier: ^0.0.19
|
||||||
version: link:../packages/providers/vercel
|
version: link:../packages/providers/vercel
|
||||||
'@llamaindex/vllm':
|
'@llamaindex/vllm':
|
||||||
specifier: ^0.0.30
|
specifier: ^0.0.31
|
||||||
version: link:../packages/providers/vllm
|
version: link:../packages/providers/vllm
|
||||||
'@llamaindex/voyage-ai':
|
'@llamaindex/voyage-ai':
|
||||||
specifier: ^1.0.5
|
specifier: ^1.0.5
|
||||||
@@ -720,7 +723,7 @@ importers:
|
|||||||
specifier: ^1.0.14
|
specifier: ^1.0.14
|
||||||
version: 1.0.18
|
version: 1.0.18
|
||||||
llamaindex:
|
llamaindex:
|
||||||
specifier: ^0.9.10
|
specifier: ^0.9.11
|
||||||
version: link:../packages/llamaindex
|
version: link:../packages/llamaindex
|
||||||
mongodb:
|
mongodb:
|
||||||
specifier: 6.7.0
|
specifier: 6.7.0
|
||||||
@@ -1257,8 +1260,8 @@ importers:
|
|||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../../env
|
version: link:../../env
|
||||||
'@mistralai/mistralai':
|
'@mistralai/mistralai':
|
||||||
specifier: ^1.3.4
|
specifier: ^1.5.1
|
||||||
version: 1.5.0(zod@3.24.2)
|
version: 1.5.1(zod@3.24.2)
|
||||||
devDependencies:
|
devDependencies:
|
||||||
bunchee:
|
bunchee:
|
||||||
specifier: 6.4.0
|
specifier: 6.4.0
|
||||||
@@ -1315,6 +1318,22 @@ importers:
|
|||||||
specifier: 6.4.0
|
specifier: 6.4.0
|
||||||
version: 6.4.0(typescript@5.7.3)
|
version: 6.4.0(typescript@5.7.3)
|
||||||
|
|
||||||
|
packages/providers/perplexity:
|
||||||
|
dependencies:
|
||||||
|
'@llamaindex/core':
|
||||||
|
specifier: workspace:*
|
||||||
|
version: link:../../core
|
||||||
|
'@llamaindex/env':
|
||||||
|
specifier: workspace:*
|
||||||
|
version: link:../../env
|
||||||
|
'@llamaindex/openai':
|
||||||
|
specifier: workspace:*
|
||||||
|
version: link:../openai
|
||||||
|
devDependencies:
|
||||||
|
bunchee:
|
||||||
|
specifier: 6.4.0
|
||||||
|
version: 6.4.0(typescript@5.7.3)
|
||||||
|
|
||||||
packages/providers/portkey-ai:
|
packages/providers/portkey-ai:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@llamaindex/core':
|
'@llamaindex/core':
|
||||||
@@ -3484,8 +3503,8 @@ packages:
|
|||||||
'@mdx-js/mdx@3.1.0':
|
'@mdx-js/mdx@3.1.0':
|
||||||
resolution: {integrity: sha512-/QxEhPAvGwbQmy1Px8F899L5Uc2KZ6JtXwlCgJmjSTBedwOZkByYcBG4GceIGPXRDsmfxhHazuS+hlOShRLeDw==}
|
resolution: {integrity: sha512-/QxEhPAvGwbQmy1Px8F899L5Uc2KZ6JtXwlCgJmjSTBedwOZkByYcBG4GceIGPXRDsmfxhHazuS+hlOShRLeDw==}
|
||||||
|
|
||||||
'@mistralai/mistralai@1.5.0':
|
'@mistralai/mistralai@1.5.1':
|
||||||
resolution: {integrity: sha512-AIn8pwAwA/fDvEUvmkt+40zH1ZmfaG3Q7oUWl17GUEC1tU7ZPwYz8Cv9P59lyS1SisHdDSu81oknO7f1ywkz8Q==}
|
resolution: {integrity: sha512-Ie0EH4dAO11MEXR5N2kS2cgr+ycTWvqN/yP9bKrtmUEqjdcF4i7DLxtrFMUw5l2dOPhrkX93G4SziFiATPWu2w==}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
zod: '>= 3'
|
zod: '>= 3'
|
||||||
|
|
||||||
@@ -14273,7 +14292,7 @@ snapshots:
|
|||||||
- acorn
|
- acorn
|
||||||
- supports-color
|
- supports-color
|
||||||
|
|
||||||
'@mistralai/mistralai@1.5.0(zod@3.24.2)':
|
'@mistralai/mistralai@1.5.1(zod@3.24.2)':
|
||||||
dependencies:
|
dependencies:
|
||||||
zod: 3.24.2
|
zod: 3.24.2
|
||||||
zod-to-json-schema: 3.24.1(zod@3.24.2)
|
zod-to-json-schema: 3.24.1(zod@3.24.2)
|
||||||
|
|||||||
@@ -187,6 +187,9 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "./packages/providers/jinaai/tsconfig.json"
|
"path": "./packages/providers/jinaai/tsconfig.json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "./packages/providers/perplexity/tsconfig.json"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
# @llamaindex/unit-test
|
# @llamaindex/unit-test
|
||||||
|
|
||||||
|
## 0.1.11
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [a8c0637]
|
||||||
|
- @llamaindex/openai@0.1.61
|
||||||
|
- llamaindex@0.9.11
|
||||||
|
|
||||||
## 0.1.10
|
## 0.1.10
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/unit-test",
|
"name": "@llamaindex/unit-test",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.1.10",
|
"version": "0.1.11",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "vitest run"
|
"test": "vitest run"
|
||||||
|
|||||||
Reference in New Issue
Block a user