mirror of
https://github.com/run-llama/LlamaIndexTS.git
synced 2026-07-16 07:14:29 -04:00
Compare commits
98 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c1578a19d9 | |||
| ae49ff4e15 | |||
| a75af835a5 | |||
| 7c7cd34908 | |||
| f651891196 | |||
| 04714c886f | |||
| cf28574f51 | |||
| 24d065f054 | |||
| b8719586e3 | |||
| 07a40aca49 | |||
| 33b562938d | |||
| 723b41c23c | |||
| 4c38c1be0b | |||
| 0dde0ca27f | |||
| f3e0d07f48 | |||
| 1364e8eeed | |||
| 96fc69cc61 | |||
| 3b7736f763 | |||
| a7a7afe66e | |||
| c646ee2eca | |||
| 5729bd92fd | |||
| e0e52cf879 | |||
| 6f75306c17 | |||
| 94cb4ad810 | |||
| 1ea4014746 | |||
| 6a9a7b1458 | |||
| 1c168cd531 | |||
| 62cba5236d | |||
| d265e96420 | |||
| d30bbf799f | |||
| 53fd00a7c3 | |||
| 83f2848d47 | |||
| 313071e9cd | |||
| 5f6782038a | |||
| fe08d0451b | |||
| 59c5e5c3d4 | |||
| ee697fb1b3 | |||
| cf3320a4ea | |||
| f2ed69f2f8 | |||
| 3489e7de84 | |||
| 468bda594e | |||
| 6f3a31caf6 | |||
| 63e9846e97 | |||
| b7382b0d24 | |||
| 2a8241328d | |||
| 0b20ff9f17 | |||
| 1fc26046e3 | |||
| b17d439d6d | |||
| 040160c360 | |||
| 981811efd1 | |||
| d563b45a27 | |||
| 2774e80234 | |||
| 449274ca5a | |||
| 78037a664c | |||
| 1d9e3b1000 | |||
| df83e32107 | |||
| f7b4e94231 | |||
| 4c07a2655d | |||
| 5c0c8b2ec4 | |||
| e5e18688a6 | |||
| b6fb10eba8 | |||
| df441e28f4 | |||
| a4e05ec7ab | |||
| 96f72ad86e | |||
| f3556c011c | |||
| ebc510582b | |||
| f3bfdc29e3 | |||
| 6cce3b12ea | |||
| 0273e9739a | |||
| 7c8b883448 | |||
| c2bb418542 | |||
| ed6acbead0 | |||
| 976cce40d7 | |||
| e4fd4158bb | |||
| 31d5dffcef | |||
| d12edee802 | |||
| ac41ed3aae | |||
| d8c1159032 | |||
| c856c5becb | |||
| 50e6b57be0 | |||
| 8b7fdba544 | |||
| 22ae8d0166 | |||
| 23bcc379a8 | |||
| bdc4bfe7b0 | |||
| 025ffe6b50 | |||
| a6595747fa | |||
| d902cc3e7e | |||
| 726eb41359 | |||
| e9714dbfcd | |||
| a3618e761e | |||
| 24eabe7f35 | |||
| ecfa939ea6 | |||
| b48bcc3add | |||
| fa01fa2051 | |||
| fb36eff5e1 | |||
| d24d3d1e8c | |||
| 5c4badbcca | |||
| 2cd1383dc8 |
@@ -25,4 +25,4 @@ jobs:
|
|||||||
run: pnpm run build
|
run: pnpm run build
|
||||||
|
|
||||||
- name: Pre Release
|
- name: Pre Release
|
||||||
run: pnpx pkg-pr-new publish ./packages/*
|
run: pnpx pkg-pr-new publish ./packages/* ./packages/providers/*
|
||||||
|
|||||||
+31
-26
@@ -13,8 +13,10 @@ concurrency:
|
|||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|
||||||
env:
|
env:
|
||||||
POSTGRES_USER: runneradmin
|
|
||||||
POSTGRES_HOST_AUTH_METHOD: trust
|
POSTGRES_HOST_AUTH_METHOD: trust
|
||||||
|
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
|
||||||
|
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
|
||||||
|
TURBO_REMOTE_ONLY: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
e2e:
|
e2e:
|
||||||
@@ -87,13 +89,7 @@ jobs:
|
|||||||
- name: Run Type Check
|
- name: Run Type Check
|
||||||
run: pnpm run type-check
|
run: pnpm run type-check
|
||||||
- name: Run Circular Dependency Check
|
- name: Run Circular Dependency Check
|
||||||
run: pnpm dlx turbo run circular-check
|
run: pnpm run circular-check
|
||||||
- uses: actions/upload-artifact@v3
|
|
||||||
if: failure()
|
|
||||||
with:
|
|
||||||
name: typecheck-build-dist
|
|
||||||
path: ./packages/llamaindex/dist
|
|
||||||
if-no-files-found: error
|
|
||||||
e2e-llamaindex-examples:
|
e2e-llamaindex-examples:
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
@@ -140,27 +136,36 @@ jobs:
|
|||||||
run: pnpm run build
|
run: pnpm run build
|
||||||
- name: Copy examples
|
- name: Copy examples
|
||||||
run: rsync -rv --exclude=node_modules ./examples ${{ runner.temp }}
|
run: rsync -rv --exclude=node_modules ./examples ${{ runner.temp }}
|
||||||
- name: Pack @llamaindex/cloud
|
- name: Pack packages
|
||||||
run: pnpm pack --pack-destination ${{ runner.temp }}
|
run: |
|
||||||
working-directory: packages/cloud
|
for dir in packages/*; do
|
||||||
- name: Pack @llamaindex/openai
|
if [ -d "$dir" ] && [ -f "$dir/package.json" ] && [[ ! "$dir" =~ autotool ]]; then
|
||||||
run: pnpm pack --pack-destination ${{ runner.temp }}
|
echo "Packing $dir"
|
||||||
working-directory: packages/llm/openai
|
pnpm pack --pack-destination ${{ runner.temp }} -C $dir
|
||||||
- name: Pack @llamaindex/groq
|
else
|
||||||
run: pnpm pack --pack-destination ${{ runner.temp }}
|
echo "Skipping $dir, no package.json found"
|
||||||
working-directory: packages/llm/groq
|
fi
|
||||||
- name: Pack @llamaindex/core
|
done
|
||||||
run: pnpm pack --pack-destination ${{ runner.temp }}
|
- name: Pack provider packages
|
||||||
working-directory: packages/core
|
run: |
|
||||||
- name: Pack @llamaindex/env
|
for dir in packages/providers/*; do
|
||||||
run: pnpm pack --pack-destination ${{ runner.temp }}
|
if [ -d "$dir" ] && [ -f "$dir/package.json" ]; then
|
||||||
working-directory: packages/env
|
echo "Packing $dir"
|
||||||
- name: Pack llamaindex
|
pnpm pack --pack-destination ${{ runner.temp }} -C $dir
|
||||||
run: pnpm pack --pack-destination ${{ runner.temp }}
|
else
|
||||||
working-directory: packages/llamaindex
|
echo "Skipping $dir, no package.json found"
|
||||||
|
fi
|
||||||
|
done
|
||||||
- name: Install
|
- name: Install
|
||||||
run: npm add ${{ runner.temp }}/*.tgz
|
run: npm add ${{ runner.temp }}/*.tgz
|
||||||
working-directory: ${{ runner.temp }}/examples
|
working-directory: ${{ runner.temp }}/examples
|
||||||
- name: Run Type Check
|
- name: Run Type Check
|
||||||
run: npx tsc --project ./tsconfig.json
|
run: npx tsc --project ./tsconfig.json
|
||||||
working-directory: ${{ runner.temp }}/examples
|
working-directory: ${{ runner.temp }}/examples
|
||||||
|
- uses: actions/upload-artifact@v4
|
||||||
|
if: failure()
|
||||||
|
with:
|
||||||
|
name: build-dist
|
||||||
|
path: |
|
||||||
|
${{ runner.temp }}/*.tgz
|
||||||
|
if-no-files-found: error
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
LlamaIndex is a data framework for your LLM application.
|
LlamaIndex is a data framework for your LLM application.
|
||||||
|
|
||||||
Use your own data with large language models (LLMs, OpenAI ChatGPT and others) in Typescript and Javascript.
|
Use your own data with large language models (LLMs, OpenAI ChatGPT and others) in JS runtime environments with TypeScript support.
|
||||||
|
|
||||||
Documentation: https://ts.llamaindex.ai/
|
Documentation: https://ts.llamaindex.ai/
|
||||||
|
|
||||||
@@ -19,17 +19,36 @@ Try examples online:
|
|||||||
|
|
||||||
LlamaIndex.TS aims to be a lightweight, easy to use set of libraries to help you integrate large language models into your applications with your own data.
|
LlamaIndex.TS aims to be a lightweight, easy to use set of libraries to help you integrate large language models into your applications with your own data.
|
||||||
|
|
||||||
## Multiple JS Environment Support
|
## Compatibility
|
||||||
|
|
||||||
|
### Multiple JS Environment Support
|
||||||
|
|
||||||
LlamaIndex.TS supports multiple JS environments, including:
|
LlamaIndex.TS supports multiple JS environments, including:
|
||||||
|
|
||||||
- Node.js (18, 20, 22) ✅
|
- Node.js (18, 20, 22) ✅
|
||||||
- Deno ✅
|
- Deno ✅
|
||||||
- Bun ✅
|
- Bun ✅
|
||||||
- React Server Components (Next.js) ✅
|
- Nitro ✅
|
||||||
|
- Vercel Edge Runtime ✅ (with some limitations)
|
||||||
|
- Cloudflare Workers ✅ (with some limitations)
|
||||||
|
|
||||||
For now, browser support is limited due to the lack of support for [AsyncLocalStorage-like APIs](https://github.com/tc39/proposal-async-context)
|
For now, browser support is limited due to the lack of support for [AsyncLocalStorage-like APIs](https://github.com/tc39/proposal-async-context)
|
||||||
|
|
||||||
|
### Supported LLMs:
|
||||||
|
|
||||||
|
- OpenAI LLms
|
||||||
|
- Anthropic LLms
|
||||||
|
- Groq LLMs
|
||||||
|
- Llama2, Llama3, Llama3.1 LLMs
|
||||||
|
- MistralAI LLMs
|
||||||
|
- Fireworks LLMs
|
||||||
|
- DeepSeek LLMs
|
||||||
|
- ReplicateAI LLMs
|
||||||
|
- TogetherAI LLMs
|
||||||
|
- HuggingFace LLms
|
||||||
|
- DeepInfra LLMs
|
||||||
|
- Gemini LLMs
|
||||||
|
|
||||||
## Getting started
|
## Getting started
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
@@ -77,7 +96,7 @@ See more about [moduleResolution](https://www.typescriptlang.org/docs/handbook/m
|
|||||||
### Node.js
|
### Node.js
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
import fs from "fs/promises";
|
import fs from "node:fs/promises";
|
||||||
import { Document, VectorStoreIndex } from "llamaindex";
|
import { Document, VectorStoreIndex } from "llamaindex";
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
@@ -111,9 +130,9 @@ main();
|
|||||||
node --import tsx ./main.ts
|
node --import tsx ./main.ts
|
||||||
```
|
```
|
||||||
|
|
||||||
### React Server Component (Next.js, Waku, Redwood.JS...)
|
### Next.js
|
||||||
|
|
||||||
First, you will need to add a llamaindex plugin to your Next.js project.
|
You will need to add a llamaindex plugin to your Next.js project.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// next.config.js
|
// next.config.js
|
||||||
@@ -124,20 +143,18 @@ module.exports = withLlamaIndex({
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
You can combine `ai` with `llamaindex` in Next.js with RSC (React Server Components).
|
### React Server Actions
|
||||||
|
|
||||||
|
You can combine `ai` with `llamaindex` in Next.js, Waku or Redwood.js with RSC (React Server Components).
|
||||||
|
|
||||||
```tsx
|
```tsx
|
||||||
// src/apps/page.tsx
|
|
||||||
"use client";
|
"use client";
|
||||||
import { chatWithAgent } from "@/actions";
|
import { chatWithAgent } from "@/actions";
|
||||||
import type { JSX } from "react";
|
import type { JSX } from "react";
|
||||||
import { useFormState } from "react-dom";
|
import { useActionState } from "react";
|
||||||
|
|
||||||
// You can use the Edge runtime in Next.js by adding this line:
|
|
||||||
// export const runtime = "edge";
|
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
const [ui, action] = useFormState<JSX.Element | null>(async () => {
|
const [ui, action] = useActionState<JSX.Element | null>(async () => {
|
||||||
return chatWithAgent("hello!", []);
|
return chatWithAgent("hello!", []);
|
||||||
}, null);
|
}, null);
|
||||||
return (
|
return (
|
||||||
@@ -167,11 +184,13 @@ export async function chatWithAgent(
|
|||||||
// ... adding your tools here
|
// ... adding your tools here
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
const responseStream = await agent.chat({
|
const responseStream = await agent.chat(
|
||||||
stream: true,
|
{
|
||||||
message: question,
|
message: question,
|
||||||
chatHistory: prevMessages,
|
chatHistory: prevMessages,
|
||||||
});
|
},
|
||||||
|
true,
|
||||||
|
);
|
||||||
const uiStream = createStreamableUI(<div>loading...</div>);
|
const uiStream = createStreamableUI(<div>loading...</div>);
|
||||||
responseStream
|
responseStream
|
||||||
.pipeTo(
|
.pipeTo(
|
||||||
@@ -189,6 +208,48 @@ export async function chatWithAgent(
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Cloudflare Workers
|
||||||
|
|
||||||
|
> [!TIP]
|
||||||
|
> Some modules are not supported in Cloudflare Workers which require Node.js APIs.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// add `OPENAI_API_KEY` to the `.dev.vars` file
|
||||||
|
interface Env {
|
||||||
|
OPENAI_API_KEY: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
async fetch(
|
||||||
|
request: Request,
|
||||||
|
env: Env,
|
||||||
|
ctx: ExecutionContext,
|
||||||
|
): Promise<Response> {
|
||||||
|
const { OpenAIAgent, OpenAI } = await import("@llamaindex/openai");
|
||||||
|
const text = await request.text();
|
||||||
|
const agent = new OpenAIAgent({
|
||||||
|
llm: new OpenAI({
|
||||||
|
apiKey: env.OPENAI_API_KEY,
|
||||||
|
}),
|
||||||
|
tools: [],
|
||||||
|
});
|
||||||
|
const responseStream = await agent.chat({
|
||||||
|
stream: true,
|
||||||
|
message: text,
|
||||||
|
});
|
||||||
|
const textEncoder = new TextEncoder();
|
||||||
|
const response = responseStream.pipeThrough<Uint8Array>(
|
||||||
|
new TransformStream({
|
||||||
|
transform: (chunk, controller) => {
|
||||||
|
controller.enqueue(textEncoder.encode(chunk.delta));
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
return new Response(response);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
### Vite
|
### Vite
|
||||||
|
|
||||||
We have some wasm dependencies for better performance. You can use `vite-plugin-wasm` to load them.
|
We have some wasm dependencies for better performance. You can use `vite-plugin-wasm` to load them.
|
||||||
@@ -204,29 +265,9 @@ export default {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
## Playground
|
### Tips when using in non-Node.js environments
|
||||||
|
|
||||||
Check out our NextJS playground at https://llama-playground.vercel.app/. The source is available at https://github.com/run-llama/ts-playground
|
When you are importing `llamaindex` in a non-Node.js environment(such as Vercel Edge, Cloudflare Workers, etc.)
|
||||||
|
|
||||||
## Core concepts for getting started:
|
|
||||||
|
|
||||||
- [Document](/packages/llamaindex/src/Node.ts): A document represents a text file, PDF file or other contiguous piece of data.
|
|
||||||
|
|
||||||
- [Node](/packages/llamaindex/src/Node.ts): The basic data building block. Most commonly, these are parts of the document split into manageable pieces that are small enough to be fed into an embedding model and LLM.
|
|
||||||
|
|
||||||
- [Embedding](/packages/llamaindex/src/embeddings/OpenAIEmbedding.ts): Embeddings are sets of floating point numbers which represent the data in a Node. By comparing the similarity of embeddings, we can derive an understanding of the similarity of two pieces of data. One use case is to compare the embedding of a question with the embeddings of our Nodes to see which Nodes may contain the data needed to answer that question. Because the default service context is OpenAI, the default embedding is `OpenAIEmbedding`. If using different models, say through Ollama, use this [Embedding](/packages/llamaindex/src/embeddings/OllamaEmbedding.ts) (see all [here](/packages/llamaindex/src/embeddings)).
|
|
||||||
|
|
||||||
- [Indices](/packages/llamaindex/src/indices/): Indices store the Nodes and the embeddings of those nodes. QueryEngines retrieve Nodes from these Indices using embedding similarity.
|
|
||||||
|
|
||||||
- [QueryEngine](/packages/llamaindex/src/engines/query/RetrieverQueryEngine.ts): Query engines are what generate the query you put in and give you back the result. Query engines generally combine a pre-built prompt with selected Nodes from your Index to give the LLM the context it needs to answer your query. To build a query engine from your Index (recommended), use the [`asQueryEngine`](/packages/llamaindex/src/indices/BaseIndex.ts) method on your Index. See all query engines [here](/packages/llamaindex/src/engines/query).
|
|
||||||
|
|
||||||
- [ChatEngine](/packages/llamaindex/src/engines/chat/SimpleChatEngine.ts): A ChatEngine helps you build a chatbot that will interact with your Indices. See all chat engines [here](/packages/llamaindex/src/engines/chat).
|
|
||||||
|
|
||||||
- [SimplePrompt](/packages/llamaindex/src/Prompt.ts): A simple standardized function call definition that takes in inputs and formats them in a template literal. SimplePrompts can be specialized using currying and combined using other SimplePrompt functions.
|
|
||||||
|
|
||||||
## Tips when using in non-Node.js environments
|
|
||||||
|
|
||||||
When you are importing `llamaindex` in a non-Node.js environment(such as React Server Components, Cloudflare Workers, etc.)
|
|
||||||
Some classes are not exported from top-level entry file.
|
Some classes are not exported from top-level entry file.
|
||||||
|
|
||||||
The reason is that some classes are only compatible with Node.js runtime,(e.g. `PDFReader`) which uses Node.js specific APIs(like `fs`, `child_process`, `crypto`).
|
The reason is that some classes are only compatible with Node.js runtime,(e.g. `PDFReader`) which uses Node.js specific APIs(like `fs`, `child_process`, `crypto`).
|
||||||
@@ -262,19 +303,31 @@ export async function getDocuments() {
|
|||||||
|
|
||||||
You'll find a complete example with LlamaIndexTS here: https://github.com/run-llama/create_llama_projects/tree/main/nextjs-edge-llamaparse
|
You'll find a complete example with LlamaIndexTS here: https://github.com/run-llama/create_llama_projects/tree/main/nextjs-edge-llamaparse
|
||||||
|
|
||||||
## Supported LLMs:
|
## Playground
|
||||||
|
|
||||||
- OpenAI GPT-3.5-turbo and GPT-4
|
Check out our NextJS playground at https://llama-playground.vercel.app/. The source is available at https://github.com/run-llama/ts-playground
|
||||||
- Anthropic Claude 3 (Opus, Sonnet, and Haiku) and the legacy models (Claude 2 and Instant)
|
|
||||||
- Groq LLMs
|
## Core concepts for getting started:
|
||||||
- Llama2/3 Chat LLMs (70B, 13B, and 7B parameters)
|
|
||||||
- MistralAI Chat LLMs
|
- [Document](/packages/llamaindex/src/Node.ts): A document represents a text file, PDF file or other contiguous piece of data.
|
||||||
- Fireworks Chat LLMs
|
|
||||||
|
- [Node](/packages/llamaindex/src/Node.ts): The basic data building block. Most commonly, these are parts of the document split into manageable pieces that are small enough to be fed into an embedding model and LLM.
|
||||||
|
|
||||||
|
- [Embedding](/packages/llamaindex/src/embeddings/OpenAIEmbedding.ts): Embeddings are sets of floating point numbers which represent the data in a Node. By comparing the similarity of embeddings, we can derive an understanding of the similarity of two pieces of data. One use case is to compare the embedding of a question with the embeddings of our Nodes to see which Nodes may contain the data needed to answer that question. Because the default service context is OpenAI, the default embedding is `OpenAIEmbedding`. If using different models, say through Ollama, use this [Embedding](/packages/llamaindex/src/embeddings/OllamaEmbedding.ts) (see all [here](/packages/llamaindex/src/embeddings)).
|
||||||
|
|
||||||
|
- [Indices](/packages/llamaindex/src/indices/): Indices store the Nodes and the embeddings of those nodes. QueryEngines retrieve Nodes from these Indices using embedding similarity.
|
||||||
|
|
||||||
|
- [QueryEngine](/packages/llamaindex/src/engines/query/RetrieverQueryEngine.ts): Query engines are what generate the query you put in and give you back the result. Query engines generally combine a pre-built prompt with selected Nodes from your Index to give the LLM the context it needs to answer your query. To build a query engine from your Index (recommended), use the [`asQueryEngine`](/packages/llamaindex/src/indices/BaseIndex.ts) method on your Index. See all query engines [here](/packages/llamaindex/src/engines/query).
|
||||||
|
|
||||||
|
- [ChatEngine](/packages/llamaindex/src/engines/chat/SimpleChatEngine.ts): A ChatEngine helps you build a chatbot that will interact with your Indices. See all chat engines [here](/packages/llamaindex/src/engines/chat).
|
||||||
|
|
||||||
|
- [SimplePrompt](/packages/llamaindex/src/Prompt.ts): A simple standardized function call definition that takes in inputs and formats them in a template literal. SimplePrompts can be specialized using currying and combined using other SimplePrompt functions.
|
||||||
|
|
||||||
## Contributing:
|
## Contributing:
|
||||||
|
|
||||||
We are in the very early days of LlamaIndex.TS. If you’re interested in hacking on it with us check out our [contributing guide](/CONTRIBUTING.md)
|
Please see our [contributing guide](CONTRIBUTING.md) for more information.
|
||||||
|
You are highly encouraged to contribute to LlamaIndex.TS!
|
||||||
|
|
||||||
## Bugs? Questions?
|
## Community
|
||||||
|
|
||||||
Please join our Discord! https://discord.com/invite/eN6D2HQ4aX
|
Please join our Discord! https://discord.com/invite/eN6D2HQ4aX
|
||||||
|
|||||||
@@ -1,5 +1,174 @@
|
|||||||
# docs
|
# docs
|
||||||
|
|
||||||
|
## 0.0.93
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [ae49ff4]
|
||||||
|
- Updated dependencies [4c38c1b]
|
||||||
|
- Updated dependencies [a75af83]
|
||||||
|
- Updated dependencies [a75af83]
|
||||||
|
- llamaindex@0.7.1
|
||||||
|
|
||||||
|
## 0.0.92
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [1364e8e]
|
||||||
|
- Updated dependencies [3b7736f]
|
||||||
|
- Updated dependencies [96fc69c]
|
||||||
|
- llamaindex@0.7.0
|
||||||
|
- @llamaindex/examples@0.0.9
|
||||||
|
|
||||||
|
## 0.0.91
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [5729bd9]
|
||||||
|
- llamaindex@0.6.22
|
||||||
|
|
||||||
|
## 0.0.90
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [6f75306]
|
||||||
|
- Updated dependencies [94cb4ad]
|
||||||
|
- llamaindex@0.6.21
|
||||||
|
|
||||||
|
## 0.0.89
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [6a9a7b1]
|
||||||
|
- llamaindex@0.6.20
|
||||||
|
|
||||||
|
## 0.0.88
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [62cba52]
|
||||||
|
- Updated dependencies [d265e96]
|
||||||
|
- Updated dependencies [d30bbf7]
|
||||||
|
- Updated dependencies [53fd00a]
|
||||||
|
- llamaindex@0.6.19
|
||||||
|
|
||||||
|
## 0.0.87
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [5f67820]
|
||||||
|
- Updated dependencies [fe08d04]
|
||||||
|
- llamaindex@0.6.18
|
||||||
|
|
||||||
|
## 0.0.86
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [ee697fb]
|
||||||
|
- llamaindex@0.6.17
|
||||||
|
|
||||||
|
## 0.0.85
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [63e9846]
|
||||||
|
- Updated dependencies [6f3a31c]
|
||||||
|
- llamaindex@0.6.16
|
||||||
|
|
||||||
|
## 0.0.84
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [2a82413]
|
||||||
|
- llamaindex@0.6.15
|
||||||
|
|
||||||
|
## 0.0.83
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- llamaindex@0.6.14
|
||||||
|
|
||||||
|
## 0.0.82
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- llamaindex@0.6.13
|
||||||
|
|
||||||
|
## 0.0.81
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [f7b4e94]
|
||||||
|
- Updated dependencies [78037a6]
|
||||||
|
- Updated dependencies [1d9e3b1]
|
||||||
|
- llamaindex@0.6.12
|
||||||
|
|
||||||
|
## 0.0.80
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [df441e2]
|
||||||
|
- llamaindex@0.6.11
|
||||||
|
|
||||||
|
## 0.0.79
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [ebc5105]
|
||||||
|
- Updated dependencies [6cce3b1]
|
||||||
|
- llamaindex@0.6.10
|
||||||
|
|
||||||
|
## 0.0.78
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- llamaindex@0.6.9
|
||||||
|
|
||||||
|
## 0.0.77
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [8b7fdba]
|
||||||
|
- llamaindex@0.6.8
|
||||||
|
|
||||||
|
## 0.0.76
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [23bcc37]
|
||||||
|
- llamaindex@0.6.7
|
||||||
|
|
||||||
|
## 0.0.75
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [d902cc3]
|
||||||
|
- Updated dependencies [025ffe6]
|
||||||
|
- Updated dependencies [a659574]
|
||||||
|
- llamaindex@0.6.6
|
||||||
|
|
||||||
|
## 0.0.74
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [e9714db]
|
||||||
|
- llamaindex@0.6.5
|
||||||
|
|
||||||
|
## 0.0.73
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [b48bcc3]
|
||||||
|
- llamaindex@0.6.4
|
||||||
|
|
||||||
|
## 0.0.72
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [2cd1383]
|
||||||
|
- Updated dependencies [5c4badb]
|
||||||
|
- llamaindex@0.6.3
|
||||||
|
|
||||||
## 0.0.71
|
## 0.0.71
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ Official documentation for LlamaParse can be found [here](https://docs.cloud.lla
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
You can then use the `LlamaParseReader` class to load local files and convert them into a parsed document that can be used by LlamaIndex.
|
You can then use the `LlamaParseReader` class to load local files and convert them into a parsed document that can be used by LlamaIndex.
|
||||||
See [LlamaParseReader.ts](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/llamaindex/src/readers/LlamaParseReader.ts) for a list of supported file types:
|
See [reader.ts](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/cloud/src/reader.ts) for a list of supported file types:
|
||||||
|
|
||||||
<CodeBlock language="ts">{CodeSource}</CodeBlock>
|
<CodeBlock language="ts">{CodeSource}</CodeBlock>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "docs",
|
"name": "docs",
|
||||||
"version": "0.0.71",
|
"version": "0.0.93",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"docusaurus": "docusaurus",
|
"docusaurus": "docusaurus",
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"extends": ["//"],
|
||||||
|
"tasks": {
|
||||||
|
"build": {
|
||||||
|
"outputs": ["build/**", ".docusaurus/**"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,16 @@
|
|||||||
# examples
|
# examples
|
||||||
|
|
||||||
|
## 0.0.9
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [1364e8e]
|
||||||
|
- Updated dependencies [96fc69c]
|
||||||
|
- Updated dependencies [3b7736f]
|
||||||
|
- Updated dependencies [96fc69c]
|
||||||
|
- llamaindex@0.7.0
|
||||||
|
- @llamaindex/core@0.3.0
|
||||||
|
|
||||||
## 0.0.8
|
## 0.0.8
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import { FunctionTool, OpenAI, ToolCallOptions } from "llamaindex";
|
|||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
async function callLLM(init: Partial<OpenAI>) {
|
async function callLLM(init: { model: string }) {
|
||||||
const csvData =
|
const csvData =
|
||||||
"Country,Average Height (cm)\nNetherlands,156\nDenmark,158\nNorway,160";
|
"Country,Average Height (cm)\nNetherlands,156\nDenmark,158\nNorway,160";
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import readline from "node:readline/promises";
|
|||||||
});
|
});
|
||||||
const chatEngine = new SimpleChatEngine({
|
const chatEngine = new SimpleChatEngine({
|
||||||
llm,
|
llm,
|
||||||
chatHistory,
|
memory: chatHistory,
|
||||||
});
|
});
|
||||||
const rl = readline.createInterface({ input, output });
|
const rl = readline.createInterface({ input, output });
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
AstraDBVectorStore,
|
AstraDBVectorStore,
|
||||||
Document,
|
Document,
|
||||||
|
MetadataFilters,
|
||||||
storageContextFromDefaults,
|
storageContextFromDefaults,
|
||||||
VectorStoreIndex,
|
VectorStoreIndex,
|
||||||
} from "llamaindex";
|
} from "llamaindex";
|
||||||
@@ -42,8 +43,10 @@ async function main() {
|
|||||||
const index = await VectorStoreIndex.fromDocuments(docs, {
|
const index = await VectorStoreIndex.fromDocuments(docs, {
|
||||||
storageContext: ctx,
|
storageContext: ctx,
|
||||||
});
|
});
|
||||||
|
const preFilters: MetadataFilters = {
|
||||||
const queryEngine = index.asQueryEngine();
|
filters: [{ key: "id", operator: "in", value: [123, 789] }],
|
||||||
|
}; // try changing the filters to see the different results
|
||||||
|
const queryEngine = index.asQueryEngine({ preFilters });
|
||||||
const response = await queryEngine.query({
|
const response = await queryEngine.query({
|
||||||
query: "Describe AstraDB.",
|
query: "Describe AstraDB.",
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,57 +1,83 @@
|
|||||||
import {
|
import {
|
||||||
ChromaVectorStore,
|
ChromaVectorStore,
|
||||||
Document,
|
Document,
|
||||||
|
MetadataFilters,
|
||||||
VectorStoreIndex,
|
VectorStoreIndex,
|
||||||
storageContextFromDefaults,
|
storageContextFromDefaults,
|
||||||
} from "llamaindex";
|
} from "llamaindex";
|
||||||
|
|
||||||
const collectionName = "dog_colors";
|
const collectionName = "dogs_with_color";
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
try {
|
try {
|
||||||
const docs = [
|
|
||||||
new Document({
|
|
||||||
text: "The dog is brown",
|
|
||||||
metadata: {
|
|
||||||
dogId: "1",
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
new Document({
|
|
||||||
text: "The dog is red",
|
|
||||||
metadata: {
|
|
||||||
dogId: "2",
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
];
|
|
||||||
|
|
||||||
console.log("Creating ChromaDB vector store");
|
|
||||||
const chromaVS = new ChromaVectorStore({ collectionName });
|
const chromaVS = new ChromaVectorStore({ collectionName });
|
||||||
const ctx = await storageContextFromDefaults({ vectorStore: chromaVS });
|
const index = await VectorStoreIndex.fromVectorStore(chromaVS);
|
||||||
|
|
||||||
console.log("Embedding documents and adding to index");
|
const queryFn = async (filters?: MetadataFilters) => {
|
||||||
const index = await VectorStoreIndex.fromDocuments(docs, {
|
console.log("\nQuerying dogs by filters: ", JSON.stringify(filters));
|
||||||
storageContext: ctx,
|
const query = "List all colors of dogs";
|
||||||
});
|
const queryEngine = index.asQueryEngine({
|
||||||
|
preFilters: filters,
|
||||||
|
similarityTopK: 3,
|
||||||
|
});
|
||||||
|
const response = await queryEngine.query({ query });
|
||||||
|
console.log(response.toString());
|
||||||
|
};
|
||||||
|
|
||||||
console.log("Querying index");
|
await queryFn(); // red, brown, yellow
|
||||||
const queryEngine = index.asQueryEngine({
|
await queryFn({ filters: [{ key: "dogId", value: "1", operator: "==" }] }); // brown
|
||||||
preFilters: {
|
await queryFn({ filters: [{ key: "dogId", value: "1", operator: "!=" }] }); // red, yellow
|
||||||
filters: [
|
await queryFn({
|
||||||
{
|
filters: [
|
||||||
key: "dogId",
|
{ key: "dogId", value: "1", operator: "==" },
|
||||||
value: "2",
|
{ key: "dogId", value: "3", operator: "==" },
|
||||||
operator: "==",
|
],
|
||||||
},
|
condition: "or",
|
||||||
],
|
}); // brown, yellow
|
||||||
},
|
await queryFn({
|
||||||
});
|
filters: [{ key: "dogId", value: ["1", "2"], operator: "in" }],
|
||||||
const response = await queryEngine.query({
|
}); // red, brown
|
||||||
query: "What is the color of the dog?",
|
|
||||||
});
|
|
||||||
console.log(response.toString());
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void main();
|
async function generate() {
|
||||||
|
const docs = [
|
||||||
|
new Document({
|
||||||
|
id_: "doc1",
|
||||||
|
text: "The dog is brown",
|
||||||
|
metadata: {
|
||||||
|
dogId: "1",
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Document({
|
||||||
|
id_: "doc2",
|
||||||
|
text: "The dog is red",
|
||||||
|
metadata: {
|
||||||
|
dogId: "2",
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Document({
|
||||||
|
id_: "doc3",
|
||||||
|
text: "The dog is yellow",
|
||||||
|
metadata: {
|
||||||
|
dogId: "3",
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
|
||||||
|
console.log("Creating ChromaDB vector store");
|
||||||
|
const chromaVS = new ChromaVectorStore({ collectionName });
|
||||||
|
const ctx = await storageContextFromDefaults({ vectorStore: chromaVS });
|
||||||
|
|
||||||
|
console.log("Embedding documents and adding to index");
|
||||||
|
await VectorStoreIndex.fromDocuments(docs, {
|
||||||
|
storageContext: ctx,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
await generate();
|
||||||
|
await main();
|
||||||
|
})();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
Document,
|
Document,
|
||||||
|
getResponseSynthesizer,
|
||||||
NodeWithScore,
|
NodeWithScore,
|
||||||
ResponseSynthesizer,
|
|
||||||
SentenceSplitter,
|
SentenceSplitter,
|
||||||
TextNode,
|
TextNode,
|
||||||
} from "llamaindex";
|
} from "llamaindex";
|
||||||
@@ -14,7 +14,7 @@ import {
|
|||||||
|
|
||||||
console.log(nodes);
|
console.log(nodes);
|
||||||
|
|
||||||
const responseSynthesizer = new ResponseSynthesizer();
|
const responseSynthesizer = getResponseSynthesizer("compact");
|
||||||
|
|
||||||
const nodesWithScore: NodeWithScore[] = [
|
const nodesWithScore: NodeWithScore[] = [
|
||||||
{
|
{
|
||||||
@@ -30,7 +30,7 @@ import {
|
|||||||
const stream = await responseSynthesizer.synthesize(
|
const stream = await responseSynthesizer.synthesize(
|
||||||
{
|
{
|
||||||
query: "What age am I?",
|
query: "What age am I?",
|
||||||
nodesWithScore,
|
nodes: nodesWithScore,
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
import {
|
||||||
|
Document,
|
||||||
|
MetadataFilters,
|
||||||
|
Settings,
|
||||||
|
SimpleDocumentStore,
|
||||||
|
VectorStoreIndex,
|
||||||
|
storageContextFromDefaults,
|
||||||
|
} from "llamaindex";
|
||||||
|
|
||||||
|
async function getDataSource() {
|
||||||
|
const docs = [
|
||||||
|
new Document({ text: "The dog is brown", metadata: { dogId: "1" } }),
|
||||||
|
new Document({ text: "The dog is yellow", metadata: { dogId: "2" } }),
|
||||||
|
];
|
||||||
|
const storageContext = await storageContextFromDefaults({
|
||||||
|
persistDir: "./cache",
|
||||||
|
});
|
||||||
|
const numberOfDocs = Object.keys(
|
||||||
|
(storageContext.docStore as SimpleDocumentStore).toDict(),
|
||||||
|
).length;
|
||||||
|
if (numberOfDocs === 0) {
|
||||||
|
return await VectorStoreIndex.fromDocuments(docs, { storageContext });
|
||||||
|
}
|
||||||
|
return await VectorStoreIndex.init({
|
||||||
|
storageContext,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Settings.callbackManager.on("retrieve-end", (event) => {
|
||||||
|
const { nodes, query } = event.detail;
|
||||||
|
console.log(`${query.query} - Number of retrieved nodes:`, nodes.length);
|
||||||
|
});
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
const index = await getDataSource();
|
||||||
|
const filters: MetadataFilters = {
|
||||||
|
filters: [{ key: "dogId", value: "2", operator: "==" }],
|
||||||
|
};
|
||||||
|
|
||||||
|
const retriever = index.asRetriever({ similarityTopK: 3, filters });
|
||||||
|
const queryEngine = index.asQueryEngine({
|
||||||
|
similarityTopK: 3,
|
||||||
|
preFilters: filters,
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("Retriever and query engine should only retrieve 1 node:");
|
||||||
|
await retriever.retrieve({ query: "Retriever: get dog" });
|
||||||
|
await queryEngine.query({ query: "QueryEngine: get dog" });
|
||||||
|
}
|
||||||
|
|
||||||
|
void main();
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
// call pnpm tsx multimodal/load.ts first to init the storage
|
// call pnpm tsx multimodal/load.ts first to init the storage
|
||||||
|
import { extractText } from "@llamaindex/core/utils";
|
||||||
import {
|
import {
|
||||||
ContextChatEngine,
|
ContextChatEngine,
|
||||||
NodeWithScore,
|
NodeWithScore,
|
||||||
@@ -25,8 +26,9 @@ Settings.callbackManager.on("retrieve-end", (event) => {
|
|||||||
const textNodes = nodes.filter(
|
const textNodes = nodes.filter(
|
||||||
(node: NodeWithScore) => node.node.type === ObjectType.TEXT,
|
(node: NodeWithScore) => node.node.type === ObjectType.TEXT,
|
||||||
);
|
);
|
||||||
|
const text = extractText(query);
|
||||||
console.log(
|
console.log(
|
||||||
`Retrieved ${textNodes.length} text nodes and ${imageNodes.length} image nodes for query: ${query}`,
|
`Retrieved ${textNodes.length} text nodes and ${imageNodes.length} image nodes for query: ${text}`,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
import { extractText } from "@llamaindex/core/utils";
|
||||||
import {
|
import {
|
||||||
MultiModalResponseSynthesizer,
|
getResponseSynthesizer,
|
||||||
OpenAI,
|
OpenAI,
|
||||||
Settings,
|
Settings,
|
||||||
VectorStoreIndex,
|
VectorStoreIndex,
|
||||||
@@ -16,7 +17,8 @@ Settings.llm = new OpenAI({ model: "gpt-4-turbo", maxTokens: 512 });
|
|||||||
// Update callbackManager
|
// Update callbackManager
|
||||||
Settings.callbackManager.on("retrieve-end", (event) => {
|
Settings.callbackManager.on("retrieve-end", (event) => {
|
||||||
const { nodes, query } = event.detail;
|
const { nodes, query } = event.detail;
|
||||||
console.log(`Retrieved ${nodes.length} nodes for query: ${query}`);
|
const text = extractText(query);
|
||||||
|
console.log(`Retrieved ${nodes.length} nodes for query: ${text}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
@@ -27,7 +29,7 @@ async function main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const queryEngine = index.asQueryEngine({
|
const queryEngine = index.asQueryEngine({
|
||||||
responseSynthesizer: new MultiModalResponseSynthesizer(),
|
responseSynthesizer: getResponseSynthesizer("multi_modal"),
|
||||||
retriever: index.asRetriever({ topK: { TEXT: 3, IMAGE: 1 } }),
|
retriever: index.asRetriever({ topK: { TEXT: 3, IMAGE: 1 } }),
|
||||||
});
|
});
|
||||||
const stream = await queryEngine.query({
|
const stream = await queryEngine.query({
|
||||||
|
|||||||
@@ -1,22 +1,24 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/examples",
|
"name": "@llamaindex/examples",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.0.8",
|
"version": "0.0.9",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aws-crypto/sha256-js": "^5.2.0",
|
"@aws-crypto/sha256-js": "^5.2.0",
|
||||||
"@azure/identity": "^4.4.1",
|
"@azure/identity": "^4.4.1",
|
||||||
"@datastax/astra-db-ts": "^1.4.1",
|
"@datastax/astra-db-ts": "^1.4.1",
|
||||||
"@llamaindex/core": "^0.2.0",
|
"@llamaindex/core": "^0.3.0",
|
||||||
"@notionhq/client": "^2.2.15",
|
"@notionhq/client": "^2.2.15",
|
||||||
"@pinecone-database/pinecone": "^3.0.2",
|
"@pinecone-database/pinecone": "^3.0.2",
|
||||||
|
"@vercel/postgres": "^0.10.0",
|
||||||
"@zilliz/milvus2-sdk-node": "^2.4.6",
|
"@zilliz/milvus2-sdk-node": "^2.4.6",
|
||||||
"chromadb": "^1.8.1",
|
"chromadb": "^1.8.1",
|
||||||
"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.6.0",
|
"llamaindex": "^0.7.0",
|
||||||
"mongodb": "^6.7.0",
|
"mongodb": "^6.7.0",
|
||||||
"pathe": "^1.1.2"
|
"pathe": "^1.1.2",
|
||||||
|
"postgres": "^3.4.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^22.5.1",
|
"@types/node": "^22.5.1",
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
Document,
|
Document,
|
||||||
|
getResponseSynthesizer,
|
||||||
PromptTemplate,
|
PromptTemplate,
|
||||||
ResponseSynthesizer,
|
|
||||||
TreeSummarize,
|
|
||||||
TreeSummarizePrompt,
|
TreeSummarizePrompt,
|
||||||
VectorStoreIndex,
|
VectorStoreIndex,
|
||||||
} from "llamaindex";
|
} from "llamaindex";
|
||||||
@@ -27,9 +26,7 @@ async function main() {
|
|||||||
|
|
||||||
const query = "The quick brown fox jumps over the lazy dog";
|
const query = "The quick brown fox jumps over the lazy dog";
|
||||||
|
|
||||||
const responseSynthesizer = new ResponseSynthesizer({
|
const responseSynthesizer = getResponseSynthesizer("tree_summarize");
|
||||||
responseBuilder: new TreeSummarize(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const queryEngine = index.asQueryEngine({
|
const queryEngine = index.asQueryEngine({
|
||||||
responseSynthesizer,
|
responseSynthesizer,
|
||||||
|
|||||||
@@ -39,6 +39,12 @@ async function main() {
|
|||||||
dogId: "2",
|
dogId: "2",
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
new Document({
|
||||||
|
text: "The dog is black",
|
||||||
|
metadata: {
|
||||||
|
dogId: "3",
|
||||||
|
},
|
||||||
|
}),
|
||||||
];
|
];
|
||||||
console.log("Creating QdrantDB vector store");
|
console.log("Creating QdrantDB vector store");
|
||||||
const qdrantVs = new QdrantVectorStore({ url: qdrantUrl, collectionName });
|
const qdrantVs = new QdrantVectorStore({ url: qdrantUrl, collectionName });
|
||||||
@@ -73,6 +79,42 @@ async function main() {
|
|||||||
query: "What is the color of the dog?",
|
query: "What is the color of the dog?",
|
||||||
});
|
});
|
||||||
console.log("Filter with dogId 2 response:", response.toString());
|
console.log("Filter with dogId 2 response:", response.toString());
|
||||||
|
|
||||||
|
console.log("Querying index with dogId !=2: Expected output: Not red");
|
||||||
|
const queryEngineNotDogId2 = index.asQueryEngine({
|
||||||
|
preFilters: {
|
||||||
|
filters: [
|
||||||
|
{
|
||||||
|
key: "dogId",
|
||||||
|
value: "2",
|
||||||
|
operator: "!=",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const responseNotDogId2 = await queryEngineNotDogId2.query({
|
||||||
|
query: "What is the color of the dog?",
|
||||||
|
});
|
||||||
|
console.log(responseNotDogId2.toString());
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
"Querying index with dogId 2 or 3: Expected output: Red, Black",
|
||||||
|
);
|
||||||
|
const queryEngineIn = index.asQueryEngine({
|
||||||
|
preFilters: {
|
||||||
|
filters: [
|
||||||
|
{
|
||||||
|
key: "dogId",
|
||||||
|
value: ["2", "3"],
|
||||||
|
operator: "in",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const responseIn = await queryEngineIn.query({
|
||||||
|
query: "List all dogs",
|
||||||
|
});
|
||||||
|
console.log(responseIn.toString());
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
CompactAndRefine,
|
getResponseSynthesizer,
|
||||||
OpenAI,
|
OpenAI,
|
||||||
PromptTemplate,
|
PromptTemplate,
|
||||||
ResponseSynthesizer,
|
|
||||||
Settings,
|
Settings,
|
||||||
VectorStoreIndex,
|
VectorStoreIndex,
|
||||||
} from "llamaindex";
|
} from "llamaindex";
|
||||||
@@ -29,8 +28,8 @@ Given the CSV file, generate me Typescript code to answer the question: {query}.
|
|||||||
`,
|
`,
|
||||||
});
|
});
|
||||||
|
|
||||||
const responseSynthesizer = new ResponseSynthesizer({
|
const responseSynthesizer = getResponseSynthesizer("compact", {
|
||||||
responseBuilder: new CompactAndRefine(undefined, csvPrompt),
|
textQATemplate: csvPrompt,
|
||||||
});
|
});
|
||||||
|
|
||||||
const queryEngine = index.asQueryEngine({ responseSynthesizer });
|
const queryEngine = index.asQueryEngine({ responseSynthesizer });
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { createMessageContent } from "@llamaindex/core/response-synthesizers";
|
||||||
import {
|
import {
|
||||||
Document,
|
Document,
|
||||||
ImageNode,
|
ImageNode,
|
||||||
@@ -6,7 +7,6 @@ import {
|
|||||||
PromptTemplate,
|
PromptTemplate,
|
||||||
VectorStoreIndex,
|
VectorStoreIndex,
|
||||||
} from "llamaindex";
|
} from "llamaindex";
|
||||||
import { createMessageContent } from "llamaindex/synthesizers/utils";
|
|
||||||
|
|
||||||
const reader = new LlamaParseReader();
|
const reader = new LlamaParseReader();
|
||||||
async function main() {
|
async function main() {
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# neon template
|
||||||
|
PGHOST=
|
||||||
|
PGDATABASE=
|
||||||
|
PGUSER=
|
||||||
|
PGPASSWORD=
|
||||||
|
ENDPOINT_ID=
|
||||||
|
|
||||||
|
# vercel template
|
||||||
|
POSTGRES_URL=
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
// load-docs.ts
|
// load-docs.ts
|
||||||
import fs from "fs/promises";
|
|
||||||
import {
|
import {
|
||||||
PGVectorStore,
|
PGVectorStore,
|
||||||
SimpleDirectoryReader,
|
SimpleDirectoryReader,
|
||||||
storageContextFromDefaults,
|
storageContextFromDefaults,
|
||||||
VectorStoreIndex,
|
VectorStoreIndex,
|
||||||
} from "llamaindex";
|
} from "llamaindex";
|
||||||
|
import fs from "node:fs/promises";
|
||||||
|
|
||||||
async function getSourceFilenames(sourceDir: string) {
|
async function getSourceFilenames(sourceDir: string) {
|
||||||
return await fs
|
return await fs
|
||||||
@@ -40,7 +40,11 @@ async function main(args: any) {
|
|||||||
const rdr = new SimpleDirectoryReader(callback);
|
const rdr = new SimpleDirectoryReader(callback);
|
||||||
const docs = await rdr.loadData({ directoryPath: sourceDir });
|
const docs = await rdr.loadData({ directoryPath: sourceDir });
|
||||||
|
|
||||||
const pgvs = new PGVectorStore();
|
const pgvs = new PGVectorStore({
|
||||||
|
clientConfig: {
|
||||||
|
connectionString: process.env.PG_CONNECTION_STRING,
|
||||||
|
},
|
||||||
|
});
|
||||||
pgvs.setCollection(sourceDir);
|
pgvs.setCollection(sourceDir);
|
||||||
await pgvs.clearCollection();
|
await pgvs.clearCollection();
|
||||||
|
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/* eslint-disable turbo/no-undeclared-env-vars */
|
||||||
|
import dotenv from "dotenv";
|
||||||
|
import { Document, PGVectorStore, VectorStoreQueryMode } from "llamaindex";
|
||||||
|
import postgres from "postgres";
|
||||||
|
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
|
const { PGHOST, PGDATABASE, PGUSER, ENDPOINT_ID } = process.env;
|
||||||
|
const PGPASSWORD = decodeURIComponent(process.env.PGPASSWORD!);
|
||||||
|
|
||||||
|
const sql = postgres({
|
||||||
|
host: PGHOST,
|
||||||
|
database: PGDATABASE,
|
||||||
|
username: PGUSER,
|
||||||
|
password: PGPASSWORD,
|
||||||
|
port: 5432,
|
||||||
|
ssl: "require",
|
||||||
|
connection: {
|
||||||
|
options: `project=${ENDPOINT_ID}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await sql`CREATE EXTENSION IF NOT EXISTS vector`;
|
||||||
|
|
||||||
|
const vectorStore = new PGVectorStore({
|
||||||
|
dimensions: 3,
|
||||||
|
client: sql,
|
||||||
|
});
|
||||||
|
|
||||||
|
await vectorStore.add([
|
||||||
|
new Document({
|
||||||
|
text: "hello, world",
|
||||||
|
embedding: [1, 2, 3],
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const results = await vectorStore.query({
|
||||||
|
mode: VectorStoreQueryMode.DEFAULT,
|
||||||
|
similarityTopK: 1,
|
||||||
|
queryEmbedding: [1, 2, 3],
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("result", results);
|
||||||
|
|
||||||
|
await sql.end();
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"name": "pg-vector-store",
|
||||||
|
"type": "module",
|
||||||
|
"private": true
|
||||||
|
}
|
||||||
@@ -7,7 +7,11 @@ async function main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const pgvs = new PGVectorStore();
|
const pgvs = new PGVectorStore({
|
||||||
|
clientConfig: {
|
||||||
|
connectionString: process.env.PG_CONNECTION_STRING,
|
||||||
|
},
|
||||||
|
});
|
||||||
// Optional - set your collection name, default is no filter on this field.
|
// Optional - set your collection name, default is no filter on this field.
|
||||||
// pgvs.setCollection();
|
// pgvs.setCollection();
|
||||||
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "./dist",
|
||||||
|
"types": ["node"],
|
||||||
|
"skipLibCheck": true
|
||||||
|
},
|
||||||
|
"include": ["./**/*.ts"]
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
// https://vercel.com/docs/storage/vercel-postgres/sdk
|
||||||
|
import { sql } from "@vercel/postgres";
|
||||||
|
import dotenv from "dotenv";
|
||||||
|
import { Document, PGVectorStore, VectorStoreQueryMode } from "llamaindex";
|
||||||
|
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
|
await sql`CREATE EXTENSION IF NOT EXISTS vector`;
|
||||||
|
|
||||||
|
const vectorStore = new PGVectorStore({
|
||||||
|
dimensions: 3,
|
||||||
|
client: sql,
|
||||||
|
});
|
||||||
|
|
||||||
|
await vectorStore.add([
|
||||||
|
new Document({
|
||||||
|
text: "hello, world",
|
||||||
|
embedding: [1, 2, 3],
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const results = await vectorStore.query({
|
||||||
|
mode: VectorStoreQueryMode.DEFAULT,
|
||||||
|
similarityTopK: 1,
|
||||||
|
queryEmbedding: [1, 2, 3],
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("result", results);
|
||||||
|
|
||||||
|
await sql.end();
|
||||||
@@ -2,12 +2,10 @@ import fs from "node:fs/promises";
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
Anthropic,
|
Anthropic,
|
||||||
CompactAndRefine,
|
|
||||||
Document,
|
Document,
|
||||||
ResponseSynthesizer,
|
|
||||||
Settings,
|
Settings,
|
||||||
VectorStoreIndex,
|
VectorStoreIndex,
|
||||||
anthropicTextQaPrompt,
|
getResponseSynthesizer,
|
||||||
} from "llamaindex";
|
} from "llamaindex";
|
||||||
|
|
||||||
// Update llm to use Anthropic
|
// Update llm to use Anthropic
|
||||||
@@ -23,9 +21,7 @@ async function main() {
|
|||||||
const document = new Document({ text: essay, id_: path });
|
const document = new Document({ text: essay, id_: path });
|
||||||
|
|
||||||
// Split text and create embeddings. Store them in a VectorStoreIndex
|
// Split text and create embeddings. Store them in a VectorStoreIndex
|
||||||
const responseSynthesizer = new ResponseSynthesizer({
|
const responseSynthesizer = getResponseSynthesizer("compact");
|
||||||
responseBuilder: new CompactAndRefine(undefined, anthropicTextQaPrompt),
|
|
||||||
});
|
|
||||||
|
|
||||||
const index = await VectorStoreIndex.fromDocuments([document]);
|
const index = await VectorStoreIndex.fromDocuments([document]);
|
||||||
|
|
||||||
|
|||||||
@@ -25,12 +25,9 @@ async function main() {
|
|||||||
similarityCutoff: 0.7,
|
similarityCutoff: 0.7,
|
||||||
});
|
});
|
||||||
// TODO: cannot pass responseSynthesizer into retriever query engine
|
// TODO: cannot pass responseSynthesizer into retriever query engine
|
||||||
const queryEngine = new RetrieverQueryEngine(
|
const queryEngine = new RetrieverQueryEngine(retriever, undefined, [
|
||||||
retriever,
|
nodePostprocessor,
|
||||||
undefined,
|
]);
|
||||||
undefined,
|
|
||||||
[nodePostprocessor],
|
|
||||||
);
|
|
||||||
|
|
||||||
const response = await queryEngine.query({
|
const response = await queryEngine.query({
|
||||||
query: "What did the author do growing up?",
|
query: "What did the author do growing up?",
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
import {
|
import {
|
||||||
|
BaseVectorStore,
|
||||||
|
getResponseSynthesizer,
|
||||||
OpenAI,
|
OpenAI,
|
||||||
OpenAIEmbedding,
|
OpenAIEmbedding,
|
||||||
ResponseSynthesizer,
|
|
||||||
RetrieverQueryEngine,
|
RetrieverQueryEngine,
|
||||||
Settings,
|
Settings,
|
||||||
TextNode,
|
TextNode,
|
||||||
TreeSummarize,
|
|
||||||
VectorIndexRetriever,
|
VectorIndexRetriever,
|
||||||
VectorStore,
|
|
||||||
VectorStoreIndex,
|
VectorStoreIndex,
|
||||||
VectorStoreQuery,
|
VectorStoreQuery,
|
||||||
VectorStoreQueryResult,
|
VectorStoreQueryResult,
|
||||||
@@ -25,7 +24,7 @@ Settings.llm = new OpenAI({
|
|||||||
* Please do not use this class in production; it's only for demonstration purposes.
|
* Please do not use this class in production; it's only for demonstration purposes.
|
||||||
*/
|
*/
|
||||||
class PineconeVectorStore<T extends RecordMetadata = RecordMetadata>
|
class PineconeVectorStore<T extends RecordMetadata = RecordMetadata>
|
||||||
implements VectorStore
|
implements BaseVectorStore
|
||||||
{
|
{
|
||||||
storesText = true;
|
storesText = true;
|
||||||
isEmbeddingQuery = false;
|
isEmbeddingQuery = false;
|
||||||
@@ -165,13 +164,8 @@ async function main() {
|
|||||||
similarityTopK: 500,
|
similarityTopK: 500,
|
||||||
});
|
});
|
||||||
|
|
||||||
const responseSynthesizer = new ResponseSynthesizer({
|
const responseSynthesizer = getResponseSynthesizer("tree_summarize");
|
||||||
responseBuilder: new TreeSummarize(),
|
return new RetrieverQueryEngine(retriever, responseSynthesizer);
|
||||||
});
|
|
||||||
|
|
||||||
return new RetrieverQueryEngine(retriever, responseSynthesizer, {
|
|
||||||
filter,
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// whatever is a key from your metadata
|
// whatever is a key from your metadata
|
||||||
|
|||||||
+2
-1
@@ -12,6 +12,7 @@
|
|||||||
"e2e": "turbo run e2e",
|
"e2e": "turbo run e2e",
|
||||||
"test": "turbo run test",
|
"test": "turbo run test",
|
||||||
"type-check": "tsc -b --diagnostics",
|
"type-check": "tsc -b --diagnostics",
|
||||||
|
"circular-check": "madge --circular ./packages/**/**/dist/index.js",
|
||||||
"release": "pnpm run build:release && changeset publish",
|
"release": "pnpm run build:release && changeset publish",
|
||||||
"release-snapshot": "pnpm run build:release && changeset publish --tag snapshot",
|
"release-snapshot": "pnpm run build:release && changeset publish --tag snapshot",
|
||||||
"new-version": "changeset version && pnpm format:write && pnpm run build:release",
|
"new-version": "changeset version && pnpm format:write && pnpm run build:release",
|
||||||
@@ -30,7 +31,7 @@
|
|||||||
"madge": "^8.0.0",
|
"madge": "^8.0.0",
|
||||||
"prettier": "^3.3.3",
|
"prettier": "^3.3.3",
|
||||||
"prettier-plugin-organize-imports": "^4.0.0",
|
"prettier-plugin-organize-imports": "^4.0.0",
|
||||||
"turbo": "^2.1.0",
|
"turbo": "^2.1.2",
|
||||||
"typescript": "^5.6.2"
|
"typescript": "^5.6.2"
|
||||||
},
|
},
|
||||||
"packageManager": "pnpm@9.5.0",
|
"packageManager": "pnpm@9.5.0",
|
||||||
|
|||||||
@@ -1,5 +1,175 @@
|
|||||||
# @llamaindex/autotool
|
# @llamaindex/autotool
|
||||||
|
|
||||||
|
## 4.0.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- a75af83: refactor: move some llm and embedding to single package
|
||||||
|
- Updated dependencies [ae49ff4]
|
||||||
|
- Updated dependencies [4c38c1b]
|
||||||
|
- Updated dependencies [a75af83]
|
||||||
|
- Updated dependencies [a75af83]
|
||||||
|
- llamaindex@0.7.1
|
||||||
|
|
||||||
|
## 4.0.0
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [1364e8e]
|
||||||
|
- Updated dependencies [3b7736f]
|
||||||
|
- Updated dependencies [96fc69c]
|
||||||
|
- llamaindex@0.7.0
|
||||||
|
|
||||||
|
## 3.0.22
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [5729bd9]
|
||||||
|
- llamaindex@0.6.22
|
||||||
|
|
||||||
|
## 3.0.21
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [6f75306]
|
||||||
|
- Updated dependencies [94cb4ad]
|
||||||
|
- llamaindex@0.6.21
|
||||||
|
|
||||||
|
## 3.0.20
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [6a9a7b1]
|
||||||
|
- llamaindex@0.6.20
|
||||||
|
|
||||||
|
## 3.0.19
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [62cba52]
|
||||||
|
- Updated dependencies [d265e96]
|
||||||
|
- Updated dependencies [d30bbf7]
|
||||||
|
- Updated dependencies [53fd00a]
|
||||||
|
- llamaindex@0.6.19
|
||||||
|
|
||||||
|
## 3.0.18
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [5f67820]
|
||||||
|
- Updated dependencies [fe08d04]
|
||||||
|
- llamaindex@0.6.18
|
||||||
|
|
||||||
|
## 3.0.17
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [ee697fb]
|
||||||
|
- llamaindex@0.6.17
|
||||||
|
|
||||||
|
## 3.0.16
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [63e9846]
|
||||||
|
- Updated dependencies [6f3a31c]
|
||||||
|
- llamaindex@0.6.16
|
||||||
|
|
||||||
|
## 3.0.15
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [2a82413]
|
||||||
|
- llamaindex@0.6.15
|
||||||
|
|
||||||
|
## 3.0.14
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- llamaindex@0.6.14
|
||||||
|
|
||||||
|
## 3.0.13
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- llamaindex@0.6.13
|
||||||
|
|
||||||
|
## 3.0.12
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [f7b4e94]
|
||||||
|
- Updated dependencies [78037a6]
|
||||||
|
- Updated dependencies [1d9e3b1]
|
||||||
|
- llamaindex@0.6.12
|
||||||
|
|
||||||
|
## 3.0.11
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- df441e2: fix: consoleLogger is missing from `@llamaindex/env`
|
||||||
|
- Updated dependencies [df441e2]
|
||||||
|
- llamaindex@0.6.11
|
||||||
|
|
||||||
|
## 3.0.10
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [ebc5105]
|
||||||
|
- Updated dependencies [6cce3b1]
|
||||||
|
- llamaindex@0.6.10
|
||||||
|
|
||||||
|
## 3.0.9
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- llamaindex@0.6.9
|
||||||
|
|
||||||
|
## 3.0.8
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [8b7fdba]
|
||||||
|
- llamaindex@0.6.8
|
||||||
|
|
||||||
|
## 3.0.7
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [23bcc37]
|
||||||
|
- llamaindex@0.6.7
|
||||||
|
|
||||||
|
## 3.0.6
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [d902cc3]
|
||||||
|
- Updated dependencies [025ffe6]
|
||||||
|
- Updated dependencies [a659574]
|
||||||
|
- llamaindex@0.6.6
|
||||||
|
|
||||||
|
## 3.0.5
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [e9714db]
|
||||||
|
- llamaindex@0.6.5
|
||||||
|
|
||||||
|
## 3.0.4
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [b48bcc3]
|
||||||
|
- llamaindex@0.6.4
|
||||||
|
|
||||||
|
## 3.0.3
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [2cd1383]
|
||||||
|
- Updated dependencies [5c4badb]
|
||||||
|
- llamaindex@0.6.3
|
||||||
|
|
||||||
## 3.0.2
|
## 3.0.2
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,5 +1,195 @@
|
|||||||
# @llamaindex/autotool-01-node-example
|
# @llamaindex/autotool-01-node-example
|
||||||
|
|
||||||
|
## 0.0.33
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [ae49ff4]
|
||||||
|
- Updated dependencies [4c38c1b]
|
||||||
|
- Updated dependencies [a75af83]
|
||||||
|
- Updated dependencies [a75af83]
|
||||||
|
- llamaindex@0.7.1
|
||||||
|
- @llamaindex/autotool@4.0.1
|
||||||
|
|
||||||
|
## 0.0.32
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [1364e8e]
|
||||||
|
- Updated dependencies [3b7736f]
|
||||||
|
- Updated dependencies [96fc69c]
|
||||||
|
- llamaindex@0.7.0
|
||||||
|
- @llamaindex/autotool@4.0.0
|
||||||
|
|
||||||
|
## 0.0.31
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [5729bd9]
|
||||||
|
- llamaindex@0.6.22
|
||||||
|
- @llamaindex/autotool@3.0.22
|
||||||
|
|
||||||
|
## 0.0.30
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [6f75306]
|
||||||
|
- Updated dependencies [94cb4ad]
|
||||||
|
- llamaindex@0.6.21
|
||||||
|
- @llamaindex/autotool@3.0.21
|
||||||
|
|
||||||
|
## 0.0.29
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [6a9a7b1]
|
||||||
|
- llamaindex@0.6.20
|
||||||
|
- @llamaindex/autotool@3.0.20
|
||||||
|
|
||||||
|
## 0.0.28
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [62cba52]
|
||||||
|
- Updated dependencies [d265e96]
|
||||||
|
- Updated dependencies [d30bbf7]
|
||||||
|
- Updated dependencies [53fd00a]
|
||||||
|
- llamaindex@0.6.19
|
||||||
|
- @llamaindex/autotool@3.0.19
|
||||||
|
|
||||||
|
## 0.0.27
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [5f67820]
|
||||||
|
- Updated dependencies [fe08d04]
|
||||||
|
- llamaindex@0.6.18
|
||||||
|
- @llamaindex/autotool@3.0.18
|
||||||
|
|
||||||
|
## 0.0.26
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [ee697fb]
|
||||||
|
- llamaindex@0.6.17
|
||||||
|
- @llamaindex/autotool@3.0.17
|
||||||
|
|
||||||
|
## 0.0.25
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [63e9846]
|
||||||
|
- Updated dependencies [6f3a31c]
|
||||||
|
- llamaindex@0.6.16
|
||||||
|
- @llamaindex/autotool@3.0.16
|
||||||
|
|
||||||
|
## 0.0.24
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [2a82413]
|
||||||
|
- llamaindex@0.6.15
|
||||||
|
- @llamaindex/autotool@3.0.15
|
||||||
|
|
||||||
|
## 0.0.23
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- llamaindex@0.6.14
|
||||||
|
- @llamaindex/autotool@3.0.14
|
||||||
|
|
||||||
|
## 0.0.22
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- llamaindex@0.6.13
|
||||||
|
- @llamaindex/autotool@3.0.13
|
||||||
|
|
||||||
|
## 0.0.21
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [f7b4e94]
|
||||||
|
- Updated dependencies [78037a6]
|
||||||
|
- Updated dependencies [1d9e3b1]
|
||||||
|
- llamaindex@0.6.12
|
||||||
|
- @llamaindex/autotool@3.0.12
|
||||||
|
|
||||||
|
## 0.0.20
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [df441e2]
|
||||||
|
- @llamaindex/autotool@3.0.11
|
||||||
|
- llamaindex@0.6.11
|
||||||
|
|
||||||
|
## 0.0.19
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [ebc5105]
|
||||||
|
- Updated dependencies [6cce3b1]
|
||||||
|
- llamaindex@0.6.10
|
||||||
|
- @llamaindex/autotool@3.0.10
|
||||||
|
|
||||||
|
## 0.0.18
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- llamaindex@0.6.9
|
||||||
|
- @llamaindex/autotool@3.0.9
|
||||||
|
|
||||||
|
## 0.0.17
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [8b7fdba]
|
||||||
|
- llamaindex@0.6.8
|
||||||
|
- @llamaindex/autotool@3.0.8
|
||||||
|
|
||||||
|
## 0.0.16
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [23bcc37]
|
||||||
|
- llamaindex@0.6.7
|
||||||
|
- @llamaindex/autotool@3.0.7
|
||||||
|
|
||||||
|
## 0.0.15
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [d902cc3]
|
||||||
|
- Updated dependencies [025ffe6]
|
||||||
|
- Updated dependencies [a659574]
|
||||||
|
- llamaindex@0.6.6
|
||||||
|
- @llamaindex/autotool@3.0.6
|
||||||
|
|
||||||
|
## 0.0.14
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [e9714db]
|
||||||
|
- llamaindex@0.6.5
|
||||||
|
- @llamaindex/autotool@3.0.5
|
||||||
|
|
||||||
|
## 0.0.13
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [b48bcc3]
|
||||||
|
- llamaindex@0.6.4
|
||||||
|
- @llamaindex/autotool@3.0.4
|
||||||
|
|
||||||
|
## 0.0.12
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [2cd1383]
|
||||||
|
- Updated dependencies [5c4badb]
|
||||||
|
- llamaindex@0.6.3
|
||||||
|
- @llamaindex/autotool@3.0.3
|
||||||
|
|
||||||
## 0.0.11
|
## 0.0.11
|
||||||
|
|
||||||
### 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.11"
|
"version": "0.0.33"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,195 @@
|
|||||||
# @llamaindex/autotool-02-next-example
|
# @llamaindex/autotool-02-next-example
|
||||||
|
|
||||||
|
## 0.1.77
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [ae49ff4]
|
||||||
|
- Updated dependencies [4c38c1b]
|
||||||
|
- Updated dependencies [a75af83]
|
||||||
|
- Updated dependencies [a75af83]
|
||||||
|
- llamaindex@0.7.1
|
||||||
|
- @llamaindex/autotool@4.0.1
|
||||||
|
|
||||||
|
## 0.1.76
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [1364e8e]
|
||||||
|
- Updated dependencies [3b7736f]
|
||||||
|
- Updated dependencies [96fc69c]
|
||||||
|
- llamaindex@0.7.0
|
||||||
|
- @llamaindex/autotool@4.0.0
|
||||||
|
|
||||||
|
## 0.1.75
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [5729bd9]
|
||||||
|
- llamaindex@0.6.22
|
||||||
|
- @llamaindex/autotool@3.0.22
|
||||||
|
|
||||||
|
## 0.1.74
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [6f75306]
|
||||||
|
- Updated dependencies [94cb4ad]
|
||||||
|
- llamaindex@0.6.21
|
||||||
|
- @llamaindex/autotool@3.0.21
|
||||||
|
|
||||||
|
## 0.1.73
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [6a9a7b1]
|
||||||
|
- llamaindex@0.6.20
|
||||||
|
- @llamaindex/autotool@3.0.20
|
||||||
|
|
||||||
|
## 0.1.72
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [62cba52]
|
||||||
|
- Updated dependencies [d265e96]
|
||||||
|
- Updated dependencies [d30bbf7]
|
||||||
|
- Updated dependencies [53fd00a]
|
||||||
|
- llamaindex@0.6.19
|
||||||
|
- @llamaindex/autotool@3.0.19
|
||||||
|
|
||||||
|
## 0.1.71
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [5f67820]
|
||||||
|
- Updated dependencies [fe08d04]
|
||||||
|
- llamaindex@0.6.18
|
||||||
|
- @llamaindex/autotool@3.0.18
|
||||||
|
|
||||||
|
## 0.1.70
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [ee697fb]
|
||||||
|
- llamaindex@0.6.17
|
||||||
|
- @llamaindex/autotool@3.0.17
|
||||||
|
|
||||||
|
## 0.1.69
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [63e9846]
|
||||||
|
- Updated dependencies [6f3a31c]
|
||||||
|
- llamaindex@0.6.16
|
||||||
|
- @llamaindex/autotool@3.0.16
|
||||||
|
|
||||||
|
## 0.1.68
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [2a82413]
|
||||||
|
- llamaindex@0.6.15
|
||||||
|
- @llamaindex/autotool@3.0.15
|
||||||
|
|
||||||
|
## 0.1.67
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- llamaindex@0.6.14
|
||||||
|
- @llamaindex/autotool@3.0.14
|
||||||
|
|
||||||
|
## 0.1.66
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- llamaindex@0.6.13
|
||||||
|
- @llamaindex/autotool@3.0.13
|
||||||
|
|
||||||
|
## 0.1.65
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [f7b4e94]
|
||||||
|
- Updated dependencies [78037a6]
|
||||||
|
- Updated dependencies [1d9e3b1]
|
||||||
|
- llamaindex@0.6.12
|
||||||
|
- @llamaindex/autotool@3.0.12
|
||||||
|
|
||||||
|
## 0.1.64
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [df441e2]
|
||||||
|
- @llamaindex/autotool@3.0.11
|
||||||
|
- llamaindex@0.6.11
|
||||||
|
|
||||||
|
## 0.1.63
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [ebc5105]
|
||||||
|
- Updated dependencies [6cce3b1]
|
||||||
|
- llamaindex@0.6.10
|
||||||
|
- @llamaindex/autotool@3.0.10
|
||||||
|
|
||||||
|
## 0.1.62
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- llamaindex@0.6.9
|
||||||
|
- @llamaindex/autotool@3.0.9
|
||||||
|
|
||||||
|
## 0.1.61
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [8b7fdba]
|
||||||
|
- llamaindex@0.6.8
|
||||||
|
- @llamaindex/autotool@3.0.8
|
||||||
|
|
||||||
|
## 0.1.60
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [23bcc37]
|
||||||
|
- llamaindex@0.6.7
|
||||||
|
- @llamaindex/autotool@3.0.7
|
||||||
|
|
||||||
|
## 0.1.59
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [d902cc3]
|
||||||
|
- Updated dependencies [025ffe6]
|
||||||
|
- Updated dependencies [a659574]
|
||||||
|
- llamaindex@0.6.6
|
||||||
|
- @llamaindex/autotool@3.0.6
|
||||||
|
|
||||||
|
## 0.1.58
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [e9714db]
|
||||||
|
- llamaindex@0.6.5
|
||||||
|
- @llamaindex/autotool@3.0.5
|
||||||
|
|
||||||
|
## 0.1.57
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [b48bcc3]
|
||||||
|
- llamaindex@0.6.4
|
||||||
|
- @llamaindex/autotool@3.0.4
|
||||||
|
|
||||||
|
## 0.1.56
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [2cd1383]
|
||||||
|
- Updated dependencies [5c4badb]
|
||||||
|
- llamaindex@0.6.3
|
||||||
|
- @llamaindex/autotool@3.0.3
|
||||||
|
|
||||||
## 0.1.55
|
## 0.1.55
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/autotool-02-next-example",
|
"name": "@llamaindex/autotool-02-next-example",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.1.55",
|
"version": "0.1.77",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
"build": "next build",
|
"build": "next build",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/autotool",
|
"name": "@llamaindex/autotool",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "3.0.2",
|
"version": "4.0.1",
|
||||||
"description": "auto transpile your JS function to LLM Agent compatible",
|
"description": "auto transpile your JS function to LLM Agent compatible",
|
||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"dist",
|
||||||
@@ -70,7 +70,7 @@
|
|||||||
"@swc/types": "^0.1.12",
|
"@swc/types": "^0.1.12",
|
||||||
"@types/json-schema": "^7.0.15",
|
"@types/json-schema": "^7.0.15",
|
||||||
"@types/node": "^22.5.1",
|
"@types/node": "^22.5.1",
|
||||||
"bunchee": "5.3.2",
|
"bunchee": "5.5.1",
|
||||||
"llamaindex": "workspace:*",
|
"llamaindex": "workspace:*",
|
||||||
"next": "14.2.11",
|
"next": "14.2.11",
|
||||||
"rollup": "^4.21.2",
|
"rollup": "^4.21.2",
|
||||||
|
|||||||
@@ -1,5 +1,86 @@
|
|||||||
# @llamaindex/cloud
|
# @llamaindex/cloud
|
||||||
|
|
||||||
|
## 1.0.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 4c38c1b: fix(cloud): do not detect file type in llama parse
|
||||||
|
- 24d065f: Log Parse Job Errors when verbose is enabled
|
||||||
|
- a75af83: refactor: move some llm and embedding to single package
|
||||||
|
- Updated dependencies [ae49ff4]
|
||||||
|
- Updated dependencies [a75af83]
|
||||||
|
- @llamaindex/env@0.1.14
|
||||||
|
- @llamaindex/core@0.3.1
|
||||||
|
|
||||||
|
## 1.0.0
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [1364e8e]
|
||||||
|
- Updated dependencies [96fc69c]
|
||||||
|
- @llamaindex/core@0.3.0
|
||||||
|
|
||||||
|
## 0.2.14
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [5f67820]
|
||||||
|
- @llamaindex/core@0.2.12
|
||||||
|
|
||||||
|
## 0.2.13
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [ee697fb]
|
||||||
|
- @llamaindex/core@0.2.11
|
||||||
|
|
||||||
|
## 0.2.12
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [3489e7d]
|
||||||
|
- Updated dependencies [468bda5]
|
||||||
|
- @llamaindex/core@0.2.10
|
||||||
|
|
||||||
|
## 0.2.11
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 0b20ff9: fix: package.json format
|
||||||
|
|
||||||
|
## 0.2.10
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 981811e: fix(cloud): llama parse reader save image incorrectly
|
||||||
|
|
||||||
|
## 0.2.9
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- df441e2: fix: consoleLogger is missing from `@llamaindex/env`
|
||||||
|
- Updated dependencies [df441e2]
|
||||||
|
- @llamaindex/core@0.2.8
|
||||||
|
- @llamaindex/env@0.1.13
|
||||||
|
|
||||||
|
## 0.2.8
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- ac41ed3: feat: bump cloud sdk version
|
||||||
|
|
||||||
|
## 0.2.7
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- fb36eff: fix: backport for node.js 18
|
||||||
|
|
||||||
|
There could have one missing API in the node.js 18, so we need to backport it to make it work.
|
||||||
|
|
||||||
|
- d24d3d1: fix: print warning when llama parse reader has error
|
||||||
|
- Updated dependencies [2cd1383]
|
||||||
|
- @llamaindex/core@0.2.3
|
||||||
|
|
||||||
## 0.2.6
|
## 0.2.6
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"type": "module",
|
||||||
|
"main": "./dist/index.cjs",
|
||||||
|
"module": "./dist/index.js",
|
||||||
|
"types": "./dist/index.d.ts",
|
||||||
|
"exports": "./dist/index.js",
|
||||||
|
"private": true
|
||||||
|
}
|
||||||
+7890
-4744
File diff suppressed because it is too large
Load Diff
+21
-23
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/cloud",
|
"name": "@llamaindex/cloud",
|
||||||
"version": "0.2.6",
|
"version": "1.0.1",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -9,56 +9,54 @@
|
|||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"openapi.json",
|
"openapi.json",
|
||||||
"dist"
|
"./api",
|
||||||
|
"./reader"
|
||||||
],
|
],
|
||||||
"exports": {
|
"exports": {
|
||||||
"./openapi.json": "./openapi.json",
|
"./openapi.json": "./openapi.json",
|
||||||
"./api": {
|
"./api": {
|
||||||
"require": {
|
"require": {
|
||||||
"types": "./dist/api.d.cts",
|
"types": "./api/dist/index.d.cts",
|
||||||
"default": "./dist/api.cjs"
|
"default": "./api/dist/index.cjs"
|
||||||
},
|
},
|
||||||
"import": {
|
"import": {
|
||||||
"types": "./dist/api.d.ts",
|
"types": "./api/dist/index.d.ts",
|
||||||
"default": "./dist/api.js"
|
"default": "./api/dist/index.js"
|
||||||
},
|
},
|
||||||
"default": {
|
"default": {
|
||||||
"types": "./dist/api.d.ts",
|
"types": "./api/dist/index.d.ts",
|
||||||
"default": "./dist/api.js"
|
"default": "./api/dist/index.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"./reader": {
|
"./reader": {
|
||||||
"require": {
|
"require": {
|
||||||
"types": "./dist/reader.d.cts",
|
"types": "./reader/dist/index.d.cts",
|
||||||
"default": "./dist/reader.cjs"
|
"default": "./reader/dist/index.cjs"
|
||||||
},
|
},
|
||||||
"import": {
|
"import": {
|
||||||
"types": "./dist/reader.d.ts",
|
"types": "./reader/dist/index.d.ts",
|
||||||
"default": "./dist/reader.js"
|
"default": "./reader/dist/index.js"
|
||||||
},
|
},
|
||||||
"default": {
|
"default": {
|
||||||
"types": "./dist/reader.d.ts",
|
"types": "./reader/dist/index.d.ts",
|
||||||
"default": "./dist/reader.js"
|
"default": "./reader/dist/index.js"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/himself65/LlamaIndexTS.git",
|
"url": "https://github.com/run-llama/LlamaIndexTS.git",
|
||||||
"directory": "packages/cloud"
|
"directory": "packages/cloud"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@hey-api/client-fetch": "^0.2.4",
|
"@hey-api/client-fetch": "^0.2.4",
|
||||||
"@hey-api/openapi-ts": "^0.53.0",
|
"@hey-api/openapi-ts": "^0.53.0",
|
||||||
"@llamaindex/core": "workspace:^0.2.2",
|
"@llamaindex/core": "workspace:*",
|
||||||
"@llamaindex/env": "workspace:^0.1.11",
|
"@llamaindex/env": "workspace:*",
|
||||||
"bunchee": "5.3.2"
|
"bunchee": "5.5.1"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@llamaindex/core": "workspace:^0.2.2",
|
"@llamaindex/core": "workspace:*",
|
||||||
"@llamaindex/env": "workspace:^0.1.11"
|
"@llamaindex/env": "workspace:*"
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"magic-bytes.js": "^1.10.0"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"type": "module",
|
||||||
|
"main": "./dist/index.cjs",
|
||||||
|
"module": "./dist/index.js",
|
||||||
|
"types": "./dist/index.d.ts",
|
||||||
|
"exports": "./dist/index.js",
|
||||||
|
"private": true
|
||||||
|
}
|
||||||
+34
-152
@@ -1,11 +1,10 @@
|
|||||||
import { createClient, createConfig, type Client } from "@hey-api/client-fetch";
|
import { type Client, createClient, createConfig } from "@hey-api/client-fetch";
|
||||||
import { Document, FileReader } from "@llamaindex/core/schema";
|
import { Document, FileReader } from "@llamaindex/core/schema";
|
||||||
import { fs, getEnv } from "@llamaindex/env";
|
import { fs, getEnv, path } from "@llamaindex/env";
|
||||||
import { filetypeinfo } from "magic-bytes.js";
|
|
||||||
import {
|
import {
|
||||||
ParsingService,
|
|
||||||
type Body_upload_file_api_v1_parsing_upload_post,
|
type Body_upload_file_api_v1_parsing_upload_post,
|
||||||
type ParserLanguages,
|
type ParserLanguages,
|
||||||
|
ParsingService,
|
||||||
} from "./api";
|
} from "./api";
|
||||||
import { sleep } from "./utils";
|
import { sleep } from "./utils";
|
||||||
|
|
||||||
@@ -13,99 +12,6 @@ export type Language = ParserLanguages;
|
|||||||
|
|
||||||
export type ResultType = "text" | "markdown" | "json";
|
export type ResultType = "text" | "markdown" | "json";
|
||||||
|
|
||||||
const SUPPORT_FILE_EXT: string[] = [
|
|
||||||
".pdf",
|
|
||||||
// document and presentations
|
|
||||||
".602",
|
|
||||||
".abw",
|
|
||||||
".cgm",
|
|
||||||
".cwk",
|
|
||||||
".doc",
|
|
||||||
".docx",
|
|
||||||
".docm",
|
|
||||||
".dot",
|
|
||||||
".dotm",
|
|
||||||
".hwp",
|
|
||||||
".key",
|
|
||||||
".lwp",
|
|
||||||
".mw",
|
|
||||||
".mcw",
|
|
||||||
".pages",
|
|
||||||
".pbd",
|
|
||||||
".ppt",
|
|
||||||
".pptm",
|
|
||||||
".pptx",
|
|
||||||
".pot",
|
|
||||||
".potm",
|
|
||||||
".potx",
|
|
||||||
".rtf",
|
|
||||||
".sda",
|
|
||||||
".sdd",
|
|
||||||
".sdp",
|
|
||||||
".sdw",
|
|
||||||
".sgl",
|
|
||||||
".sti",
|
|
||||||
".sxi",
|
|
||||||
".sxw",
|
|
||||||
".stw",
|
|
||||||
".sxg",
|
|
||||||
".txt",
|
|
||||||
".uof",
|
|
||||||
".uop",
|
|
||||||
".uot",
|
|
||||||
".vor",
|
|
||||||
".wpd",
|
|
||||||
".wps",
|
|
||||||
".xml",
|
|
||||||
".zabw",
|
|
||||||
".epub",
|
|
||||||
// images
|
|
||||||
".jpg",
|
|
||||||
".jpeg",
|
|
||||||
".png",
|
|
||||||
".gif",
|
|
||||||
".bmp",
|
|
||||||
".svg",
|
|
||||||
".tiff",
|
|
||||||
".webp",
|
|
||||||
// web
|
|
||||||
".htm",
|
|
||||||
".html",
|
|
||||||
// spreadsheets
|
|
||||||
".xlsx",
|
|
||||||
".xls",
|
|
||||||
".xlsm",
|
|
||||||
".xlsb",
|
|
||||||
".xlw",
|
|
||||||
".csv",
|
|
||||||
".dif",
|
|
||||||
".sylk",
|
|
||||||
".slk",
|
|
||||||
".prn",
|
|
||||||
".numbers",
|
|
||||||
".et",
|
|
||||||
".ods",
|
|
||||||
".fods",
|
|
||||||
".uos1",
|
|
||||||
".uos2",
|
|
||||||
".dbf",
|
|
||||||
".wk1",
|
|
||||||
".wk2",
|
|
||||||
".wk3",
|
|
||||||
".wk4",
|
|
||||||
".wks",
|
|
||||||
".123",
|
|
||||||
".wq1",
|
|
||||||
".wq2",
|
|
||||||
".wb1",
|
|
||||||
".wb2",
|
|
||||||
".wb3",
|
|
||||||
".qpw",
|
|
||||||
".xlr",
|
|
||||||
".eth",
|
|
||||||
".tsv",
|
|
||||||
];
|
|
||||||
|
|
||||||
//todo: should move into @llamaindex/env
|
//todo: should move into @llamaindex/env
|
||||||
type WriteStream = {
|
type WriteStream = {
|
||||||
write: (text: string) => void;
|
write: (text: string) => void;
|
||||||
@@ -170,6 +76,15 @@ export class LlamaParseReader extends FileReader {
|
|||||||
vendorMultimodalModelName?: string | undefined;
|
vendorMultimodalModelName?: string | undefined;
|
||||||
// The API key for the multimodal API. Can also be set as an env variable: LLAMA_CLOUD_VENDOR_MULTIMODAL_API_KEY
|
// The API key for the multimodal API. Can also be set as an env variable: LLAMA_CLOUD_VENDOR_MULTIMODAL_API_KEY
|
||||||
vendorMultimodalApiKey?: string | undefined;
|
vendorMultimodalApiKey?: string | undefined;
|
||||||
|
|
||||||
|
webhookUrl?: string | undefined;
|
||||||
|
premiumMode?: boolean | undefined;
|
||||||
|
takeScreenshot?: boolean | undefined;
|
||||||
|
disableOcr?: boolean | undefined;
|
||||||
|
disableReconstruction?: boolean | undefined;
|
||||||
|
inputS3Path?: string | undefined;
|
||||||
|
outputS3PathPrefix?: string | undefined;
|
||||||
|
|
||||||
// numWorkers is implemented in SimpleDirectoryReader
|
// numWorkers is implemented in SimpleDirectoryReader
|
||||||
stdout?: WriteStream | undefined;
|
stdout?: WriteStream | undefined;
|
||||||
|
|
||||||
@@ -229,20 +144,13 @@ export class LlamaParseReader extends FileReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a job for the LlamaParse API
|
// Create a job for the LlamaParse API
|
||||||
private async createJob(
|
private async createJob(data: Uint8Array): Promise<string> {
|
||||||
data: Uint8Array,
|
|
||||||
fileName: string = "unknown",
|
|
||||||
): Promise<string> {
|
|
||||||
// Load data, set the mime type
|
|
||||||
const { mime, extension } = await LlamaParseReader.getMimeType(data);
|
|
||||||
|
|
||||||
if (this.verbose) {
|
if (this.verbose) {
|
||||||
const name = fileName ? fileName : extension;
|
console.log("Started uploading the file");
|
||||||
console.log(`Starting load for ${name} file`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const body = {
|
const body = {
|
||||||
file: new File([data], fileName, { type: mime }),
|
file: new Blob([data]),
|
||||||
language: this.language,
|
language: this.language,
|
||||||
parsing_instruction: this.parsingInstruction,
|
parsing_instruction: this.parsingInstruction,
|
||||||
skip_diagonal_text: this.skipDiagonalText,
|
skip_diagonal_text: this.skipDiagonalText,
|
||||||
@@ -260,13 +168,13 @@ export class LlamaParseReader extends FileReader {
|
|||||||
use_vendor_multimodal_model: this.useVendorMultimodalModel,
|
use_vendor_multimodal_model: this.useVendorMultimodalModel,
|
||||||
vendor_multimodal_model_name: this.vendorMultimodalModelName,
|
vendor_multimodal_model_name: this.vendorMultimodalModelName,
|
||||||
vendor_multimodal_api_key: this.vendorMultimodalApiKey,
|
vendor_multimodal_api_key: this.vendorMultimodalApiKey,
|
||||||
// fixme: does these fields need to be set?
|
premium_mode: this.premiumMode,
|
||||||
webhook_url: undefined,
|
webhook_url: this.webhookUrl,
|
||||||
take_screenshot: undefined,
|
take_screenshot: this.takeScreenshot,
|
||||||
disable_ocr: undefined,
|
disable_ocr: this.disableOcr,
|
||||||
disable_reconstruction: undefined,
|
disable_reconstruction: this.disableReconstruction,
|
||||||
input_s3_path: undefined,
|
input_s3_path: this.inputS3Path,
|
||||||
output_s3_path_prefix: undefined,
|
output_s3_path_prefix: this.outputS3PathPrefix,
|
||||||
} satisfies {
|
} satisfies {
|
||||||
[Key in keyof Body_upload_file_api_v1_parsing_upload_post]-?:
|
[Key in keyof Body_upload_file_api_v1_parsing_upload_post]-?:
|
||||||
| Body_upload_file_api_v1_parsing_upload_post[Key]
|
| Body_upload_file_api_v1_parsing_upload_post[Key]
|
||||||
@@ -361,6 +269,11 @@ export class LlamaParseReader extends FileReader {
|
|||||||
}
|
}
|
||||||
tries++;
|
tries++;
|
||||||
} else {
|
} else {
|
||||||
|
if (this.verbose) {
|
||||||
|
console.error(
|
||||||
|
`Recieved Error response ${status} for job ${jobId}. Got Error Code: ${data.error_code} and Error Message: ${data.error_message}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Failed to parse the file: ${jobId}, status: ${status}`,
|
`Failed to parse the file: ${jobId}, status: ${status}`,
|
||||||
);
|
);
|
||||||
@@ -373,14 +286,10 @@ export class LlamaParseReader extends FileReader {
|
|||||||
* To be used with resultType = "text" and "markdown"
|
* To be used with resultType = "text" and "markdown"
|
||||||
*
|
*
|
||||||
* @param {Uint8Array} fileContent - The content of the file to be loaded.
|
* @param {Uint8Array} fileContent - The content of the file to be loaded.
|
||||||
* @param {string} [fileName] - The optional name of the file to be loaded.
|
|
||||||
* @return {Promise<Document[]>} A Promise object that resolves to an array of Document objects.
|
* @return {Promise<Document[]>} A Promise object that resolves to an array of Document objects.
|
||||||
*/
|
*/
|
||||||
async loadDataAsContent(
|
async loadDataAsContent(fileContent: Uint8Array): Promise<Document[]> {
|
||||||
fileContent: Uint8Array,
|
return this.createJob(fileContent)
|
||||||
fileName?: string,
|
|
||||||
): Promise<Document[]> {
|
|
||||||
return this.createJob(fileContent, fileName)
|
|
||||||
.then(async (jobId) => {
|
.then(async (jobId) => {
|
||||||
if (this.verbose) {
|
if (this.verbose) {
|
||||||
console.log(`Started parsing the file under job id ${jobId}`);
|
console.log(`Started parsing the file under job id ${jobId}`);
|
||||||
@@ -403,6 +312,7 @@ export class LlamaParseReader extends FileReader {
|
|||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
if (this.ignoreErrors) {
|
if (this.ignoreErrors) {
|
||||||
|
console.warn(`Error while parsing the file: ${error.message}`);
|
||||||
return [];
|
return [];
|
||||||
} else {
|
} else {
|
||||||
throw error;
|
throw error;
|
||||||
@@ -437,8 +347,8 @@ export class LlamaParseReader extends FileReader {
|
|||||||
resultJson.file_path = isFilePath ? filePathOrContent : undefined;
|
resultJson.file_path = isFilePath ? filePathOrContent : undefined;
|
||||||
return [resultJson];
|
return [resultJson];
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`Error while parsing the file under job id ${jobId}`, e);
|
|
||||||
if (this.ignoreErrors) {
|
if (this.ignoreErrors) {
|
||||||
|
console.error(`Error while parsing the file under job id ${jobId}`, e);
|
||||||
return [];
|
return [];
|
||||||
} else {
|
} else {
|
||||||
throw e;
|
throw e;
|
||||||
@@ -506,14 +416,7 @@ export class LlamaParseReader extends FileReader {
|
|||||||
jobId: string,
|
jobId: string,
|
||||||
imageName: string,
|
imageName: string,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
// Get the full path
|
return path.join(downloadPath, `${jobId}-${imageName}`);
|
||||||
let imagePath = `${downloadPath}/${jobId}-${imageName}`;
|
|
||||||
// Get a valid image path
|
|
||||||
if (!imagePath.endsWith(".png") && !imagePath.endsWith(".jpg")) {
|
|
||||||
imagePath += ".png";
|
|
||||||
}
|
|
||||||
|
|
||||||
return imagePath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async fetchAndSaveImage(
|
private async fetchAndSaveImage(
|
||||||
@@ -534,10 +437,9 @@ export class LlamaParseReader extends FileReader {
|
|||||||
if (response.error) {
|
if (response.error) {
|
||||||
throw new Error(`Failed to download image: ${response.error.detail}`);
|
throw new Error(`Failed to download image: ${response.error.detail}`);
|
||||||
}
|
}
|
||||||
const arrayBuffer = (await response.data) as ArrayBuffer;
|
const blob = (await response.data) as Blob;
|
||||||
const buffer = new Uint8Array(arrayBuffer);
|
|
||||||
// Write the image buffer to the specified imagePath
|
// Write the image buffer to the specified imagePath
|
||||||
await fs.writeFile(imagePath, buffer);
|
await fs.writeFile(imagePath, new Uint8Array(await blob.arrayBuffer()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filters out invalid values (null, undefined, empty string) of specific params.
|
// Filters out invalid values (null, undefined, empty string) of specific params.
|
||||||
@@ -568,24 +470,4 @@ export class LlamaParseReader extends FileReader {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getMimeType(
|
|
||||||
data: Uint8Array,
|
|
||||||
): Promise<{ mime: string; extension: string }> {
|
|
||||||
const typeinfos = filetypeinfo(data);
|
|
||||||
// find the first type info that matches the supported MIME types
|
|
||||||
// It could be happened that docx file is recognized as zip file, so we need to check the mime type
|
|
||||||
const info = typeinfos.find((info) => {
|
|
||||||
if (info.extension && SUPPORT_FILE_EXT.includes(`.${info.extension}`)) {
|
|
||||||
return info;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (!info || !info.mime || !info.extension) {
|
|
||||||
const ext = SUPPORT_FILE_EXT.join(", ");
|
|
||||||
throw new Error(
|
|
||||||
`File has type which does not match supported MIME Types. Supported formats include: ${ext}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return { mime: info.mime, extension: info.extension };
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"extends": ["//"],
|
||||||
|
"tasks": {
|
||||||
|
"build": {
|
||||||
|
"outputs": ["**/dist/**", "src/client/**"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,104 @@
|
|||||||
# @llamaindex/community
|
# @llamaindex/community
|
||||||
|
|
||||||
|
## 0.0.49
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- a75af83: refactor: move some llm and embedding to single package
|
||||||
|
- Updated dependencies [ae49ff4]
|
||||||
|
- Updated dependencies [a75af83]
|
||||||
|
- @llamaindex/env@0.1.14
|
||||||
|
- @llamaindex/core@0.3.1
|
||||||
|
|
||||||
|
## 0.0.48
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [1364e8e]
|
||||||
|
- Updated dependencies [96fc69c]
|
||||||
|
- @llamaindex/core@0.3.0
|
||||||
|
|
||||||
|
## 0.0.47
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [5f67820]
|
||||||
|
- @llamaindex/core@0.2.12
|
||||||
|
|
||||||
|
## 0.0.46
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [ee697fb]
|
||||||
|
- @llamaindex/core@0.2.11
|
||||||
|
|
||||||
|
## 0.0.45
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [3489e7d]
|
||||||
|
- Updated dependencies [468bda5]
|
||||||
|
- @llamaindex/core@0.2.10
|
||||||
|
|
||||||
|
## 0.0.44
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [b17d439]
|
||||||
|
- @llamaindex/core@0.2.9
|
||||||
|
|
||||||
|
## 0.0.43
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 2774e80: feat: added meta3.2 support via Bedrock including vision, tool call and inference region support
|
||||||
|
|
||||||
|
## 0.0.42
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- df441e2: fix: consoleLogger is missing from `@llamaindex/env`
|
||||||
|
- Updated dependencies [df441e2]
|
||||||
|
- @llamaindex/core@0.2.8
|
||||||
|
- @llamaindex/env@0.1.13
|
||||||
|
|
||||||
|
## 0.0.41
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [6cce3b1]
|
||||||
|
- @llamaindex/core@0.2.7
|
||||||
|
|
||||||
|
## 0.0.40
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 50e6b57: feat: add Amazon Bedrock Retriever
|
||||||
|
- Updated dependencies [8b7fdba]
|
||||||
|
- @llamaindex/core@0.2.6
|
||||||
|
|
||||||
|
## 0.0.39
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [d902cc3]
|
||||||
|
- @llamaindex/core@0.2.5
|
||||||
|
|
||||||
|
## 0.0.38
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [b48bcc3]
|
||||||
|
- @llamaindex/core@0.2.4
|
||||||
|
- @llamaindex/env@0.1.12
|
||||||
|
|
||||||
|
## 0.0.37
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [2cd1383]
|
||||||
|
- @llamaindex/core@0.2.3
|
||||||
|
|
||||||
## 0.0.36
|
## 0.0.36
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -5,8 +5,11 @@
|
|||||||
## Current Features:
|
## Current Features:
|
||||||
|
|
||||||
- Bedrock support for the Anthropic Claude Models [usage](https://ts.llamaindex.ai/modules/llms/available_llms/bedrock)
|
- Bedrock support for the Anthropic Claude Models [usage](https://ts.llamaindex.ai/modules/llms/available_llms/bedrock)
|
||||||
- Bedrock support for the Meta LLama 2, 3 and 3.1 Models [usage](https://ts.llamaindex.ai/modules/llms/available_llms/bedrock)
|
- Bedrock support for the Meta LLama 2, 3, 3.1 and 3.2 Models [usage](https://ts.llamaindex.ai/modules/llms/available_llms/bedrock)
|
||||||
- Meta LLama3.1 405b tool call support
|
- Meta LLama3.1 405b and Llama3.2 tool call support
|
||||||
|
- Meta 3.2 11B and 90B vision support
|
||||||
|
- Bedrock support for querying Knowledge Base
|
||||||
|
- Bedrock: [Supported Regions and models for cross-region inference](https://docs.aws.amazon.com/bedrock/latest/userguide/cross-region-inference-support.html)
|
||||||
|
|
||||||
## LICENSE
|
## LICENSE
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/community",
|
"name": "@llamaindex/community",
|
||||||
"description": "Community package for LlamaIndexTS",
|
"description": "Community package for LlamaIndexTS",
|
||||||
"version": "0.0.36",
|
"version": "0.0.49",
|
||||||
"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",
|
||||||
@@ -43,9 +43,10 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^22.5.1",
|
"@types/node": "^22.5.1",
|
||||||
"bunchee": "5.3.2"
|
"bunchee": "5.5.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@aws-sdk/client-bedrock-agent-runtime": "^3.642.0",
|
||||||
"@aws-sdk/client-bedrock-runtime": "^3.642.0",
|
"@aws-sdk/client-bedrock-runtime": "^3.642.0",
|
||||||
"@llamaindex/core": "workspace:*",
|
"@llamaindex/core": "workspace:*",
|
||||||
"@llamaindex/env": "workspace:*"
|
"@llamaindex/env": "workspace:*"
|
||||||
|
|||||||
@@ -2,4 +2,7 @@ export {
|
|||||||
BEDROCK_MODELS,
|
BEDROCK_MODELS,
|
||||||
BEDROCK_MODEL_MAX_TOKENS,
|
BEDROCK_MODEL_MAX_TOKENS,
|
||||||
Bedrock,
|
Bedrock,
|
||||||
|
INFERENCE_BEDROCK_MODELS,
|
||||||
|
INFERENCE_TO_BEDROCK_MAP,
|
||||||
} from "./llm/bedrock/index.js";
|
} from "./llm/bedrock/index.js";
|
||||||
|
export { AmazonKnowledgeBaseRetriever } from "./retrievers/bedrock.js";
|
||||||
|
|||||||
@@ -6,7 +6,10 @@ import type {
|
|||||||
MessageContentDetail,
|
MessageContentDetail,
|
||||||
ToolCallLLMMessageOptions,
|
ToolCallLLMMessageOptions,
|
||||||
} from "@llamaindex/core/llms";
|
} from "@llamaindex/core/llms";
|
||||||
import { mapMessageContentToMessageContentDetails } from "../utils";
|
import {
|
||||||
|
extractDataUrlComponents,
|
||||||
|
mapMessageContentToMessageContentDetails,
|
||||||
|
} from "../utils";
|
||||||
import type {
|
import type {
|
||||||
AnthropicContent,
|
AnthropicContent,
|
||||||
AnthropicImageContent,
|
AnthropicImageContent,
|
||||||
@@ -143,27 +146,6 @@ export const mapTextContent = (text: string): AnthropicTextContent => {
|
|||||||
return { type: "text", text };
|
return { type: "text", text };
|
||||||
};
|
};
|
||||||
|
|
||||||
export const extractDataUrlComponents = (
|
|
||||||
dataUrl: string,
|
|
||||||
): {
|
|
||||||
mimeType: string;
|
|
||||||
base64: string;
|
|
||||||
} => {
|
|
||||||
const parts = dataUrl.split(";base64,");
|
|
||||||
|
|
||||||
if (parts.length !== 2 || !parts[0]!.startsWith("data:")) {
|
|
||||||
throw new Error("Invalid data URL");
|
|
||||||
}
|
|
||||||
|
|
||||||
const mimeType = parts[0]!.slice(5);
|
|
||||||
const base64 = parts[1]!;
|
|
||||||
|
|
||||||
return {
|
|
||||||
mimeType,
|
|
||||||
base64,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export const mapImageContent = (imageUrl: string): AnthropicImageContent => {
|
export const mapImageContent = (imageUrl: string): AnthropicImageContent => {
|
||||||
if (!imageUrl.startsWith("data:"))
|
if (!imageUrl.startsWith("data:"))
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import {
|
|||||||
ToolCallLLM,
|
ToolCallLLM,
|
||||||
type ToolCallLLMMessageOptions,
|
type ToolCallLLMMessageOptions,
|
||||||
} from "@llamaindex/core/llms";
|
} from "@llamaindex/core/llms";
|
||||||
import { streamConverter, wrapLLMEvent } from "@llamaindex/core/utils";
|
import { streamConverter } from "@llamaindex/core/utils";
|
||||||
import {
|
import {
|
||||||
type BedrockAdditionalChatOptions,
|
type BedrockAdditionalChatOptions,
|
||||||
type BedrockChatStreamResponse,
|
type BedrockChatStreamResponse,
|
||||||
@@ -24,6 +24,7 @@ import {
|
|||||||
} from "./provider";
|
} from "./provider";
|
||||||
import { mapMessageContentToMessageContentDetails } from "./utils";
|
import { mapMessageContentToMessageContentDetails } from "./utils";
|
||||||
|
|
||||||
|
import { wrapLLMEvent } from "@llamaindex/core/decorator";
|
||||||
import { AnthropicProvider } from "./anthropic/provider";
|
import { AnthropicProvider } from "./anthropic/provider";
|
||||||
import { MetaProvider } from "./meta/provider";
|
import { MetaProvider } from "./meta/provider";
|
||||||
|
|
||||||
@@ -46,35 +47,96 @@ export type BedrockChatParamsNonStreaming = LLMChatParamsNonStreaming<
|
|||||||
export type BedrockChatNonStreamResponse =
|
export type BedrockChatNonStreamResponse =
|
||||||
ChatResponse<ToolCallLLMMessageOptions>;
|
ChatResponse<ToolCallLLMMessageOptions>;
|
||||||
|
|
||||||
export enum BEDROCK_MODELS {
|
export const BEDROCK_MODELS = {
|
||||||
AMAZON_TITAN_TG1_LARGE = "amazon.titan-tg1-large",
|
AMAZON_TITAN_TG1_LARGE: "amazon.titan-tg1-large",
|
||||||
AMAZON_TITAN_TEXT_EXPRESS_V1 = "amazon.titan-text-express-v1",
|
AMAZON_TITAN_TEXT_EXPRESS_V1: "amazon.titan-text-express-v1",
|
||||||
AI21_J2_GRANDE_INSTRUCT = "ai21.j2-grande-instruct",
|
AI21_J2_GRANDE_INSTRUCT: "ai21.j2-grande-instruct",
|
||||||
AI21_J2_JUMBO_INSTRUCT = "ai21.j2-jumbo-instruct",
|
AI21_J2_JUMBO_INSTRUCT: "ai21.j2-jumbo-instruct",
|
||||||
AI21_J2_MID = "ai21.j2-mid",
|
AI21_J2_MID: "ai21.j2-mid",
|
||||||
AI21_J2_MID_V1 = "ai21.j2-mid-v1",
|
AI21_J2_MID_V1: "ai21.j2-mid-v1",
|
||||||
AI21_J2_ULTRA = "ai21.j2-ultra",
|
AI21_J2_ULTRA: "ai21.j2-ultra",
|
||||||
AI21_J2_ULTRA_V1 = "ai21.j2-ultra-v1",
|
AI21_J2_ULTRA_V1: "ai21.j2-ultra-v1",
|
||||||
COHERE_COMMAND_TEXT_V14 = "cohere.command-text-v14",
|
COHERE_COMMAND_TEXT_V14: "cohere.command-text-v14",
|
||||||
ANTHROPIC_CLAUDE_INSTANT_1 = "anthropic.claude-instant-v1",
|
ANTHROPIC_CLAUDE_INSTANT_1: "anthropic.claude-instant-v1",
|
||||||
ANTHROPIC_CLAUDE_1 = "anthropic.claude-v1", // EOF: No longer supported
|
ANTHROPIC_CLAUDE_1: "anthropic.claude-v1", // EOF: No longer supported
|
||||||
ANTHROPIC_CLAUDE_2 = "anthropic.claude-v2",
|
ANTHROPIC_CLAUDE_2: "anthropic.claude-v2",
|
||||||
ANTHROPIC_CLAUDE_2_1 = "anthropic.claude-v2:1",
|
ANTHROPIC_CLAUDE_2_1: "anthropic.claude-v2:1",
|
||||||
ANTHROPIC_CLAUDE_3_SONNET = "anthropic.claude-3-sonnet-20240229-v1:0",
|
ANTHROPIC_CLAUDE_3_SONNET: "anthropic.claude-3-sonnet-20240229-v1:0",
|
||||||
ANTHROPIC_CLAUDE_3_HAIKU = "anthropic.claude-3-haiku-20240307-v1:0",
|
ANTHROPIC_CLAUDE_3_HAIKU: "anthropic.claude-3-haiku-20240307-v1:0",
|
||||||
ANTHROPIC_CLAUDE_3_OPUS = "anthropic.claude-3-opus-20240229-v1:0",
|
ANTHROPIC_CLAUDE_3_OPUS: "anthropic.claude-3-opus-20240229-v1:0",
|
||||||
ANTHROPIC_CLAUDE_3_5_SONNET = "anthropic.claude-3-5-sonnet-20240620-v1:0",
|
ANTHROPIC_CLAUDE_3_5_SONNET: "anthropic.claude-3-5-sonnet-20240620-v1:0",
|
||||||
META_LLAMA2_13B_CHAT = "meta.llama2-13b-chat-v1",
|
META_LLAMA2_13B_CHAT: "meta.llama2-13b-chat-v1",
|
||||||
META_LLAMA2_70B_CHAT = "meta.llama2-70b-chat-v1",
|
META_LLAMA2_70B_CHAT: "meta.llama2-70b-chat-v1",
|
||||||
META_LLAMA3_8B_INSTRUCT = "meta.llama3-8b-instruct-v1:0",
|
META_LLAMA3_8B_INSTRUCT: "meta.llama3-8b-instruct-v1:0",
|
||||||
META_LLAMA3_70B_INSTRUCT = "meta.llama3-70b-instruct-v1:0",
|
META_LLAMA3_70B_INSTRUCT: "meta.llama3-70b-instruct-v1:0",
|
||||||
META_LLAMA3_1_8B_INSTRUCT = "meta.llama3-1-8b-instruct-v1:0",
|
META_LLAMA3_1_8B_INSTRUCT: "meta.llama3-1-8b-instruct-v1:0",
|
||||||
META_LLAMA3_1_70B_INSTRUCT = "meta.llama3-1-70b-instruct-v1:0",
|
META_LLAMA3_1_70B_INSTRUCT: "meta.llama3-1-70b-instruct-v1:0",
|
||||||
META_LLAMA3_1_405B_INSTRUCT = "meta.llama3-1-405b-instruct-v1:0",
|
META_LLAMA3_1_405B_INSTRUCT: "meta.llama3-1-405b-instruct-v1:0",
|
||||||
MISTRAL_7B_INSTRUCT = "mistral.mistral-7b-instruct-v0:2",
|
META_LLAMA3_2_1B_INSTRUCT: "meta.llama3-2-1b-instruct-v1:0",
|
||||||
MISTRAL_MIXTRAL_7B_INSTRUCT = "mistral.mixtral-8x7b-instruct-v0:1",
|
META_LLAMA3_2_3B_INSTRUCT: "meta.llama3-2-3b-instruct-v1:0",
|
||||||
MISTRAL_MIXTRAL_LARGE_2402 = "mistral.mistral-large-2402-v1:0",
|
META_LLAMA3_2_11B_INSTRUCT: "meta.llama3-2-11b-instruct-v1:0",
|
||||||
}
|
META_LLAMA3_2_90B_INSTRUCT: "meta.llama3-2-90b-instruct-v1:0",
|
||||||
|
MISTRAL_7B_INSTRUCT: "mistral.mistral-7b-instruct-v0:2",
|
||||||
|
MISTRAL_MIXTRAL_7B_INSTRUCT: "mistral.mixtral-8x7b-instruct-v0:1",
|
||||||
|
MISTRAL_MIXTRAL_LARGE_2402: "mistral.mistral-large-2402-v1:0",
|
||||||
|
};
|
||||||
|
export type BEDROCK_MODELS =
|
||||||
|
(typeof BEDROCK_MODELS)[keyof typeof BEDROCK_MODELS];
|
||||||
|
|
||||||
|
export const INFERENCE_BEDROCK_MODELS = {
|
||||||
|
US_ANTHROPIC_CLAUDE_3_HAIKU: "us.anthropic.claude-3-haiku-20240307-v1:0",
|
||||||
|
US_ANTHROPIC_CLAUDE_3_OPUS: "us.anthropic.claude-3-opus-20240229-v1:0",
|
||||||
|
US_ANTHROPIC_CLAUDE_3_SONNET: "us.anthropic.claude-3-sonnet-20240229-v1:0",
|
||||||
|
US_ANTHROPIC_CLAUDE_3_5_SONNET:
|
||||||
|
"us.anthropic.claude-3-5-sonnet-20240620-v1:0",
|
||||||
|
US_META_LLAMA_3_2_1B_INSTRUCT: "us.meta.llama3-2-1b-instruct-v1:0",
|
||||||
|
US_META_LLAMA_3_2_3B_INSTRUCT: "us.meta.llama3-2-3b-instruct-v1:0",
|
||||||
|
US_META_LLAMA_3_2_11B_INSTRUCT: "us.meta.llama3-2-11b-instruct-v1:0",
|
||||||
|
US_META_LLAMA_3_2_90B_INSTRUCT: "us.meta.llama3-2-90b-instruct-v1:0",
|
||||||
|
|
||||||
|
EU_ANTHROPIC_CLAUDE_3_HAIKU: "eu.anthropic.claude-3-haiku-20240307-v1:0",
|
||||||
|
EU_ANTHROPIC_CLAUDE_3_SONNET: "eu.anthropic.claude-3-sonnet-20240229-v1:0",
|
||||||
|
EU_ANTHROPIC_CLAUDE_3_5_SONNET:
|
||||||
|
"eu.anthropic.claude-3-5-sonnet-20240620-v1:0",
|
||||||
|
EU_META_LLAMA_3_2_1B_INSTRUCT: "eu.meta.llama3-2-1b-instruct-v1:0",
|
||||||
|
EU_META_LLAMA_3_2_3B_INSTRUCT: "eu.meta.llama3-2-3b-instruct-v1:0",
|
||||||
|
};
|
||||||
|
|
||||||
|
export type INFERENCE_BEDROCK_MODELS =
|
||||||
|
(typeof INFERENCE_BEDROCK_MODELS)[keyof typeof INFERENCE_BEDROCK_MODELS];
|
||||||
|
|
||||||
|
export const INFERENCE_TO_BEDROCK_MAP: Record<
|
||||||
|
INFERENCE_BEDROCK_MODELS,
|
||||||
|
BEDROCK_MODELS
|
||||||
|
> = {
|
||||||
|
[INFERENCE_BEDROCK_MODELS.US_ANTHROPIC_CLAUDE_3_HAIKU]:
|
||||||
|
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_HAIKU,
|
||||||
|
[INFERENCE_BEDROCK_MODELS.US_ANTHROPIC_CLAUDE_3_OPUS]:
|
||||||
|
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_OPUS,
|
||||||
|
[INFERENCE_BEDROCK_MODELS.US_ANTHROPIC_CLAUDE_3_SONNET]:
|
||||||
|
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_SONNET,
|
||||||
|
[INFERENCE_BEDROCK_MODELS.US_ANTHROPIC_CLAUDE_3_5_SONNET]:
|
||||||
|
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_5_SONNET,
|
||||||
|
[INFERENCE_BEDROCK_MODELS.US_META_LLAMA_3_2_1B_INSTRUCT]:
|
||||||
|
BEDROCK_MODELS.META_LLAMA3_2_1B_INSTRUCT,
|
||||||
|
[INFERENCE_BEDROCK_MODELS.US_META_LLAMA_3_2_3B_INSTRUCT]:
|
||||||
|
BEDROCK_MODELS.META_LLAMA3_2_3B_INSTRUCT,
|
||||||
|
[INFERENCE_BEDROCK_MODELS.US_META_LLAMA_3_2_11B_INSTRUCT]:
|
||||||
|
BEDROCK_MODELS.META_LLAMA3_2_11B_INSTRUCT,
|
||||||
|
[INFERENCE_BEDROCK_MODELS.US_META_LLAMA_3_2_90B_INSTRUCT]:
|
||||||
|
BEDROCK_MODELS.META_LLAMA3_2_90B_INSTRUCT,
|
||||||
|
|
||||||
|
[INFERENCE_BEDROCK_MODELS.EU_ANTHROPIC_CLAUDE_3_HAIKU]:
|
||||||
|
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_HAIKU,
|
||||||
|
[INFERENCE_BEDROCK_MODELS.EU_ANTHROPIC_CLAUDE_3_SONNET]:
|
||||||
|
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_SONNET,
|
||||||
|
[INFERENCE_BEDROCK_MODELS.EU_ANTHROPIC_CLAUDE_3_5_SONNET]:
|
||||||
|
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_5_SONNET,
|
||||||
|
[INFERENCE_BEDROCK_MODELS.EU_META_LLAMA_3_2_1B_INSTRUCT]:
|
||||||
|
BEDROCK_MODELS.META_LLAMA3_2_1B_INSTRUCT,
|
||||||
|
[INFERENCE_BEDROCK_MODELS.EU_META_LLAMA_3_2_3B_INSTRUCT]:
|
||||||
|
BEDROCK_MODELS.META_LLAMA3_2_3B_INSTRUCT,
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Values taken from https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters.html#model-parameters-claude
|
* Values taken from https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters.html#model-parameters-claude
|
||||||
@@ -108,6 +170,10 @@ const CHAT_ONLY_MODELS = {
|
|||||||
[BEDROCK_MODELS.META_LLAMA3_1_8B_INSTRUCT]: 128000,
|
[BEDROCK_MODELS.META_LLAMA3_1_8B_INSTRUCT]: 128000,
|
||||||
[BEDROCK_MODELS.META_LLAMA3_1_70B_INSTRUCT]: 128000,
|
[BEDROCK_MODELS.META_LLAMA3_1_70B_INSTRUCT]: 128000,
|
||||||
[BEDROCK_MODELS.META_LLAMA3_1_405B_INSTRUCT]: 128000,
|
[BEDROCK_MODELS.META_LLAMA3_1_405B_INSTRUCT]: 128000,
|
||||||
|
[BEDROCK_MODELS.META_LLAMA3_2_1B_INSTRUCT]: 131000,
|
||||||
|
[BEDROCK_MODELS.META_LLAMA3_2_3B_INSTRUCT]: 131000,
|
||||||
|
[BEDROCK_MODELS.META_LLAMA3_2_11B_INSTRUCT]: 128000,
|
||||||
|
[BEDROCK_MODELS.META_LLAMA3_2_90B_INSTRUCT]: 128000,
|
||||||
[BEDROCK_MODELS.MISTRAL_7B_INSTRUCT]: 32000,
|
[BEDROCK_MODELS.MISTRAL_7B_INSTRUCT]: 32000,
|
||||||
[BEDROCK_MODELS.MISTRAL_MIXTRAL_7B_INSTRUCT]: 32000,
|
[BEDROCK_MODELS.MISTRAL_MIXTRAL_7B_INSTRUCT]: 32000,
|
||||||
[BEDROCK_MODELS.MISTRAL_MIXTRAL_LARGE_2402]: 32000,
|
[BEDROCK_MODELS.MISTRAL_MIXTRAL_LARGE_2402]: 32000,
|
||||||
@@ -138,17 +204,25 @@ export const STREAMING_MODELS = new Set([
|
|||||||
BEDROCK_MODELS.META_LLAMA3_1_8B_INSTRUCT,
|
BEDROCK_MODELS.META_LLAMA3_1_8B_INSTRUCT,
|
||||||
BEDROCK_MODELS.META_LLAMA3_1_70B_INSTRUCT,
|
BEDROCK_MODELS.META_LLAMA3_1_70B_INSTRUCT,
|
||||||
BEDROCK_MODELS.META_LLAMA3_1_405B_INSTRUCT,
|
BEDROCK_MODELS.META_LLAMA3_1_405B_INSTRUCT,
|
||||||
|
BEDROCK_MODELS.META_LLAMA3_2_1B_INSTRUCT,
|
||||||
|
BEDROCK_MODELS.META_LLAMA3_2_3B_INSTRUCT,
|
||||||
|
BEDROCK_MODELS.META_LLAMA3_2_11B_INSTRUCT,
|
||||||
|
BEDROCK_MODELS.META_LLAMA3_2_90B_INSTRUCT,
|
||||||
BEDROCK_MODELS.MISTRAL_7B_INSTRUCT,
|
BEDROCK_MODELS.MISTRAL_7B_INSTRUCT,
|
||||||
BEDROCK_MODELS.MISTRAL_MIXTRAL_7B_INSTRUCT,
|
BEDROCK_MODELS.MISTRAL_MIXTRAL_7B_INSTRUCT,
|
||||||
BEDROCK_MODELS.MISTRAL_MIXTRAL_LARGE_2402,
|
BEDROCK_MODELS.MISTRAL_MIXTRAL_LARGE_2402,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
export const TOOL_CALL_MODELS = [
|
export const TOOL_CALL_MODELS: BEDROCK_MODELS[] = [
|
||||||
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_SONNET,
|
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_SONNET,
|
||||||
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_HAIKU,
|
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_HAIKU,
|
||||||
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_OPUS,
|
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_OPUS,
|
||||||
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_5_SONNET,
|
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_5_SONNET,
|
||||||
BEDROCK_MODELS.META_LLAMA3_1_405B_INSTRUCT,
|
BEDROCK_MODELS.META_LLAMA3_1_405B_INSTRUCT,
|
||||||
|
BEDROCK_MODELS.META_LLAMA3_2_1B_INSTRUCT,
|
||||||
|
BEDROCK_MODELS.META_LLAMA3_2_3B_INSTRUCT,
|
||||||
|
BEDROCK_MODELS.META_LLAMA3_2_11B_INSTRUCT,
|
||||||
|
BEDROCK_MODELS.META_LLAMA3_2_90B_INSTRUCT,
|
||||||
];
|
];
|
||||||
|
|
||||||
const getProvider = (model: string): Provider => {
|
const getProvider = (model: string): Provider => {
|
||||||
@@ -165,7 +239,7 @@ const getProvider = (model: string): Provider => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type BedrockModelParams = {
|
export type BedrockModelParams = {
|
||||||
model: keyof typeof BEDROCK_FOUNDATION_LLMS;
|
model: BEDROCK_MODELS | INFERENCE_BEDROCK_MODELS;
|
||||||
temperature?: number;
|
temperature?: number;
|
||||||
topP?: number;
|
topP?: number;
|
||||||
maxTokens?: number;
|
maxTokens?: number;
|
||||||
@@ -184,6 +258,10 @@ export const BEDROCK_MODEL_MAX_TOKENS: Partial<Record<BEDROCK_MODELS, number>> =
|
|||||||
[BEDROCK_MODELS.META_LLAMA3_1_8B_INSTRUCT]: 2048,
|
[BEDROCK_MODELS.META_LLAMA3_1_8B_INSTRUCT]: 2048,
|
||||||
[BEDROCK_MODELS.META_LLAMA3_1_70B_INSTRUCT]: 2048,
|
[BEDROCK_MODELS.META_LLAMA3_1_70B_INSTRUCT]: 2048,
|
||||||
[BEDROCK_MODELS.META_LLAMA3_1_405B_INSTRUCT]: 2048,
|
[BEDROCK_MODELS.META_LLAMA3_1_405B_INSTRUCT]: 2048,
|
||||||
|
[BEDROCK_MODELS.META_LLAMA3_2_1B_INSTRUCT]: 2048,
|
||||||
|
[BEDROCK_MODELS.META_LLAMA3_2_3B_INSTRUCT]: 2048,
|
||||||
|
[BEDROCK_MODELS.META_LLAMA3_2_11B_INSTRUCT]: 2048,
|
||||||
|
[BEDROCK_MODELS.META_LLAMA3_2_90B_INSTRUCT]: 2048,
|
||||||
};
|
};
|
||||||
|
|
||||||
const DEFAULT_BEDROCK_PARAMS = {
|
const DEFAULT_BEDROCK_PARAMS = {
|
||||||
@@ -192,14 +270,15 @@ const DEFAULT_BEDROCK_PARAMS = {
|
|||||||
maxTokens: 1024, // required by anthropic
|
maxTokens: 1024, // required by anthropic
|
||||||
};
|
};
|
||||||
|
|
||||||
export type BedrockParams = BedrockModelParams & BedrockRuntimeClientConfig;
|
export type BedrockParams = BedrockRuntimeClientConfig & BedrockModelParams;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ToolCallLLM for Bedrock
|
* ToolCallLLM for Bedrock
|
||||||
*/
|
*/
|
||||||
export class Bedrock extends ToolCallLLM<BedrockAdditionalChatOptions> {
|
export class Bedrock extends ToolCallLLM<BedrockAdditionalChatOptions> {
|
||||||
private client: BedrockRuntimeClient;
|
private client: BedrockRuntimeClient;
|
||||||
model: keyof typeof BEDROCK_FOUNDATION_LLMS;
|
protected actualModel: BEDROCK_MODELS | INFERENCE_BEDROCK_MODELS;
|
||||||
|
model: BEDROCK_MODELS;
|
||||||
temperature: number;
|
temperature: number;
|
||||||
topP: number;
|
topP: number;
|
||||||
maxTokens?: number;
|
maxTokens?: number;
|
||||||
@@ -216,8 +295,8 @@ export class Bedrock extends ToolCallLLM<BedrockAdditionalChatOptions> {
|
|||||||
...params
|
...params
|
||||||
}: BedrockParams) {
|
}: BedrockParams) {
|
||||||
super();
|
super();
|
||||||
|
this.actualModel = model;
|
||||||
this.model = model;
|
this.model = INFERENCE_TO_BEDROCK_MAP[model] ?? model;
|
||||||
this.provider = getProvider(this.model);
|
this.provider = getProvider(this.model);
|
||||||
this.maxTokens = maxTokens ?? DEFAULT_BEDROCK_PARAMS.maxTokens;
|
this.maxTokens = maxTokens ?? DEFAULT_BEDROCK_PARAMS.maxTokens;
|
||||||
this.temperature = temperature ?? DEFAULT_BEDROCK_PARAMS.temperature;
|
this.temperature = temperature ?? DEFAULT_BEDROCK_PARAMS.temperature;
|
||||||
@@ -240,7 +319,7 @@ export class Bedrock extends ToolCallLLM<BedrockAdditionalChatOptions> {
|
|||||||
temperature: this.temperature,
|
temperature: this.temperature,
|
||||||
topP: this.topP,
|
topP: this.topP,
|
||||||
maxTokens: this.maxTokens,
|
maxTokens: this.maxTokens,
|
||||||
contextWindow: BEDROCK_FOUNDATION_LLMS[this.model],
|
contextWindow: BEDROCK_FOUNDATION_LLMS[this.model] ?? 128000,
|
||||||
tokenizer: undefined,
|
tokenizer: undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -255,6 +334,8 @@ export class Bedrock extends ToolCallLLM<BedrockAdditionalChatOptions> {
|
|||||||
params.additionalChatOptions,
|
params.additionalChatOptions,
|
||||||
);
|
);
|
||||||
const command = new InvokeModelCommand(input);
|
const command = new InvokeModelCommand(input);
|
||||||
|
command.input.modelId = this.actualModel;
|
||||||
|
|
||||||
const response = await this.client.send(command);
|
const response = await this.client.send(command);
|
||||||
let options: ToolCallLLMMessageOptions = {};
|
let options: ToolCallLLMMessageOptions = {};
|
||||||
if (this.supportToolCall) {
|
if (this.supportToolCall) {
|
||||||
@@ -286,6 +367,8 @@ export class Bedrock extends ToolCallLLM<BedrockAdditionalChatOptions> {
|
|||||||
params.additionalChatOptions,
|
params.additionalChatOptions,
|
||||||
);
|
);
|
||||||
const command = new InvokeModelWithResponseStreamCommand(input);
|
const command = new InvokeModelWithResponseStreamCommand(input);
|
||||||
|
command.input.modelId = this.actualModel;
|
||||||
|
|
||||||
const response = await this.client.send(command);
|
const response = await this.client.send(command);
|
||||||
|
|
||||||
if (response.body) yield* this.provider.reduceStream(response.body);
|
if (response.body) yield* this.provider.reduceStream(response.body);
|
||||||
|
|||||||
@@ -67,21 +67,26 @@ export class MetaProvider extends Provider<MetaStreamEvent> {
|
|||||||
for await (const response of stream) {
|
for await (const response of stream) {
|
||||||
const event = this.getStreamingEventResponse(response);
|
const event = this.getStreamingEventResponse(response);
|
||||||
const delta = this.getTextFromStreamResponse(response);
|
const delta = this.getTextFromStreamResponse(response);
|
||||||
|
|
||||||
// odd quirk of llama3.1, start token is \n\n
|
// odd quirk of llama3.1, start token is \n\n
|
||||||
if (
|
if (
|
||||||
|
!toolId &&
|
||||||
!event?.generation.trim() &&
|
!event?.generation.trim() &&
|
||||||
event?.generation_token_count === 1 &&
|
event?.generation_token_count === 1 &&
|
||||||
event.prompt_token_count !== null
|
event?.prompt_token_count !== null
|
||||||
)
|
)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (delta === TOKENS.TOOL_CALL) {
|
if (delta.startsWith(TOKENS.TOOL_CALL)) {
|
||||||
toolId = randomUUID();
|
toolId = randomUUID();
|
||||||
|
const parts = delta.split(TOKENS.TOOL_CALL).filter((part) => part);
|
||||||
|
collecting.push(...parts);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let options: undefined | ToolCallLLMMessageOptions = undefined;
|
let options: undefined | ToolCallLLMMessageOptions = undefined;
|
||||||
if (toolId && event?.stop_reason === "stop") {
|
if (toolId && event?.stop_reason === "stop") {
|
||||||
|
if (delta) collecting.push(delta);
|
||||||
const tool = JSON.parse(collecting.join(""));
|
const tool = JSON.parse(collecting.join(""));
|
||||||
options = {
|
options = {
|
||||||
toolCall: [
|
toolCall: [
|
||||||
@@ -110,11 +115,18 @@ export class MetaProvider extends Provider<MetaStreamEvent> {
|
|||||||
getRequestBody<T extends ChatMessage>(
|
getRequestBody<T extends ChatMessage>(
|
||||||
metadata: LLMMetadata,
|
metadata: LLMMetadata,
|
||||||
messages: T[],
|
messages: T[],
|
||||||
tools?: BaseTool[],
|
tools: BaseTool[] = [],
|
||||||
): InvokeModelCommandInput | InvokeModelWithResponseStreamCommandInput {
|
): InvokeModelCommandInput | InvokeModelWithResponseStreamCommandInput {
|
||||||
let prompt: string = "";
|
let prompt: string = "";
|
||||||
|
let images: string[] = [];
|
||||||
if (metadata.model.startsWith("meta.llama3")) {
|
if (metadata.model.startsWith("meta.llama3")) {
|
||||||
prompt = mapChatMessagesToMetaLlama3Messages(messages, tools);
|
const mapped = mapChatMessagesToMetaLlama3Messages({
|
||||||
|
messages,
|
||||||
|
tools,
|
||||||
|
model: metadata.model,
|
||||||
|
});
|
||||||
|
prompt = mapped.prompt;
|
||||||
|
images = mapped.images;
|
||||||
} else if (metadata.model.startsWith("meta.llama2")) {
|
} else if (metadata.model.startsWith("meta.llama2")) {
|
||||||
prompt = mapChatMessagesToMetaLlama2Messages(messages);
|
prompt = mapChatMessagesToMetaLlama2Messages(messages);
|
||||||
} else {
|
} else {
|
||||||
@@ -127,6 +139,7 @@ export class MetaProvider extends Provider<MetaStreamEvent> {
|
|||||||
accept: "application/json",
|
accept: "application/json",
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
prompt,
|
prompt,
|
||||||
|
images: images.length ? images : undefined,
|
||||||
max_gen_len: metadata.maxTokens,
|
max_gen_len: metadata.maxTokens,
|
||||||
temperature: metadata.temperature,
|
temperature: metadata.temperature,
|
||||||
top_p: metadata.topP,
|
top_p: metadata.topP,
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
import type {
|
import type {
|
||||||
BaseTool,
|
BaseTool,
|
||||||
ChatMessage,
|
ChatMessage,
|
||||||
|
LLMMetadata,
|
||||||
MessageContentTextDetail,
|
MessageContentTextDetail,
|
||||||
ToolCallLLMMessageOptions,
|
ToolCallLLMMessageOptions,
|
||||||
} from "@llamaindex/core/llms";
|
} from "@llamaindex/core/llms";
|
||||||
|
import { extractDataUrlComponents } from "../utils";
|
||||||
|
import { TOKENS } from "./constants";
|
||||||
import type { MetaMessage } from "./types";
|
import type { MetaMessage } from "./types";
|
||||||
|
|
||||||
const getToolCallInstructionString = (tool: BaseTool): string => {
|
const getToolCallInstructionString = (tool: BaseTool): string => {
|
||||||
@@ -24,7 +27,7 @@ const getToolCallParametersString = (tool: BaseTool): string => {
|
|||||||
|
|
||||||
// ported from https://github.com/meta-llama/llama-agentic-system/blob/main/llama_agentic_system/system_prompt.py
|
// ported from https://github.com/meta-llama/llama-agentic-system/blob/main/llama_agentic_system/system_prompt.py
|
||||||
// NOTE: using json instead of the above xml style tool calling works more reliability
|
// NOTE: using json instead of the above xml style tool calling works more reliability
|
||||||
export const getToolsPrompt = (tools?: BaseTool[]) => {
|
export const getToolsPrompt_3_1 = (tools?: BaseTool[]) => {
|
||||||
if (!tools?.length) return "";
|
if (!tools?.length) return "";
|
||||||
|
|
||||||
const customToolParams = tools.map((tool) => {
|
const customToolParams = tools.map((tool) => {
|
||||||
@@ -77,6 +80,46 @@ Reminder:
|
|||||||
`;
|
`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getToolsPrompt_3_2 = (tools?: BaseTool[]) => {
|
||||||
|
if (!tools?.length) return "";
|
||||||
|
return `
|
||||||
|
You are an expert in composing functions. You are given a question and a set of possible functions.
|
||||||
|
Based on the question, you will need to make one or more function/tool calls to achieve the purpose.
|
||||||
|
If none of the function can be used, point it out. If the given question lacks the parameters required by the function,
|
||||||
|
also point it out. You should only return the function call in tools call sections.
|
||||||
|
|
||||||
|
If you decide to invoke any of the function(s), you MUST put it in the format of and start with the token: ${TOKENS.TOOL_CALL}:
|
||||||
|
{
|
||||||
|
"name": function_name,
|
||||||
|
"parameters": parameters,
|
||||||
|
}
|
||||||
|
where
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": function_name,
|
||||||
|
"parameters": parameters, => a JSON dict with the function argument name as key and function argument value as value.
|
||||||
|
}
|
||||||
|
|
||||||
|
Here is an example,
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "example_function_name",
|
||||||
|
"parameters": {"example_name": "example_value"}
|
||||||
|
}
|
||||||
|
|
||||||
|
Reminder:
|
||||||
|
- Function calls MUST follow the specified format
|
||||||
|
- Required parameters MUST be specified
|
||||||
|
- Only call one function at a time
|
||||||
|
- You SHOULD NOT include any other text in the response
|
||||||
|
- Put the entire function call reply on one line
|
||||||
|
|
||||||
|
Here is a list of functions in JSON format that you can invoke.
|
||||||
|
|
||||||
|
${JSON.stringify(tools)}
|
||||||
|
`;
|
||||||
|
};
|
||||||
|
|
||||||
export const mapChatRoleToMetaRole = (
|
export const mapChatRoleToMetaRole = (
|
||||||
role: ChatMessage["role"],
|
role: ChatMessage["role"],
|
||||||
): MetaMessage["role"] => {
|
): MetaMessage["role"] => {
|
||||||
@@ -125,16 +168,46 @@ export const mapChatMessagesToMetaMessages = <
|
|||||||
/**
|
/**
|
||||||
* Documentation at https://llama.meta.com/docs/model-cards-and-prompt-formats/meta-llama-3
|
* Documentation at https://llama.meta.com/docs/model-cards-and-prompt-formats/meta-llama-3
|
||||||
*/
|
*/
|
||||||
export const mapChatMessagesToMetaLlama3Messages = <T extends ChatMessage>(
|
export const mapChatMessagesToMetaLlama3Messages = <T extends ChatMessage>({
|
||||||
messages: T[],
|
messages,
|
||||||
tools?: BaseTool[],
|
model,
|
||||||
): string => {
|
tools,
|
||||||
|
}: {
|
||||||
|
messages: T[];
|
||||||
|
model: LLMMetadata["model"];
|
||||||
|
tools?: BaseTool[];
|
||||||
|
}): { prompt: string; images: string[] } => {
|
||||||
|
const images: string[] = [];
|
||||||
|
const textMessages: T[] = [];
|
||||||
|
|
||||||
|
messages.forEach((message) => {
|
||||||
|
if (Array.isArray(message.content)) {
|
||||||
|
message.content.forEach((content) => {
|
||||||
|
if (content.type === "image_url") {
|
||||||
|
const { base64 } = extractDataUrlComponents(content.image_url.url);
|
||||||
|
images.push(base64);
|
||||||
|
} else {
|
||||||
|
textMessages.push(message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
textMessages.push(message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const parts: string[] = [];
|
const parts: string[] = [];
|
||||||
if (tools?.length) {
|
|
||||||
|
let toolsPrompt = "";
|
||||||
|
if (model.startsWith("meta.llama3-2")) {
|
||||||
|
toolsPrompt = getToolsPrompt_3_2(tools);
|
||||||
|
} else if (model.startsWith("meta.llama3-1")) {
|
||||||
|
toolsPrompt = getToolsPrompt_3_1(tools);
|
||||||
|
}
|
||||||
|
if (toolsPrompt) {
|
||||||
parts.push(
|
parts.push(
|
||||||
"<|begin_of_text|>",
|
"<|begin_of_text|>",
|
||||||
"<|start_header_id|>system<|end_header_id|>",
|
"<|start_header_id|>system<|end_header_id|>",
|
||||||
getToolsPrompt(tools),
|
toolsPrompt,
|
||||||
"<|eot_id|>",
|
"<|eot_id|>",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -154,7 +227,9 @@ export const mapChatMessagesToMetaLlama3Messages = <T extends ChatMessage>(
|
|||||||
...mapped,
|
...mapped,
|
||||||
"<|start_header_id|>assistant<|end_header_id|>",
|
"<|start_header_id|>assistant<|end_header_id|>",
|
||||||
);
|
);
|
||||||
return parts.join("\n");
|
|
||||||
|
const prompt = parts.join("\n");
|
||||||
|
return { prompt, images };
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -11,3 +11,24 @@ export const mapMessageContentToMessageContentDetails = (
|
|||||||
|
|
||||||
export const toUtf8 = (input: Uint8Array): string =>
|
export const toUtf8 = (input: Uint8Array): string =>
|
||||||
new TextDecoder("utf-8").decode(input);
|
new TextDecoder("utf-8").decode(input);
|
||||||
|
|
||||||
|
export const extractDataUrlComponents = (
|
||||||
|
dataUrl: string,
|
||||||
|
): {
|
||||||
|
mimeType: string;
|
||||||
|
base64: string;
|
||||||
|
} => {
|
||||||
|
const parts = dataUrl.split(";base64,");
|
||||||
|
|
||||||
|
if (parts.length !== 2 || !parts[0]!.startsWith("data:")) {
|
||||||
|
throw new Error("Invalid data URL");
|
||||||
|
}
|
||||||
|
|
||||||
|
const mimeType = parts[0]!.slice(5);
|
||||||
|
const base64 = parts[1]!;
|
||||||
|
|
||||||
|
return {
|
||||||
|
mimeType,
|
||||||
|
base64,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|||||||
@@ -0,0 +1,165 @@
|
|||||||
|
import type { KnowledgeBaseVectorSearchConfiguration } from "@aws-sdk/client-bedrock-agent-runtime";
|
||||||
|
import {
|
||||||
|
BedrockAgentRuntimeClient,
|
||||||
|
type BedrockAgentRuntimeClientConfig,
|
||||||
|
type RetrievalFilter,
|
||||||
|
RetrieveCommand,
|
||||||
|
type SearchType,
|
||||||
|
} from "@aws-sdk/client-bedrock-agent-runtime";
|
||||||
|
import type { QueryBundle } from "@llamaindex/core/query-engine";
|
||||||
|
import { BaseRetriever } from "@llamaindex/core/retriever";
|
||||||
|
import { Document, type NodeWithScore } from "@llamaindex/core/schema";
|
||||||
|
import { extractText } from "@llamaindex/core/utils";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for the arguments required to initialize an
|
||||||
|
* AmazonKnowledgeBaseRetriever instance.
|
||||||
|
*/
|
||||||
|
export interface AmazonKnowledgeBaseRetrieverArgs {
|
||||||
|
knowledgeBaseId: string;
|
||||||
|
topK: number;
|
||||||
|
region: string;
|
||||||
|
clientOptions?: BedrockAgentRuntimeClientConfig;
|
||||||
|
filter?: RetrievalFilter;
|
||||||
|
overrideSearchType?: SearchType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class for interacting with Amazon Bedrock Knowledge Bases, a RAG workflow oriented service
|
||||||
|
* Extends the BaseRetriever class.
|
||||||
|
* @example
|
||||||
|
* ```typescript
|
||||||
|
* const retriever = new AmazonKnowledgeBaseRetriever({
|
||||||
|
* topK: 10,
|
||||||
|
* knowledgeBaseId: "YOUR_KNOWLEDGE_BASE_ID",
|
||||||
|
* region: "us-east-2",
|
||||||
|
* clientOptions: {
|
||||||
|
* credentials: {
|
||||||
|
* accessKeyId: "YOUR_ACCESS_KEY_ID",
|
||||||
|
* secretAccessKey: "YOUR_SECRET_ACCESS_KEY",
|
||||||
|
* },
|
||||||
|
* },
|
||||||
|
* });
|
||||||
|
*
|
||||||
|
* const docs = await retriever.retrieve({query: "How are clouds formed?"});
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export class AmazonKnowledgeBaseRetriever extends BaseRetriever {
|
||||||
|
static lc_name() {
|
||||||
|
return "AmazonKnowledgeBaseRetriever";
|
||||||
|
}
|
||||||
|
|
||||||
|
lc_namespace = ["llamaindex", "retrievers", "amazon_bedrock_knowledge_base"];
|
||||||
|
|
||||||
|
knowledgeBaseId: string;
|
||||||
|
|
||||||
|
topK: number;
|
||||||
|
|
||||||
|
bedrockAgentRuntimeClient: BedrockAgentRuntimeClient;
|
||||||
|
|
||||||
|
filter: RetrievalFilter | undefined;
|
||||||
|
|
||||||
|
overrideSearchType: SearchType | undefined;
|
||||||
|
|
||||||
|
constructor({
|
||||||
|
knowledgeBaseId,
|
||||||
|
topK = 10,
|
||||||
|
clientOptions,
|
||||||
|
region,
|
||||||
|
filter,
|
||||||
|
overrideSearchType,
|
||||||
|
}: AmazonKnowledgeBaseRetrieverArgs) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.topK = topK;
|
||||||
|
this.filter = filter;
|
||||||
|
this.overrideSearchType = overrideSearchType;
|
||||||
|
this.bedrockAgentRuntimeClient = new BedrockAgentRuntimeClient({
|
||||||
|
region,
|
||||||
|
...clientOptions,
|
||||||
|
});
|
||||||
|
this.knowledgeBaseId = knowledgeBaseId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cleans the result text by replacing sequences of whitespace with a
|
||||||
|
* single space and removing ellipses.
|
||||||
|
* @param resText The result text to clean.
|
||||||
|
* @returns The cleaned result text.
|
||||||
|
*/
|
||||||
|
cleanResult(resText: string) {
|
||||||
|
const res = resText.replace(/\s+/g, " ").replace(/\.\.\./g, "");
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
async queryKnowledgeBase(
|
||||||
|
query: QueryBundle,
|
||||||
|
topK: number,
|
||||||
|
filter?: RetrievalFilter,
|
||||||
|
overrideSearchType?: SearchType,
|
||||||
|
): Promise<NodeWithScore[]> {
|
||||||
|
const retrieveCommand = new RetrieveCommand({
|
||||||
|
knowledgeBaseId: this.knowledgeBaseId,
|
||||||
|
retrievalQuery: {
|
||||||
|
text: extractText(query),
|
||||||
|
},
|
||||||
|
retrievalConfiguration: {
|
||||||
|
vectorSearchConfiguration: {
|
||||||
|
numberOfResults: topK,
|
||||||
|
overrideSearchType,
|
||||||
|
filter,
|
||||||
|
} as KnowledgeBaseVectorSearchConfiguration,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const retrieveResponse =
|
||||||
|
await this.bedrockAgentRuntimeClient.send(retrieveCommand);
|
||||||
|
|
||||||
|
return (
|
||||||
|
retrieveResponse.retrievalResults?.map((result) => {
|
||||||
|
let source;
|
||||||
|
switch (result.location?.type) {
|
||||||
|
case "CONFLUENCE":
|
||||||
|
source = result.location?.confluenceLocation?.url;
|
||||||
|
break;
|
||||||
|
case "S3":
|
||||||
|
source = result.location?.s3Location?.uri;
|
||||||
|
break;
|
||||||
|
case "SALESFORCE":
|
||||||
|
source = result.location?.salesforceLocation?.url;
|
||||||
|
break;
|
||||||
|
case "SHAREPOINT":
|
||||||
|
source = result.location?.sharePointLocation?.url;
|
||||||
|
break;
|
||||||
|
case "WEB":
|
||||||
|
source = result.location?.webLocation?.url;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
source = result.location?.s3Location?.uri;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
node: new Document({
|
||||||
|
text: this.cleanResult(result.content?.text || ""),
|
||||||
|
metadata: {
|
||||||
|
source,
|
||||||
|
score: result.score,
|
||||||
|
...result.metadata,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
score: result.score ?? 1.0,
|
||||||
|
};
|
||||||
|
}) ?? []
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async _retrieve(query: QueryBundle): Promise<NodeWithScore[]> {
|
||||||
|
return await this.queryKnowledgeBase(
|
||||||
|
query,
|
||||||
|
this.topK,
|
||||||
|
this.filter,
|
||||||
|
this.overrideSearchType,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,98 @@
|
|||||||
# @llamaindex/core
|
# @llamaindex/core
|
||||||
|
|
||||||
|
## 0.3.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- a75af83: refactor: move some llm and embedding to single package
|
||||||
|
- Updated dependencies [ae49ff4]
|
||||||
|
- Updated dependencies [a75af83]
|
||||||
|
- @llamaindex/env@0.1.14
|
||||||
|
|
||||||
|
## 0.3.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- 1364e8e: update metadata extractors to use PromptTemplate
|
||||||
|
- 96fc69c: add defaultQuestionExtractPrompt
|
||||||
|
|
||||||
|
## 0.2.12
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 5f67820: Fix that node parsers generate nodes with UUIDs
|
||||||
|
|
||||||
|
## 0.2.11
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- ee697fb: fix: generate uuid when inserting to Qdrant
|
||||||
|
|
||||||
|
## 0.2.10
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 3489e7d: fix: num output incorrect in prompt helper
|
||||||
|
- 468bda5: fix: correct warning when chunk size smaller than 0
|
||||||
|
|
||||||
|
## 0.2.9
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- b17d439: Fix #1278: resolved issue where the id\_ was not correctly passed as the id when creating a TextNode. As a result, the upsert operation to the vector database was using a generated ID instead of the provided document ID, if available.
|
||||||
|
|
||||||
|
## 0.2.8
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- df441e2: fix: consoleLogger is missing from `@llamaindex/env`
|
||||||
|
- Updated dependencies [df441e2]
|
||||||
|
- @llamaindex/env@0.1.13
|
||||||
|
|
||||||
|
## 0.2.7
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 6cce3b1: feat: support `npm:postgres`
|
||||||
|
|
||||||
|
## 0.2.6
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 8b7fdba: refactor: move chat engine & retriever into core.
|
||||||
|
|
||||||
|
- `chatHistory` in BaseChatEngine now returns `ChatMessage[] | Promise<ChatMessage[]>`, instead of `BaseMemory`
|
||||||
|
- update `retrieve-end` type
|
||||||
|
|
||||||
|
## 0.2.5
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- d902cc3: Fix context not being sent using ContextChatEngine
|
||||||
|
|
||||||
|
## 0.2.4
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- b48bcc3: feat: add `load-transformers` event type when loading `@xenova/transformers` module
|
||||||
|
|
||||||
|
This would benefit user who want to customize the transformer env.
|
||||||
|
|
||||||
|
- Updated dependencies [b48bcc3]
|
||||||
|
- @llamaindex/env@0.1.12
|
||||||
|
|
||||||
|
## 0.2.3
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 2cd1383: refactor: align `response-synthesizers` & `chat-engine` module
|
||||||
|
|
||||||
|
- builtin event system
|
||||||
|
- correct class extends
|
||||||
|
- aligin APIs, naming with llama-index python
|
||||||
|
- move stream out of first parameter to second parameter for the better tyep checking
|
||||||
|
- remove JSONQueryEngine in `@llamaindex/experimental`, as the code quality is not satisify and we will bring it back later
|
||||||
|
|
||||||
## 0.2.2
|
## 0.2.2
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"type": "module",
|
||||||
|
"main": "./dist/index.cjs",
|
||||||
|
"module": "./dist/index.js",
|
||||||
|
"types": "./dist/index.d.ts",
|
||||||
|
"exports": "./dist/index.js",
|
||||||
|
"private": true
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"type": "module",
|
||||||
|
"main": "./dist/index.cjs",
|
||||||
|
"module": "./dist/index.js",
|
||||||
|
"types": "./dist/index.d.ts",
|
||||||
|
"exports": "./dist/index.js",
|
||||||
|
"private": true
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"type": "module",
|
||||||
|
"main": "./dist/index.cjs",
|
||||||
|
"module": "./dist/index.js",
|
||||||
|
"types": "./dist/index.d.ts",
|
||||||
|
"exports": "./dist/index.js",
|
||||||
|
"private": true
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"type": "module",
|
||||||
|
"main": "./dist/index.cjs",
|
||||||
|
"module": "./dist/index.js",
|
||||||
|
"types": "./dist/index.d.ts",
|
||||||
|
"exports": "./dist/index.js",
|
||||||
|
"private": true
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"type": "module",
|
||||||
|
"main": "./dist/index.cjs",
|
||||||
|
"module": "./dist/index.js",
|
||||||
|
"types": "./dist/index.d.ts",
|
||||||
|
"exports": "./dist/index.js",
|
||||||
|
"private": true
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"type": "module",
|
||||||
|
"main": "./dist/index.cjs",
|
||||||
|
"module": "./dist/index.js",
|
||||||
|
"types": "./dist/index.d.ts",
|
||||||
|
"exports": "./dist/index.js",
|
||||||
|
"private": true
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"type": "module",
|
||||||
|
"main": "./dist/index.cjs",
|
||||||
|
"module": "./dist/index.js",
|
||||||
|
"types": "./dist/index.d.ts",
|
||||||
|
"exports": "./dist/index.js",
|
||||||
|
"private": true
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"type": "module",
|
||||||
|
"main": "./dist/index.cjs",
|
||||||
|
"module": "./dist/index.js",
|
||||||
|
"types": "./dist/index.d.ts",
|
||||||
|
"exports": "./dist/index.js",
|
||||||
|
"private": true
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"type": "module",
|
||||||
|
"main": "./dist/index.cjs",
|
||||||
|
"module": "./dist/index.js",
|
||||||
|
"types": "./dist/index.d.ts",
|
||||||
|
"exports": "./dist/index.js",
|
||||||
|
"private": true
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"type": "module",
|
||||||
|
"main": "./dist/index.cjs",
|
||||||
|
"module": "./dist/index.js",
|
||||||
|
"types": "./dist/index.d.ts",
|
||||||
|
"exports": "./dist/index.js",
|
||||||
|
"private": true
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"type": "module",
|
||||||
|
"main": "./dist/index.cjs",
|
||||||
|
"module": "./dist/index.js",
|
||||||
|
"types": "./dist/index.d.ts",
|
||||||
|
"exports": "./dist/index.js",
|
||||||
|
"private": true
|
||||||
|
}
|
||||||
+218
-84
@@ -1,194 +1,326 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/core",
|
"name": "@llamaindex/core",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "0.2.2",
|
"version": "0.3.1",
|
||||||
"description": "LlamaIndex Core Module",
|
"description": "LlamaIndex Core Module",
|
||||||
"exports": {
|
"exports": {
|
||||||
"./node-parser": {
|
"./agent": {
|
||||||
"require": {
|
"require": {
|
||||||
"types": "./dist/node-parser/index.d.cts",
|
"types": "./agent/dist/index.d.cts",
|
||||||
"default": "./dist/node-parser/index.cjs"
|
"default": "./agent/dist/index.cjs"
|
||||||
},
|
},
|
||||||
"import": {
|
"import": {
|
||||||
"types": "./dist/node-parser/index.d.ts",
|
"types": "./agent/dist/index.d.ts",
|
||||||
"default": "./dist/node-parser/index.js"
|
"default": "./agent/dist/index.js"
|
||||||
},
|
},
|
||||||
"default": {
|
"default": {
|
||||||
"types": "./dist/node-parser/index.d.ts",
|
"types": "./agent/dist/index.d.ts",
|
||||||
"default": "./dist/node-parser/index.js"
|
"default": "./agent/dist/index.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"./objects": {
|
||||||
|
"require": {
|
||||||
|
"types": "./objects/dist/index.d.cts",
|
||||||
|
"default": "./objects/dist/index.cjs"
|
||||||
|
},
|
||||||
|
"import": {
|
||||||
|
"types": "./objects/dist/index.d.ts",
|
||||||
|
"default": "./objects/dist/index.js"
|
||||||
|
},
|
||||||
|
"default": {
|
||||||
|
"types": "./objects/dist/index.d.ts",
|
||||||
|
"default": "./objects/dist/index.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"./node-parser": {
|
||||||
|
"require": {
|
||||||
|
"types": "./node-parser/dist/index.d.cts",
|
||||||
|
"default": "./node-parser/dist/index.cjs"
|
||||||
|
},
|
||||||
|
"import": {
|
||||||
|
"types": "./node-parser/dist/index.d.ts",
|
||||||
|
"default": "./node-parser/dist/index.js"
|
||||||
|
},
|
||||||
|
"default": {
|
||||||
|
"types": "./node-parser/dist/index.d.ts",
|
||||||
|
"default": "./node-parser/dist/index.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"./query-engine": {
|
"./query-engine": {
|
||||||
"require": {
|
"require": {
|
||||||
"types": "./dist/query-engine/index.d.cts",
|
"types": "./query-engine/dist/index.d.cts",
|
||||||
"default": "./dist/query-engine/index.cjs"
|
"default": "./query-engine/dist/index.cjs"
|
||||||
},
|
},
|
||||||
"import": {
|
"import": {
|
||||||
"types": "./dist/query-engine/index.d.ts",
|
"types": "./query-engine/dist/index.d.ts",
|
||||||
"default": "./dist/query-engine/index.js"
|
"default": "./query-engine/dist/index.js"
|
||||||
},
|
},
|
||||||
"default": {
|
"default": {
|
||||||
"types": "./dist/query-engine/index.d.ts",
|
"types": "./query-engine/dist/index.d.ts",
|
||||||
"default": "./dist/query-engine/index.js"
|
"default": "./query-engine/dist/index.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"./llms": {
|
"./llms": {
|
||||||
"require": {
|
"require": {
|
||||||
"types": "./dist/llms/index.d.cts",
|
"types": "./llms/dist/index.d.cts",
|
||||||
"default": "./dist/llms/index.cjs"
|
"default": "./llms/dist/index.cjs"
|
||||||
},
|
},
|
||||||
"import": {
|
"import": {
|
||||||
"types": "./dist/llms/index.d.ts",
|
"types": "./llms/dist/index.d.ts",
|
||||||
"default": "./dist/llms/index.js"
|
"default": "./llms/dist/index.js"
|
||||||
},
|
},
|
||||||
"default": {
|
"default": {
|
||||||
"types": "./dist/llms/index.d.ts",
|
"types": "./llms/dist/index.d.ts",
|
||||||
"default": "./dist/llms/index.js"
|
"default": "./llms/dist/index.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"./decorator": {
|
"./decorator": {
|
||||||
"require": {
|
"require": {
|
||||||
"types": "./dist/decorator/index.d.cts",
|
"types": "./decorator/dist/index.d.cts",
|
||||||
"default": "./dist/decorator/index.cjs"
|
"default": "./decorator/dist/index.cjs"
|
||||||
},
|
},
|
||||||
"import": {
|
"import": {
|
||||||
"types": "./dist/decorator/index.d.ts",
|
"types": "./decorator/dist/index.d.ts",
|
||||||
"default": "./dist/decorator/index.js"
|
"default": "./decorator/dist/index.js"
|
||||||
},
|
},
|
||||||
"default": {
|
"default": {
|
||||||
"types": "./dist/decorator/index.d.ts",
|
"types": "./decorator/dist/index.d.ts",
|
||||||
"default": "./dist/decorator/index.js"
|
"default": "./decorator/dist/index.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"./embeddings": {
|
"./embeddings": {
|
||||||
"require": {
|
"require": {
|
||||||
"types": "./dist/embeddings/index.d.cts",
|
"types": "./embeddings/dist/index.d.cts",
|
||||||
"default": "./dist/embeddings/index.cjs"
|
"default": "./embeddings/dist/index.cjs"
|
||||||
},
|
},
|
||||||
"import": {
|
"import": {
|
||||||
"types": "./dist/embeddings/index.d.ts",
|
"types": "./embeddings/dist/index.d.ts",
|
||||||
"default": "./dist/embeddings/index.js"
|
"default": "./embeddings/dist/index.js"
|
||||||
},
|
},
|
||||||
"default": {
|
"default": {
|
||||||
"types": "./dist/embeddings/index.d.ts",
|
"types": "./embeddings/dist/index.d.ts",
|
||||||
"default": "./dist/embeddings/index.js"
|
"default": "./embeddings/dist/index.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"./global": {
|
"./global": {
|
||||||
"require": {
|
"require": {
|
||||||
"types": "./dist/global/index.d.cts",
|
"types": "./global/dist/index.d.cts",
|
||||||
"default": "./dist/global/index.cjs"
|
"default": "./global/dist/index.cjs"
|
||||||
},
|
},
|
||||||
"import": {
|
"import": {
|
||||||
"types": "./dist/global/index.d.ts",
|
"types": "./global/dist/index.d.ts",
|
||||||
"default": "./dist/global/index.js"
|
"default": "./global/dist/index.js"
|
||||||
},
|
},
|
||||||
"default": {
|
"default": {
|
||||||
"types": "./dist/global/index.d.ts",
|
"types": "./global/dist/index.d.ts",
|
||||||
"default": "./dist/global/index.js"
|
"default": "./global/dist/index.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"./schema": {
|
"./schema": {
|
||||||
"require": {
|
"require": {
|
||||||
"types": "./dist/schema/index.d.cts",
|
"types": "./schema/dist/index.d.cts",
|
||||||
"default": "./dist/schema/index.cjs"
|
"default": "./schema/dist/index.cjs"
|
||||||
},
|
},
|
||||||
"import": {
|
"import": {
|
||||||
"types": "./dist/schema/index.d.ts",
|
"types": "./schema/dist/index.d.ts",
|
||||||
"default": "./dist/schema/index.js"
|
"default": "./schema/dist/index.js"
|
||||||
},
|
},
|
||||||
"default": {
|
"default": {
|
||||||
"types": "./dist/schema/index.d.ts",
|
"types": "./schema/dist/index.d.ts",
|
||||||
"default": "./dist/schema/index.js"
|
"default": "./schema/dist/index.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"./utils": {
|
"./utils": {
|
||||||
"require": {
|
"require": {
|
||||||
"types": "./dist/utils/index.d.cts",
|
"types": "./utils/dist/index.d.cts",
|
||||||
"default": "./dist/utils/index.cjs"
|
"default": "./utils/dist/index.cjs"
|
||||||
},
|
},
|
||||||
"import": {
|
"import": {
|
||||||
"types": "./dist/utils/index.d.ts",
|
"types": "./utils/dist/index.d.ts",
|
||||||
"default": "./dist/utils/index.js"
|
"default": "./utils/dist/index.js"
|
||||||
},
|
},
|
||||||
"default": {
|
"default": {
|
||||||
"types": "./dist/utils/index.d.ts",
|
"types": "./utils/dist/index.d.ts",
|
||||||
"default": "./dist/utils/index.js"
|
"default": "./utils/dist/index.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"./prompts": {
|
"./prompts": {
|
||||||
"require": {
|
"require": {
|
||||||
"types": "./dist/prompts/index.d.cts",
|
"types": "./prompts/dist/index.d.cts",
|
||||||
"default": "./dist/prompts/index.cjs"
|
"default": "./prompts/dist/index.cjs"
|
||||||
},
|
},
|
||||||
"import": {
|
"import": {
|
||||||
"types": "./dist/prompts/index.d.ts",
|
"types": "./prompts/dist/index.d.ts",
|
||||||
"default": "./dist/prompts/index.js"
|
"default": "./prompts/dist/index.js"
|
||||||
},
|
},
|
||||||
"default": {
|
"default": {
|
||||||
"types": "./dist/prompts/index.d.ts",
|
"types": "./prompts/dist/index.d.ts",
|
||||||
"default": "./dist/prompts/index.js"
|
"default": "./prompts/dist/index.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"./indices": {
|
"./indices": {
|
||||||
"require": {
|
"require": {
|
||||||
"types": "./dist/indices/index.d.cts",
|
"types": "./indices/dist/index.d.cts",
|
||||||
"default": "./dist/indices/index.cjs"
|
"default": "./indices/dist/index.cjs"
|
||||||
},
|
},
|
||||||
"import": {
|
"import": {
|
||||||
"types": "./dist/indices/index.d.ts",
|
"types": "./indices/dist/index.d.ts",
|
||||||
"default": "./dist/indices/index.js"
|
"default": "./indices/dist/index.js"
|
||||||
},
|
},
|
||||||
"default": {
|
"default": {
|
||||||
"types": "./dist/indices/index.d.ts",
|
"types": "./indices/dist/index.d.ts",
|
||||||
"default": "./dist/indices/index.js"
|
"default": "./indices/dist/index.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"./workflow": {
|
"./workflow": {
|
||||||
"require": {
|
"require": {
|
||||||
"types": "./dist/workflow/index.d.cts",
|
"types": "./workflow/dist/index.d.cts",
|
||||||
"default": "./dist/workflow/index.cjs"
|
"default": "./workflow/dist/index.cjs"
|
||||||
},
|
},
|
||||||
"import": {
|
"import": {
|
||||||
"types": "./dist/workflow/index.d.ts",
|
"types": "./workflow/dist/index.d.ts",
|
||||||
"default": "./dist/workflow/index.js"
|
"default": "./workflow/dist/index.js"
|
||||||
},
|
},
|
||||||
"default": {
|
"default": {
|
||||||
"types": "./dist/workflow/index.d.ts",
|
"types": "./workflow/dist/index.d.ts",
|
||||||
"default": "./dist/workflow/index.js"
|
"default": "./workflow/dist/index.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"./memory": {
|
"./memory": {
|
||||||
"require": {
|
"require": {
|
||||||
"types": "./dist/memory/index.d.cts",
|
"types": "./memory/dist/index.d.cts",
|
||||||
"default": "./dist/memory/index.cjs"
|
"default": "./memory/dist/index.cjs"
|
||||||
},
|
},
|
||||||
"import": {
|
"import": {
|
||||||
"types": "./dist/memory/index.d.ts",
|
"types": "./memory/dist/index.d.ts",
|
||||||
"default": "./dist/memory/index.js"
|
"default": "./memory/dist/index.js"
|
||||||
},
|
},
|
||||||
"default": {
|
"default": {
|
||||||
"types": "./dist/memory/index.d.ts",
|
"types": "./memory/dist/index.d.ts",
|
||||||
"default": "./dist/memory/index.js"
|
"default": "./memory/dist/index.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"./storage/chat-store": {
|
"./storage/chat-store": {
|
||||||
"require": {
|
"require": {
|
||||||
"types": "./dist/storage/chat-store/index.d.cts",
|
"types": "./storage/chat-store/dist/index.d.cts",
|
||||||
"default": "./dist/storage/chat-store/index.cjs"
|
"default": "./storage/chat-store/dist/index.cjs"
|
||||||
},
|
},
|
||||||
"import": {
|
"import": {
|
||||||
"types": "./dist/storage/chat-store/index.d.ts",
|
"types": "./storage/chat-store/dist/index.d.ts",
|
||||||
"default": "./dist/storage/chat-store/index.js"
|
"default": "./storage/chat-store/dist/index.js"
|
||||||
},
|
},
|
||||||
"default": {
|
"default": {
|
||||||
"types": "./dist/storage/chat-store/index.d.ts",
|
"types": "./storage/chat-store/dist/index.d.ts",
|
||||||
"default": "./dist/storage/chat-store/index.js"
|
"default": "./storage/chat-store/dist/index.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"./response-synthesizers": {
|
||||||
|
"require": {
|
||||||
|
"types": "./response-synthesizers/dist/index.d.cts",
|
||||||
|
"default": "./response-synthesizers/dist/index.cjs"
|
||||||
|
},
|
||||||
|
"import": {
|
||||||
|
"types": "./response-synthesizers/dist/index.d.ts",
|
||||||
|
"default": "./response-synthesizers/dist/index.js"
|
||||||
|
},
|
||||||
|
"default": {
|
||||||
|
"types": "./response-synthesizers/dist/index.d.ts",
|
||||||
|
"default": "./response-synthesizers/dist/index.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"./chat-engine": {
|
||||||
|
"require": {
|
||||||
|
"types": "./chat-engine/dist/index.d.cts",
|
||||||
|
"default": "./chat-engine/dist/index.cjs"
|
||||||
|
},
|
||||||
|
"import": {
|
||||||
|
"types": "./chat-engine/dist/index.d.ts",
|
||||||
|
"default": "./chat-engine/dist/index.js"
|
||||||
|
},
|
||||||
|
"default": {
|
||||||
|
"types": "./chat-engine/dist/index.d.ts",
|
||||||
|
"default": "./chat-engine/dist/index.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"./retriever": {
|
||||||
|
"require": {
|
||||||
|
"types": "./retriever/dist/index.d.cts",
|
||||||
|
"default": "./retriever/dist/index.cjs"
|
||||||
|
},
|
||||||
|
"import": {
|
||||||
|
"types": "./retriever/dist/index.d.ts",
|
||||||
|
"default": "./retriever/dist/index.js"
|
||||||
|
},
|
||||||
|
"default": {
|
||||||
|
"types": "./retriever/dist/index.d.ts",
|
||||||
|
"default": "./retriever/dist/index.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"./vector-store": {
|
||||||
|
"require": {
|
||||||
|
"types": "./vector-store/dist/index.d.cts",
|
||||||
|
"default": "./vector-store/dist/index.cjs"
|
||||||
|
},
|
||||||
|
"import": {
|
||||||
|
"types": "./vector-store/dist/index.d.ts",
|
||||||
|
"default": "./vector-store/dist/index.js"
|
||||||
|
},
|
||||||
|
"default": {
|
||||||
|
"types": "./vector-store/dist/index.d.ts",
|
||||||
|
"default": "./vector-store/dist/index.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"./tools": {
|
||||||
|
"require": {
|
||||||
|
"types": "./tools/dist/index.d.cts",
|
||||||
|
"default": "./tools/dist/index.cjs"
|
||||||
|
},
|
||||||
|
"import": {
|
||||||
|
"types": "./tools/dist/index.d.ts",
|
||||||
|
"default": "./tools/dist/index.js"
|
||||||
|
},
|
||||||
|
"default": {
|
||||||
|
"types": "./tools/dist/index.d.ts",
|
||||||
|
"default": "./tools/dist/index.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"./data-structs": {
|
||||||
|
"require": {
|
||||||
|
"types": "./data-structs/dist/index.d.cts",
|
||||||
|
"default": "./data-structs/dist/index.cjs"
|
||||||
|
},
|
||||||
|
"import": {
|
||||||
|
"types": "./data-structs/dist/index.d.ts",
|
||||||
|
"default": "./data-structs/dist/index.js"
|
||||||
|
},
|
||||||
|
"default": {
|
||||||
|
"types": "./data-structs/dist/index.d.ts",
|
||||||
|
"default": "./data-structs/dist/index.js"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"dist"
|
"./agent",
|
||||||
|
"./objects",
|
||||||
|
"./node-parser",
|
||||||
|
"./query-engine",
|
||||||
|
"./llms",
|
||||||
|
"./decorator",
|
||||||
|
"./embeddings",
|
||||||
|
"./global",
|
||||||
|
"./schema",
|
||||||
|
"./utils",
|
||||||
|
"./prompts",
|
||||||
|
"./indices",
|
||||||
|
"./workflow",
|
||||||
|
"./memory",
|
||||||
|
"./storage",
|
||||||
|
"./response-synthesizers",
|
||||||
|
"./chat-engine",
|
||||||
|
"./retriever",
|
||||||
|
"./vector-store",
|
||||||
|
"./tools",
|
||||||
|
"./data-structs"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "bunchee --watch",
|
"dev": "bunchee --watch",
|
||||||
@@ -197,12 +329,12 @@
|
|||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"directory": "packages/core",
|
"directory": "packages/core",
|
||||||
"url": "https://github.com/himself65/LlamaIndexTS.git"
|
"url": "https://github.com/run-llama/LlamaIndexTS.git"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@edge-runtime/vm": "^4.0.3",
|
"@edge-runtime/vm": "^4.0.3",
|
||||||
"ajv": "^8.17.1",
|
"ajv": "^8.17.1",
|
||||||
"bunchee": "5.3.2",
|
"bunchee": "5.5.1",
|
||||||
"happy-dom": "^15.7.4",
|
"happy-dom": "^15.7.4",
|
||||||
"natural": "^8.0.1",
|
"natural": "^8.0.1",
|
||||||
"python-format-js": "^1.4.3"
|
"python-format-js": "^1.4.3"
|
||||||
@@ -210,6 +342,8 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@llamaindex/env": "workspace:*",
|
"@llamaindex/env": "workspace:*",
|
||||||
"@types/node": "^22.5.1",
|
"@types/node": "^22.5.1",
|
||||||
"zod": "^3.23.8"
|
"magic-bytes.js": "^1.10.0",
|
||||||
|
"zod": "^3.23.8",
|
||||||
|
"zod-to-json-schema": "^3.23.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"type": "module",
|
||||||
|
"main": "./dist/index.cjs",
|
||||||
|
"module": "./dist/index.js",
|
||||||
|
"types": "./dist/index.d.ts",
|
||||||
|
"exports": "./dist/index.js",
|
||||||
|
"private": true
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"type": "module",
|
||||||
|
"main": "./dist/index.cjs",
|
||||||
|
"module": "./dist/index.js",
|
||||||
|
"types": "./dist/index.d.ts",
|
||||||
|
"exports": "./dist/index.js",
|
||||||
|
"private": true
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"type": "module",
|
||||||
|
"main": "./dist/index.cjs",
|
||||||
|
"module": "./dist/index.js",
|
||||||
|
"types": "./dist/index.d.ts",
|
||||||
|
"exports": "./dist/index.js",
|
||||||
|
"private": true
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"type": "module",
|
||||||
|
"main": "./dist/index.cjs",
|
||||||
|
"module": "./dist/index.js",
|
||||||
|
"types": "./dist/index.d.ts",
|
||||||
|
"exports": "./dist/index.js",
|
||||||
|
"private": true
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"type": "module",
|
||||||
|
"main": "./dist/index.cjs",
|
||||||
|
"module": "./dist/index.js",
|
||||||
|
"types": "./dist/index.d.ts",
|
||||||
|
"exports": "./dist/index.js",
|
||||||
|
"private": true
|
||||||
|
}
|
||||||
@@ -1,23 +1,21 @@
|
|||||||
|
import { consoleLogger, emptyLogger, randomUUID } from "@llamaindex/env";
|
||||||
|
import {
|
||||||
|
BaseChatEngine,
|
||||||
|
type NonStreamingChatEngineParams,
|
||||||
|
type StreamingChatEngineParams,
|
||||||
|
} from "../chat-engine";
|
||||||
|
import { wrapEventCaller } from "../decorator";
|
||||||
|
import { Settings } from "../global";
|
||||||
import type {
|
import type {
|
||||||
BaseToolWithCall,
|
BaseToolWithCall,
|
||||||
ChatMessage,
|
ChatMessage,
|
||||||
LLM,
|
LLM,
|
||||||
MessageContent,
|
MessageContent,
|
||||||
ToolOutput,
|
ToolOutput,
|
||||||
} from "@llamaindex/core/llms";
|
} from "../llms";
|
||||||
import { BaseMemory } from "@llamaindex/core/memory";
|
import { BaseMemory } from "../memory";
|
||||||
import { EngineResponse } from "@llamaindex/core/schema";
|
import type { ObjectRetriever } from "../objects";
|
||||||
import { wrapEventCaller } from "@llamaindex/core/utils";
|
import { EngineResponse } from "../schema";
|
||||||
import { randomUUID } from "@llamaindex/env";
|
|
||||||
import { Settings } from "../Settings.js";
|
|
||||||
import {
|
|
||||||
type ChatEngine,
|
|
||||||
type ChatEngineParamsNonStreaming,
|
|
||||||
type ChatEngineParamsStreaming,
|
|
||||||
} from "../engines/chat/index.js";
|
|
||||||
import { consoleLogger, emptyLogger } from "../internal/logger.js";
|
|
||||||
import { isReadableStream } from "../internal/utils.js";
|
|
||||||
import { ObjectRetriever } from "../objects/index.js";
|
|
||||||
import type {
|
import type {
|
||||||
AgentTaskContext,
|
AgentTaskContext,
|
||||||
TaskHandler,
|
TaskHandler,
|
||||||
@@ -207,8 +205,7 @@ export abstract class AgentRunner<
|
|||||||
>
|
>
|
||||||
? AdditionalMessageOptions
|
? AdditionalMessageOptions
|
||||||
: never,
|
: never,
|
||||||
> implements ChatEngine
|
> extends BaseChatEngine {
|
||||||
{
|
|
||||||
readonly #llm: AI;
|
readonly #llm: AI;
|
||||||
readonly #tools:
|
readonly #tools:
|
||||||
| BaseToolWithCall[]
|
| BaseToolWithCall[]
|
||||||
@@ -259,6 +256,7 @@ export abstract class AgentRunner<
|
|||||||
protected constructor(
|
protected constructor(
|
||||||
params: AgentRunnerParams<AI, Store, AdditionalMessageOptions>,
|
params: AgentRunnerParams<AI, Store, AdditionalMessageOptions>,
|
||||||
) {
|
) {
|
||||||
|
super();
|
||||||
const { llm, chatHistory, systemPrompt, runner, tools, verbose } = params;
|
const { llm, chatHistory, systemPrompt, runner, tools, verbose } = params;
|
||||||
this.#llm = llm;
|
this.#llm = llm;
|
||||||
this.#chatHistory = chatHistory;
|
this.#chatHistory = chatHistory;
|
||||||
@@ -345,20 +343,19 @@ export abstract class AgentRunner<
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async chat(params: ChatEngineParamsNonStreaming): Promise<EngineResponse>;
|
async chat(params: NonStreamingChatEngineParams): Promise<EngineResponse>;
|
||||||
async chat(
|
async chat(
|
||||||
params: ChatEngineParamsStreaming,
|
params: StreamingChatEngineParams,
|
||||||
): Promise<ReadableStream<EngineResponse>>;
|
): Promise<ReadableStream<EngineResponse>>;
|
||||||
@wrapEventCaller
|
@wrapEventCaller
|
||||||
async chat(
|
async chat(
|
||||||
params: ChatEngineParamsNonStreaming | ChatEngineParamsStreaming,
|
params: NonStreamingChatEngineParams | StreamingChatEngineParams,
|
||||||
): Promise<EngineResponse | ReadableStream<EngineResponse>> {
|
): Promise<EngineResponse | ReadableStream<EngineResponse>> {
|
||||||
let chatHistory: ChatMessage<AdditionalMessageOptions>[] = [];
|
let chatHistory: ChatMessage<AdditionalMessageOptions>[] = [];
|
||||||
|
|
||||||
if (params.chatHistory instanceof BaseMemory) {
|
if (params.chatHistory instanceof BaseMemory) {
|
||||||
chatHistory = (await params.chatHistory.getMessages(
|
chatHistory =
|
||||||
params.message,
|
(await params.chatHistory.getMessages()) as ChatMessage<AdditionalMessageOptions>[];
|
||||||
)) as ChatMessage<AdditionalMessageOptions>[];
|
|
||||||
} else {
|
} else {
|
||||||
chatHistory =
|
chatHistory =
|
||||||
params.chatHistory as ChatMessage<AdditionalMessageOptions>[];
|
params.chatHistory as ChatMessage<AdditionalMessageOptions>[];
|
||||||
@@ -375,7 +372,7 @@ export abstract class AgentRunner<
|
|||||||
this.#chatHistory = [...stepOutput.taskStep.context.store.messages];
|
this.#chatHistory = [...stepOutput.taskStep.context.store.messages];
|
||||||
if (stepOutput.isLast) {
|
if (stepOutput.isLast) {
|
||||||
const { output } = stepOutput;
|
const { output } = stepOutput;
|
||||||
if (isReadableStream(output)) {
|
if (output instanceof ReadableStream) {
|
||||||
return output.pipeThrough<EngineResponse>(
|
return output.pipeThrough<EngineResponse>(
|
||||||
new TransformStream({
|
new TransformStream({
|
||||||
transform(chunk, controller) {
|
transform(chunk, controller) {
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
export { AgentRunner, AgentWorker, type AgentParamsBase } from "./base.js";
|
||||||
|
export { LLMAgent, LLMAgentWorker, type LLMAgentParams } from "./llm.js";
|
||||||
|
export type { AgentEndEvent, AgentStartEvent, TaskHandler } from "./types.js";
|
||||||
|
export {
|
||||||
|
callTool,
|
||||||
|
consumeAsyncIterable,
|
||||||
|
createReadableStream,
|
||||||
|
stepTools,
|
||||||
|
stepToolsStreaming,
|
||||||
|
validateAgentParams,
|
||||||
|
} from "./utils.js";
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { BaseToolWithCall, LLM } from "@llamaindex/core/llms";
|
import { Settings } from "../global";
|
||||||
import { ObjectRetriever } from "../objects/index.js";
|
import type { BaseToolWithCall, LLM } from "../llms";
|
||||||
import { Settings } from "../Settings.js";
|
import { ObjectRetriever } from "../objects";
|
||||||
import { AgentRunner, AgentWorker, type AgentParamsBase } from "./base.js";
|
import { AgentRunner, AgentWorker, type AgentParamsBase } from "./base.js";
|
||||||
import { validateAgentParams } from "./utils.js";
|
import { validateAgentParams } from "./utils.js";
|
||||||
|
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import type { Logger } from "@llamaindex/env";
|
||||||
|
import type { UUID } from "../global";
|
||||||
import type {
|
import type {
|
||||||
BaseToolWithCall,
|
BaseToolWithCall,
|
||||||
ChatMessage,
|
ChatMessage,
|
||||||
@@ -6,9 +8,7 @@ import type {
|
|||||||
LLM,
|
LLM,
|
||||||
MessageContent,
|
MessageContent,
|
||||||
ToolOutput,
|
ToolOutput,
|
||||||
} from "@llamaindex/core/llms";
|
} from "../llms";
|
||||||
import type { Logger } from "../internal/logger.js";
|
|
||||||
import type { UUID } from "../types.js";
|
|
||||||
|
|
||||||
export type AgentTaskContext<
|
export type AgentTaskContext<
|
||||||
Model extends LLM,
|
Model extends LLM,
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
import {
|
import type { Logger } from "@llamaindex/env";
|
||||||
type JSONObject,
|
import { z } from "zod";
|
||||||
type JSONValue,
|
import { type JSONObject, type JSONValue, Settings } from "../global";
|
||||||
Settings,
|
|
||||||
} from "@llamaindex/core/global";
|
|
||||||
import type {
|
import type {
|
||||||
BaseTool,
|
BaseTool,
|
||||||
ChatMessage,
|
ChatMessage,
|
||||||
@@ -14,15 +12,13 @@ import type {
|
|||||||
ToolCall,
|
ToolCall,
|
||||||
ToolCallLLMMessageOptions,
|
ToolCallLLMMessageOptions,
|
||||||
ToolOutput,
|
ToolOutput,
|
||||||
} from "@llamaindex/core/llms";
|
} from "../llms";
|
||||||
import { baseToolWithCallSchema } from "@llamaindex/core/schema";
|
import { baseToolWithCallSchema } from "../schema";
|
||||||
import { z } from "zod";
|
|
||||||
import type { Logger } from "../internal/logger.js";
|
|
||||||
import {
|
import {
|
||||||
isAsyncIterable,
|
isAsyncIterable,
|
||||||
prettifyError,
|
prettifyError,
|
||||||
stringifyJSONToMessageContent,
|
stringifyJSONToMessageContent,
|
||||||
} from "../internal/utils.js";
|
} from "../utils";
|
||||||
import type { AgentParamsBase } from "./base.js";
|
import type { AgentParamsBase } from "./base.js";
|
||||||
import type { TaskHandler } from "./types.js";
|
import type { TaskHandler } from "./types.js";
|
||||||
|
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import type { ChatMessage, MessageContent } from "../llms";
|
||||||
|
import type { BaseMemory } from "../memory";
|
||||||
|
import { EngineResponse } from "../schema";
|
||||||
|
|
||||||
|
export interface BaseChatEngineParams<
|
||||||
|
AdditionalMessageOptions extends object = object,
|
||||||
|
> {
|
||||||
|
message: MessageContent;
|
||||||
|
/**
|
||||||
|
* Optional chat history if you want to customize the chat history.
|
||||||
|
*/
|
||||||
|
chatHistory?:
|
||||||
|
| ChatMessage<AdditionalMessageOptions>[]
|
||||||
|
| BaseMemory<AdditionalMessageOptions>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface StreamingChatEngineParams<
|
||||||
|
AdditionalMessageOptions extends object = object,
|
||||||
|
> extends BaseChatEngineParams<AdditionalMessageOptions> {
|
||||||
|
stream: true;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface NonStreamingChatEngineParams<
|
||||||
|
AdditionalMessageOptions extends object = object,
|
||||||
|
> extends BaseChatEngineParams<AdditionalMessageOptions> {
|
||||||
|
stream?: false;
|
||||||
|
}
|
||||||
|
|
||||||
|
export abstract class BaseChatEngine {
|
||||||
|
abstract chat(params: NonStreamingChatEngineParams): Promise<EngineResponse>;
|
||||||
|
abstract chat(
|
||||||
|
params: StreamingChatEngineParams,
|
||||||
|
): Promise<AsyncIterable<EngineResponse>>;
|
||||||
|
|
||||||
|
abstract chatHistory: ChatMessage[] | Promise<ChatMessage[]>;
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
import { randomUUID } from "@llamaindex/env";
|
||||||
|
import type { UUID } from "../global";
|
||||||
|
import { IndexStructType } from "./struct-type";
|
||||||
|
|
||||||
|
export abstract class IndexStruct {
|
||||||
|
indexId: string;
|
||||||
|
summary: string | undefined;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
indexId: UUID = randomUUID(),
|
||||||
|
summary: string | undefined = undefined,
|
||||||
|
) {
|
||||||
|
this.indexId = indexId;
|
||||||
|
this.summary = summary;
|
||||||
|
}
|
||||||
|
|
||||||
|
toJson(): Record<string, unknown> {
|
||||||
|
return {
|
||||||
|
indexId: this.indexId,
|
||||||
|
summary: this.summary,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
getSummary(): string {
|
||||||
|
if (this.summary === undefined) {
|
||||||
|
throw new Error("summary field of the index struct is not set");
|
||||||
|
}
|
||||||
|
return this.summary;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A table of keywords mapping keywords to text chunks.
|
||||||
|
export class KeywordTable extends IndexStruct {
|
||||||
|
table: Map<string, Set<string>> = new Map();
|
||||||
|
type: IndexStructType = IndexStructType.KEYWORD_TABLE;
|
||||||
|
|
||||||
|
addNode(keywords: string[], nodeId: string): void {
|
||||||
|
keywords.forEach((keyword) => {
|
||||||
|
if (!this.table.has(keyword)) {
|
||||||
|
this.table.set(keyword, new Set());
|
||||||
|
}
|
||||||
|
this.table.get(keyword)!.add(nodeId);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteNode(keywords: string[], nodeId: string) {
|
||||||
|
keywords.forEach((keyword) => {
|
||||||
|
if (this.table.has(keyword)) {
|
||||||
|
this.table.get(keyword)!.delete(nodeId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
toJson(): Record<string, unknown> {
|
||||||
|
return {
|
||||||
|
...super.toJson(),
|
||||||
|
table: Array.from(this.table.entries()).reduce(
|
||||||
|
(acc, [keyword, nodeIds]) => {
|
||||||
|
acc[keyword] = Array.from(nodeIds);
|
||||||
|
return acc;
|
||||||
|
},
|
||||||
|
{} as Record<string, string[]>,
|
||||||
|
),
|
||||||
|
type: this.type,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export { IndexStruct, KeywordTable } from "./data-structs";
|
||||||
|
export { IndexStructType } from "./struct-type";
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
export const IndexStructType = {
|
||||||
|
NODE: "node",
|
||||||
|
TREE: "tree",
|
||||||
|
LIST: "list",
|
||||||
|
KEYWORD_TABLE: "keyword_table",
|
||||||
|
DICT: "dict",
|
||||||
|
SIMPLE_DICT: "simple_dict",
|
||||||
|
WEAVIATE: "weaviate",
|
||||||
|
PINECONE: "pinecone",
|
||||||
|
QDRANT: "qdrant",
|
||||||
|
LANCEDB: "lancedb",
|
||||||
|
MILVUS: "milvus",
|
||||||
|
CHROMA: "chroma",
|
||||||
|
MYSCALE: "myscale",
|
||||||
|
CLICKHOUSE: "clickhouse",
|
||||||
|
VECTOR_STORE: "vector_store",
|
||||||
|
OPENSEARCH: "opensearch",
|
||||||
|
DASHVECTOR: "dashvector",
|
||||||
|
CHATGPT_RETRIEVAL_PLUGIN: "chatgpt_retrieval_plugin",
|
||||||
|
DEEPLAKE: "deeplake",
|
||||||
|
EPSILLA: "epsilla",
|
||||||
|
MULTIMODAL_VECTOR_STORE: "multimodal",
|
||||||
|
SQL: "sql",
|
||||||
|
KG: "kg",
|
||||||
|
SIMPLE_KG: "simple_kg",
|
||||||
|
SIMPLE_LPG: "simple_lpg",
|
||||||
|
NEBULAGRAPH: "nebulagraph",
|
||||||
|
FALKORDB: "falkordb",
|
||||||
|
EMPTY: "empty",
|
||||||
|
COMPOSITE: "composite",
|
||||||
|
PANDAS: "pandas",
|
||||||
|
DOCUMENT_SUMMARY: "document_summary",
|
||||||
|
VECTARA: "vectara",
|
||||||
|
ZILLIZ_CLOUD_PIPELINE: "zilliz_cloud_pipeline",
|
||||||
|
POSTGRESML: "postgresml",
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export type IndexStructType =
|
||||||
|
(typeof IndexStructType)[keyof typeof IndexStructType];
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
import { AsyncLocalStorage } from "@llamaindex/env";
|
||||||
|
import { withEventCaller } from "../global";
|
||||||
|
import { isAsyncIterable, isIterable } from "../utils";
|
||||||
|
|
||||||
|
export function wrapEventCaller<This, Result, Args extends unknown[]>(
|
||||||
|
originalMethod: (this: This, ...args: Args) => Result,
|
||||||
|
context: ClassMethodDecoratorContext<object>,
|
||||||
|
) {
|
||||||
|
const name = context.name;
|
||||||
|
context.addInitializer(function () {
|
||||||
|
// @ts-expect-error
|
||||||
|
const fn = this[name].bind(this);
|
||||||
|
// @ts-expect-error
|
||||||
|
this[name] = (...args: unknown[]) => {
|
||||||
|
return withEventCaller(this, () => fn(...args));
|
||||||
|
};
|
||||||
|
});
|
||||||
|
return function (this: This, ...args: Args): Result {
|
||||||
|
const result = originalMethod.call(this, ...args);
|
||||||
|
// patch for iterators because AsyncLocalStorage doesn't work with them
|
||||||
|
if (isAsyncIterable(result)) {
|
||||||
|
const iter = result[Symbol.asyncIterator]();
|
||||||
|
const snapshot = AsyncLocalStorage.snapshot();
|
||||||
|
return (async function* asyncGeneratorWrapper() {
|
||||||
|
while (true) {
|
||||||
|
const { value, done } = await snapshot(() => iter.next());
|
||||||
|
if (done) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
yield value;
|
||||||
|
}
|
||||||
|
})() as Result;
|
||||||
|
} else if (isIterable(result)) {
|
||||||
|
const iter = result[Symbol.iterator]();
|
||||||
|
const snapshot = AsyncLocalStorage.snapshot();
|
||||||
|
return (function* generatorWrapper() {
|
||||||
|
while (true) {
|
||||||
|
const { value, done } = snapshot(() => iter.next());
|
||||||
|
if (done) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
yield value;
|
||||||
|
}
|
||||||
|
})() as Result;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,67 +1,3 @@
|
|||||||
import { getEnv } from "@llamaindex/env";
|
export { wrapEventCaller } from "./event-caller";
|
||||||
import { Settings } from "../global";
|
export { lazyInitHash } from "./lazy-init-hash";
|
||||||
import type { BaseNode } from "../schema/node";
|
export { wrapLLMEvent } from "./wrap-llm-event";
|
||||||
|
|
||||||
const emitOnce = false;
|
|
||||||
|
|
||||||
export function chunkSizeCheck<
|
|
||||||
This extends { id_: string },
|
|
||||||
Args extends any[],
|
|
||||||
Return,
|
|
||||||
>(
|
|
||||||
contentGetter: (this: This, ...args: Args) => string,
|
|
||||||
_context: ClassMethodDecoratorContext<
|
|
||||||
This,
|
|
||||||
(this: This, ...args: Args) => Return
|
|
||||||
>,
|
|
||||||
) {
|
|
||||||
return function (this: This, ...args: Args) {
|
|
||||||
const content = contentGetter.call(this, ...args);
|
|
||||||
const chunkSize = Settings.chunkSize;
|
|
||||||
const enableChunkSizeCheck = getEnv("ENABLE_CHUNK_SIZE_CHECK") === "true";
|
|
||||||
if (
|
|
||||||
enableChunkSizeCheck &&
|
|
||||||
chunkSize !== undefined &&
|
|
||||||
content.length > chunkSize
|
|
||||||
) {
|
|
||||||
console.warn(
|
|
||||||
`Node (${this.id_}) is larger than chunk size: ${content.length} > ${chunkSize}`,
|
|
||||||
);
|
|
||||||
if (!emitOnce) {
|
|
||||||
console.warn(
|
|
||||||
"Will truncate the content if it is larger than chunk size",
|
|
||||||
);
|
|
||||||
console.warn("If you want to disable this behavior:");
|
|
||||||
console.warn(" 1. Set Settings.chunkSize = undefined");
|
|
||||||
console.warn(" 2. Set Settings.chunkSize to a larger value");
|
|
||||||
console.warn(
|
|
||||||
" 3. Change the way of splitting content into smaller chunks",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return content.slice(0, chunkSize);
|
|
||||||
}
|
|
||||||
return content;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function lazyInitHash(
|
|
||||||
value: ClassAccessorDecoratorTarget<BaseNode, string>,
|
|
||||||
_context: ClassAccessorDecoratorContext,
|
|
||||||
): ClassAccessorDecoratorResult<BaseNode, string> {
|
|
||||||
return {
|
|
||||||
get() {
|
|
||||||
const oldValue = value.get.call(this);
|
|
||||||
if (oldValue === "") {
|
|
||||||
const hash = this.generateHash();
|
|
||||||
value.set.call(this, hash);
|
|
||||||
}
|
|
||||||
return value.get.call(this);
|
|
||||||
},
|
|
||||||
set(newValue: string) {
|
|
||||||
value.set.call(this, newValue);
|
|
||||||
},
|
|
||||||
init(value: string): string {
|
|
||||||
return value;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import type { BaseNode } from "../schema";
|
||||||
|
|
||||||
|
export function lazyInitHash(
|
||||||
|
value: ClassAccessorDecoratorTarget<BaseNode, string>,
|
||||||
|
_context: ClassAccessorDecoratorContext,
|
||||||
|
): ClassAccessorDecoratorResult<BaseNode, string> {
|
||||||
|
return {
|
||||||
|
get() {
|
||||||
|
const oldValue = value.get.call(this);
|
||||||
|
if (oldValue === "") {
|
||||||
|
const hash = this.generateHash();
|
||||||
|
value.set.call(this, hash);
|
||||||
|
}
|
||||||
|
return value.get.call(this);
|
||||||
|
},
|
||||||
|
set(newValue: string) {
|
||||||
|
value.set.call(this, newValue);
|
||||||
|
},
|
||||||
|
init(value: string): string {
|
||||||
|
return value;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -9,4 +9,9 @@ export type {
|
|||||||
LLMToolResultEvent,
|
LLMToolResultEvent,
|
||||||
LlamaIndexEventMaps,
|
LlamaIndexEventMaps,
|
||||||
} from "./settings/callback-manager";
|
} from "./settings/callback-manager";
|
||||||
export type { JSONArray, JSONObject, JSONValue } from "./type";
|
export {
|
||||||
|
EventCaller,
|
||||||
|
getEventCaller,
|
||||||
|
withEventCaller,
|
||||||
|
} from "./settings/event-caller";
|
||||||
|
export type { JSONArray, JSONObject, JSONValue, UUID } from "./type";
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { Tokenizer } from "@llamaindex/env";
|
import { getEnv, type Tokenizer } from "@llamaindex/env";
|
||||||
import type { LLM } from "../llms";
|
import type { LLM } from "../llms";
|
||||||
import {
|
import {
|
||||||
type CallbackManager,
|
type CallbackManager,
|
||||||
@@ -61,4 +61,16 @@ export const Settings = {
|
|||||||
): Result {
|
): Result {
|
||||||
return withCallbackManager(callbackManager, fn);
|
return withCallbackManager(callbackManager, fn);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
get debug() {
|
||||||
|
let debug = getEnv("DEBUG");
|
||||||
|
if (typeof window !== "undefined") {
|
||||||
|
debug ||= window.localStorage.debug;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
(Boolean(debug) && debug?.includes("llamaindex")) ||
|
||||||
|
debug === "*" ||
|
||||||
|
debug === "true"
|
||||||
|
);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { AsyncLocalStorage, CustomEvent } from "@llamaindex/env";
|
import { AsyncLocalStorage, CustomEvent } from "@llamaindex/env";
|
||||||
|
import type { AgentEndEvent, AgentStartEvent } from "../../agent";
|
||||||
import type {
|
import type {
|
||||||
ChatMessage,
|
ChatMessage,
|
||||||
ChatResponse,
|
ChatResponse,
|
||||||
@@ -6,9 +7,15 @@ import type {
|
|||||||
ToolCall,
|
ToolCall,
|
||||||
ToolOutput,
|
ToolOutput,
|
||||||
} from "../../llms";
|
} from "../../llms";
|
||||||
|
import type { QueryEndEvent, QueryStartEvent } from "../../query-engine";
|
||||||
|
import type {
|
||||||
|
SynthesizeEndEvent,
|
||||||
|
SynthesizeStartEvent,
|
||||||
|
} from "../../response-synthesizers";
|
||||||
|
import type { RetrieveEndEvent, RetrieveStartEvent } from "../../retriever";
|
||||||
import { TextNode } from "../../schema";
|
import { TextNode } from "../../schema";
|
||||||
import { EventCaller, getEventCaller } from "../../utils/event-caller";
|
|
||||||
import type { UUID } from "../type";
|
import type { UUID } from "../type";
|
||||||
|
import { EventCaller, getEventCaller } from "./event-caller";
|
||||||
|
|
||||||
export type LLMStartEvent = {
|
export type LLMStartEvent = {
|
||||||
id: UUID;
|
id: UUID;
|
||||||
@@ -60,6 +67,14 @@ export interface LlamaIndexEventMaps {
|
|||||||
"chunking-end": ChunkingEndEvent;
|
"chunking-end": ChunkingEndEvent;
|
||||||
"node-parsing-start": NodeParsingStartEvent;
|
"node-parsing-start": NodeParsingStartEvent;
|
||||||
"node-parsing-end": NodeParsingEndEvent;
|
"node-parsing-end": NodeParsingEndEvent;
|
||||||
|
"query-start": QueryStartEvent;
|
||||||
|
"query-end": QueryEndEvent;
|
||||||
|
"synthesize-start": SynthesizeStartEvent;
|
||||||
|
"synthesize-end": SynthesizeEndEvent;
|
||||||
|
"retrieve-start": RetrieveStartEvent;
|
||||||
|
"retrieve-end": RetrieveEndEvent;
|
||||||
|
"agent-start": AgentStartEvent;
|
||||||
|
"agent-end": AgentEndEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class LlamaIndexCustomEvent<T = any> extends CustomEvent<T> {
|
export class LlamaIndexCustomEvent<T = any> extends CustomEvent<T> {
|
||||||
@@ -119,16 +134,29 @@ export class CallbackManager {
|
|||||||
dispatchEvent<K extends keyof LlamaIndexEventMaps>(
|
dispatchEvent<K extends keyof LlamaIndexEventMaps>(
|
||||||
event: K,
|
event: K,
|
||||||
detail: LlamaIndexEventMaps[K],
|
detail: LlamaIndexEventMaps[K],
|
||||||
|
sync = false,
|
||||||
) {
|
) {
|
||||||
const cbs = this.#handlers.get(event);
|
const cbs = this.#handlers.get(event);
|
||||||
if (!cbs) {
|
if (!cbs) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
queueMicrotask(() => {
|
if (typeof queueMicrotask === "undefined") {
|
||||||
|
console.warn(
|
||||||
|
"queueMicrotask is not available, dispatching synchronously",
|
||||||
|
);
|
||||||
|
sync = true;
|
||||||
|
}
|
||||||
|
if (sync) {
|
||||||
cbs.forEach((handler) =>
|
cbs.forEach((handler) =>
|
||||||
handler(LlamaIndexCustomEvent.fromEvent(event, { ...detail })),
|
handler(LlamaIndexCustomEvent.fromEvent(event, { ...detail })),
|
||||||
);
|
);
|
||||||
});
|
} else {
|
||||||
|
queueMicrotask(() => {
|
||||||
|
cbs.forEach((handler) =>
|
||||||
|
handler(LlamaIndexCustomEvent.fromEvent(event, { ...detail })),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
import { AsyncLocalStorage, randomUUID } from "@llamaindex/env";
|
||||||
|
|
||||||
|
const eventReasonAsyncLocalStorage = new AsyncLocalStorage<EventCaller>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* EventCaller is used to track the caller of an event.
|
||||||
|
*/
|
||||||
|
export class EventCaller {
|
||||||
|
public readonly id = randomUUID();
|
||||||
|
|
||||||
|
private constructor(
|
||||||
|
public readonly caller: unknown,
|
||||||
|
public readonly parent: EventCaller | null,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
#computedCallers: unknown[] | null = null;
|
||||||
|
|
||||||
|
public get computedCallers(): unknown[] {
|
||||||
|
if (this.#computedCallers != null) {
|
||||||
|
return this.#computedCallers;
|
||||||
|
}
|
||||||
|
const callers = [this.caller];
|
||||||
|
let parent = this.parent;
|
||||||
|
while (parent != null) {
|
||||||
|
callers.push(parent.caller);
|
||||||
|
parent = parent.parent;
|
||||||
|
}
|
||||||
|
this.#computedCallers = callers;
|
||||||
|
return callers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static create(
|
||||||
|
caller: unknown,
|
||||||
|
parent: EventCaller | null,
|
||||||
|
): EventCaller {
|
||||||
|
return new EventCaller(caller, parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getEventCaller(): EventCaller | null {
|
||||||
|
return eventReasonAsyncLocalStorage.getStore() ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param caller who is calling this function, pass in `this` if it's a class method
|
||||||
|
* @param fn
|
||||||
|
*/
|
||||||
|
export function withEventCaller<T>(caller: unknown, fn: () => T) {
|
||||||
|
// create a chain of event callers
|
||||||
|
const parentCaller = getEventCaller();
|
||||||
|
return eventReasonAsyncLocalStorage.run(
|
||||||
|
EventCaller.create(caller, parentCaller),
|
||||||
|
fn,
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,22 +1,23 @@
|
|||||||
import { type Tokenizer, tokenizers } from "@llamaindex/env";
|
import { type Tokenizer, tokenizers } from "@llamaindex/env";
|
||||||
import {
|
import {
|
||||||
DEFAULT_CHUNK_OVERLAP_RATIO,
|
DEFAULT_CHUNK_OVERLAP_RATIO,
|
||||||
|
DEFAULT_CHUNK_SIZE,
|
||||||
DEFAULT_CONTEXT_WINDOW,
|
DEFAULT_CONTEXT_WINDOW,
|
||||||
DEFAULT_NUM_OUTPUTS,
|
DEFAULT_NUM_OUTPUTS,
|
||||||
DEFAULT_PADDING,
|
DEFAULT_PADDING,
|
||||||
|
Settings,
|
||||||
} from "../global";
|
} from "../global";
|
||||||
import { SentenceSplitter } from "../node-parser";
|
import type { LLMMetadata } from "../llms";
|
||||||
import type { PromptTemplate } from "../prompts";
|
import { TextSplitter, TokenTextSplitter, truncateText } from "../node-parser";
|
||||||
|
import { BasePromptTemplate, PromptTemplate } from "../prompts";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the empty prompt text given a prompt.
|
* Get the empty prompt text given a prompt.
|
||||||
*/
|
*/
|
||||||
function getEmptyPromptTxt(prompt: PromptTemplate) {
|
function getEmptyPromptTxt(prompt: PromptTemplate): string {
|
||||||
return prompt.format({
|
return prompt.format(
|
||||||
...Object.fromEntries(
|
Object.fromEntries([...prompt.templateVars.keys()].map((key) => [key, ""])),
|
||||||
[...prompt.templateVars.keys()].map((key) => [key, ""]),
|
);
|
||||||
),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -32,24 +33,24 @@ export function getBiggestPrompt(prompts: PromptTemplate[]): PromptTemplate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type PromptHelperOptions = {
|
export type PromptHelperOptions = {
|
||||||
contextWindow?: number;
|
contextWindow?: number | undefined;
|
||||||
numOutput?: number;
|
numOutput?: number | undefined;
|
||||||
chunkOverlapRatio?: number;
|
chunkOverlapRatio?: number | undefined;
|
||||||
chunkSizeLimit?: number;
|
chunkSizeLimit?: number | undefined;
|
||||||
tokenizer?: Tokenizer;
|
tokenizer?: Tokenizer | undefined;
|
||||||
separator?: string;
|
separator?: string | undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A collection of helper functions for working with prompts.
|
* A collection of helper functions for working with prompts.
|
||||||
*/
|
*/
|
||||||
export class PromptHelper {
|
export class PromptHelper {
|
||||||
contextWindow = DEFAULT_CONTEXT_WINDOW;
|
contextWindow: number;
|
||||||
numOutput = DEFAULT_NUM_OUTPUTS;
|
numOutput: number;
|
||||||
chunkOverlapRatio = DEFAULT_CHUNK_OVERLAP_RATIO;
|
chunkOverlapRatio: number;
|
||||||
chunkSizeLimit: number | undefined;
|
chunkSizeLimit: number | undefined;
|
||||||
tokenizer: Tokenizer;
|
tokenizer: Tokenizer;
|
||||||
separator = " ";
|
separator: string;
|
||||||
|
|
||||||
constructor(options: PromptHelperOptions = {}) {
|
constructor(options: PromptHelperOptions = {}) {
|
||||||
const {
|
const {
|
||||||
@@ -69,68 +70,119 @@ export class PromptHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a prompt, return the maximum size of the inputs to the prompt.
|
* Calculate the available context size based on the number of prompt tokens.
|
||||||
* @param prompt
|
|
||||||
* @returns
|
|
||||||
*/
|
*/
|
||||||
private getAvailableContextSize(prompt: PromptTemplate) {
|
#getAvailableContextSize(numPromptTokens: number): number {
|
||||||
const emptyPromptText = getEmptyPromptTxt(prompt);
|
const contextSizeTokens =
|
||||||
const promptTokens = this.tokenizer.encode(emptyPromptText);
|
this.contextWindow - numPromptTokens - this.numOutput;
|
||||||
const numPromptTokens = promptTokens.length;
|
if (contextSizeTokens < 0) {
|
||||||
|
throw new Error(
|
||||||
return this.contextWindow - numPromptTokens - this.numOutput;
|
`Calculated available context size ${contextSizeTokens} is not non-negative.`,
|
||||||
}
|
);
|
||||||
|
|
||||||
/**
|
|
||||||
* Find the maximum size of each chunk given a prompt.
|
|
||||||
*/
|
|
||||||
private getAvailableChunkSize(
|
|
||||||
prompt: PromptTemplate,
|
|
||||||
numChunks = 1,
|
|
||||||
padding = 5,
|
|
||||||
): number {
|
|
||||||
const availableContextSize = this.getAvailableContextSize(prompt);
|
|
||||||
|
|
||||||
const result = Math.floor(availableContextSize / numChunks) - padding;
|
|
||||||
|
|
||||||
if (this.chunkSizeLimit) {
|
|
||||||
return Math.min(this.chunkSizeLimit, result);
|
|
||||||
} else {
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
return contextSizeTokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a text splitter with the correct chunk sizes and overlaps given a prompt.
|
* Calculate the available chunk size based on the prompt and other parameters.
|
||||||
|
*/
|
||||||
|
#getAvailableChunkSize<Template extends BasePromptTemplate>(
|
||||||
|
prompt: Template,
|
||||||
|
numChunks: number = 1,
|
||||||
|
padding: number = 5,
|
||||||
|
): number {
|
||||||
|
let numPromptTokens = 0;
|
||||||
|
|
||||||
|
if (prompt instanceof PromptTemplate) {
|
||||||
|
numPromptTokens = this.tokenizer.encode(getEmptyPromptTxt(prompt)).length;
|
||||||
|
}
|
||||||
|
|
||||||
|
const availableContextSize = this.#getAvailableContextSize(numPromptTokens);
|
||||||
|
let result = Math.floor(availableContextSize / numChunks) - padding;
|
||||||
|
|
||||||
|
if (this.chunkSizeLimit !== undefined) {
|
||||||
|
result = Math.min(this.chunkSizeLimit, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a text splitter configured to maximally pack the available context window.
|
||||||
*/
|
*/
|
||||||
getTextSplitterGivenPrompt(
|
getTextSplitterGivenPrompt(
|
||||||
prompt: PromptTemplate,
|
prompt: BasePromptTemplate,
|
||||||
numChunks = 1,
|
numChunks: number = 1,
|
||||||
padding = DEFAULT_PADDING,
|
padding: number = DEFAULT_PADDING,
|
||||||
) {
|
): TextSplitter {
|
||||||
const chunkSize = this.getAvailableChunkSize(prompt, numChunks, padding);
|
const chunkSize = this.#getAvailableChunkSize(prompt, numChunks, padding);
|
||||||
if (chunkSize === 0) {
|
if (chunkSize <= 0) {
|
||||||
throw new Error("Got 0 as available chunk size");
|
throw new TypeError(`Chunk size ${chunkSize} is not positive.`);
|
||||||
}
|
}
|
||||||
const chunkOverlap = this.chunkOverlapRatio * chunkSize;
|
const chunkOverlap = Math.floor(this.chunkOverlapRatio * chunkSize);
|
||||||
return new SentenceSplitter({
|
return new TokenTextSplitter({
|
||||||
|
separator: this.separator,
|
||||||
chunkSize,
|
chunkSize,
|
||||||
chunkOverlap,
|
chunkOverlap,
|
||||||
separator: this.separator,
|
|
||||||
tokenizer: this.tokenizer,
|
tokenizer: this.tokenizer,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Repack resplits the strings based on the optimal text splitter.
|
* Truncate text chunks to fit within the available context window.
|
||||||
|
*/
|
||||||
|
truncate(
|
||||||
|
prompt: BasePromptTemplate,
|
||||||
|
textChunks: string[],
|
||||||
|
padding: number = DEFAULT_PADDING,
|
||||||
|
): string[] {
|
||||||
|
const textSplitter = this.getTextSplitterGivenPrompt(
|
||||||
|
prompt,
|
||||||
|
textChunks.length,
|
||||||
|
padding,
|
||||||
|
);
|
||||||
|
return textChunks.map((chunk) => truncateText(chunk, textSplitter));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repack text chunks to better utilize the available context window.
|
||||||
*/
|
*/
|
||||||
repack(
|
repack(
|
||||||
prompt: PromptTemplate,
|
prompt: BasePromptTemplate,
|
||||||
textChunks: string[],
|
textChunks: string[],
|
||||||
padding = DEFAULT_PADDING,
|
padding: number = DEFAULT_PADDING,
|
||||||
) {
|
): string[] {
|
||||||
const textSplitter = this.getTextSplitterGivenPrompt(prompt, 1, padding);
|
const textSplitter = this.getTextSplitterGivenPrompt(prompt, 1, padding);
|
||||||
const combinedStr = textChunks.join("\n\n");
|
const combinedStr = textChunks
|
||||||
|
.map((c) => c.trim())
|
||||||
|
.filter((c) => c.length > 0)
|
||||||
|
.join("\n\n");
|
||||||
return textSplitter.splitText(combinedStr);
|
return textSplitter.splitText(combinedStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static fromLLMMetadata(
|
||||||
|
metadata: LLMMetadata,
|
||||||
|
options?: {
|
||||||
|
chunkOverlapRatio?: number;
|
||||||
|
chunkSizeLimit?: number;
|
||||||
|
tokenizer?: Tokenizer;
|
||||||
|
separator?: string;
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
const {
|
||||||
|
chunkOverlapRatio = DEFAULT_CHUNK_OVERLAP_RATIO,
|
||||||
|
chunkSizeLimit = DEFAULT_CHUNK_SIZE,
|
||||||
|
tokenizer = Settings.tokenizer,
|
||||||
|
separator = " ",
|
||||||
|
} = options ?? {};
|
||||||
|
return new PromptHelper({
|
||||||
|
contextWindow: metadata.contextWindow,
|
||||||
|
// fixme: numOutput is not in LLMMetadata
|
||||||
|
numOutput: DEFAULT_NUM_OUTPUTS,
|
||||||
|
chunkOverlapRatio,
|
||||||
|
chunkSizeLimit,
|
||||||
|
tokenizer,
|
||||||
|
separator,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Settings } from "../global";
|
import { Settings } from "../global";
|
||||||
import type { ChatMessage, MessageContent } from "../llms";
|
import type { ChatMessage } from "../llms";
|
||||||
import { type BaseChatStore, SimpleChatStore } from "../storage/chat-store";
|
import { type BaseChatStore, SimpleChatStore } from "../storage/chat-store";
|
||||||
import { extractText } from "../utils";
|
import { extractText } from "../utils";
|
||||||
|
|
||||||
@@ -12,15 +12,36 @@ export const DEFAULT_CHAT_STORE_KEY = "chat_history";
|
|||||||
export abstract class BaseMemory<
|
export abstract class BaseMemory<
|
||||||
AdditionalMessageOptions extends object = object,
|
AdditionalMessageOptions extends object = object,
|
||||||
> {
|
> {
|
||||||
|
/**
|
||||||
|
* Retrieves messages from the memory, optionally including transient messages.
|
||||||
|
* Compared to getAllMessages, this method a) allows for transient messages to be included in the retrieval and b) may return a subset of the total messages by applying a token limit.
|
||||||
|
* @param transientMessages Optional array of temporary messages to be included in the retrieval.
|
||||||
|
* These messages are not stored in the memory but are considered for the current interaction.
|
||||||
|
* @returns An array of chat messages, either synchronously or as a Promise.
|
||||||
|
*/
|
||||||
abstract getMessages(
|
abstract getMessages(
|
||||||
input?: MessageContent | undefined,
|
transientMessages?: ChatMessage<AdditionalMessageOptions>[] | undefined,
|
||||||
):
|
):
|
||||||
| ChatMessage<AdditionalMessageOptions>[]
|
| ChatMessage<AdditionalMessageOptions>[]
|
||||||
| Promise<ChatMessage<AdditionalMessageOptions>[]>;
|
| Promise<ChatMessage<AdditionalMessageOptions>[]>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves all messages stored in the memory.
|
||||||
|
* @returns An array of all chat messages, either synchronously or as a Promise.
|
||||||
|
*/
|
||||||
abstract getAllMessages():
|
abstract getAllMessages():
|
||||||
| ChatMessage<AdditionalMessageOptions>[]
|
| ChatMessage<AdditionalMessageOptions>[]
|
||||||
| Promise<ChatMessage<AdditionalMessageOptions>[]>;
|
| Promise<ChatMessage<AdditionalMessageOptions>[]>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a new message to the memory.
|
||||||
|
* @param messages The chat message to be added to the memory.
|
||||||
|
*/
|
||||||
abstract put(messages: ChatMessage<AdditionalMessageOptions>): void;
|
abstract put(messages: ChatMessage<AdditionalMessageOptions>): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears all messages from the memory.
|
||||||
|
*/
|
||||||
abstract reset(): void;
|
abstract reset(): void;
|
||||||
|
|
||||||
protected _tokenCountForMessages(messages: ChatMessage[]): number {
|
protected _tokenCountForMessages(messages: ChatMessage[]): number {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Settings } from "../global";
|
import { Settings } from "../global";
|
||||||
import type { ChatMessage, LLM, MessageContent } from "../llms";
|
import type { ChatMessage, LLM } from "../llms";
|
||||||
import { type BaseChatStore } from "../storage/chat-store";
|
import { type BaseChatStore } from "../storage/chat-store";
|
||||||
import { BaseChatStoreMemory, DEFAULT_TOKEN_LIMIT_RATIO } from "./base";
|
import { BaseChatStoreMemory, DEFAULT_TOKEN_LIMIT_RATIO } from "./base";
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ export class ChatMemoryBuffer<
|
|||||||
}
|
}
|
||||||
|
|
||||||
getMessages(
|
getMessages(
|
||||||
input?: MessageContent | undefined,
|
transientMessages?: ChatMessage<AdditionalMessageOptions>[] | undefined,
|
||||||
initialTokenCount: number = 0,
|
initialTokenCount: number = 0,
|
||||||
) {
|
) {
|
||||||
const messages = this.getAllMessages();
|
const messages = this.getAllMessages();
|
||||||
@@ -43,16 +43,22 @@ export class ChatMemoryBuffer<
|
|||||||
throw new Error("Initial token count exceeds token limit");
|
throw new Error("Initial token count exceeds token limit");
|
||||||
}
|
}
|
||||||
|
|
||||||
let messageCount = messages.length;
|
// Add input messages as transient messages
|
||||||
let currentMessages = messages.slice(-messageCount);
|
const messagesWithInput = transientMessages
|
||||||
let tokenCount = this._tokenCountForMessages(messages) + initialTokenCount;
|
? [...transientMessages, ...messages]
|
||||||
|
: messages;
|
||||||
|
|
||||||
|
let messageCount = messagesWithInput.length;
|
||||||
|
let currentMessages = messagesWithInput.slice(-messageCount);
|
||||||
|
let tokenCount =
|
||||||
|
this._tokenCountForMessages(messagesWithInput) + initialTokenCount;
|
||||||
|
|
||||||
while (tokenCount > this.tokenLimit && messageCount > 1) {
|
while (tokenCount > this.tokenLimit && messageCount > 1) {
|
||||||
messageCount -= 1;
|
messageCount -= 1;
|
||||||
if (messages.at(-messageCount)!.role === "assistant") {
|
if (messagesWithInput.at(-messageCount)!.role === "assistant") {
|
||||||
messageCount -= 1;
|
messageCount -= 1;
|
||||||
}
|
}
|
||||||
currentMessages = messages.slice(-messageCount);
|
currentMessages = messagesWithInput.slice(-messageCount);
|
||||||
tokenCount =
|
tokenCount =
|
||||||
this._tokenCountForMessages(currentMessages) + initialTokenCount;
|
this._tokenCountForMessages(currentMessages) + initialTokenCount;
|
||||||
}
|
}
|
||||||
@@ -60,6 +66,6 @@ export class ChatMemoryBuffer<
|
|||||||
if (tokenCount > this.tokenLimit && messageCount <= 0) {
|
if (tokenCount > this.tokenLimit && messageCount <= 0) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
return messages.slice(-messageCount);
|
return messagesWithInput.slice(-messageCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,18 +114,22 @@ export class ChatSummaryMemoryBuffer extends BaseMemory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private calcCurrentRequestMessages() {
|
private calcCurrentRequestMessages(transientMessages?: ChatMessage[]) {
|
||||||
// TODO: check order: currently, we're sending:
|
// currently, we're sending:
|
||||||
// system messages first, then transient messages and then the messages that describe the conversation so far
|
// system messages first, then transient messages and then the messages that describe the conversation so far
|
||||||
return [...this.systemMessages, ...this.calcConversationMessages(true)];
|
return [
|
||||||
|
...this.systemMessages,
|
||||||
|
...(transientMessages ? transientMessages : []),
|
||||||
|
...this.calcConversationMessages(true),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
this.messages = [];
|
this.messages = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
async getMessages(): Promise<ChatMessage[]> {
|
async getMessages(transientMessages?: ChatMessage[]): Promise<ChatMessage[]> {
|
||||||
const requestMessages = this.calcCurrentRequestMessages();
|
const requestMessages = this.calcCurrentRequestMessages(transientMessages);
|
||||||
|
|
||||||
// get tokens of current request messages and the transient messages
|
// get tokens of current request messages and the transient messages
|
||||||
const tokens = requestMessages.reduce(
|
const tokens = requestMessages.reduce(
|
||||||
@@ -149,7 +153,7 @@ export class ChatSummaryMemoryBuffer extends BaseMemory {
|
|||||||
// TODO: we still might have too many tokens
|
// TODO: we still might have too many tokens
|
||||||
// e.g. too large system messages or transient messages
|
// e.g. too large system messages or transient messages
|
||||||
// how should we deal with that?
|
// how should we deal with that?
|
||||||
return this.calcCurrentRequestMessages();
|
return this.calcCurrentRequestMessages(transientMessages);
|
||||||
}
|
}
|
||||||
return requestMessages;
|
return requestMessages;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ export { MetadataAwareTextSplitter, NodeParser, TextSplitter } from "./base";
|
|||||||
export { MarkdownNodeParser } from "./markdown";
|
export { MarkdownNodeParser } from "./markdown";
|
||||||
export { SentenceSplitter } from "./sentence-splitter";
|
export { SentenceSplitter } from "./sentence-splitter";
|
||||||
export { SentenceWindowNodeParser } from "./sentence-window";
|
export { SentenceWindowNodeParser } from "./sentence-window";
|
||||||
|
export { TokenTextSplitter } from "./token-text-splitter";
|
||||||
export type { SplitterParams } from "./type";
|
export type { SplitterParams } from "./type";
|
||||||
export {
|
export {
|
||||||
splitByChar,
|
splitByChar,
|
||||||
@@ -20,5 +21,6 @@ export {
|
|||||||
splitByRegex,
|
splitByRegex,
|
||||||
splitBySentenceTokenizer,
|
splitBySentenceTokenizer,
|
||||||
splitBySep,
|
splitBySep,
|
||||||
|
truncateText,
|
||||||
} from "./utils";
|
} from "./utils";
|
||||||
export type { TextSplitterFn } from "./utils";
|
export type { TextSplitterFn } from "./utils";
|
||||||
|
|||||||
@@ -0,0 +1,206 @@
|
|||||||
|
import type { Tokenizer } from "@llamaindex/env";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { DEFAULT_CHUNK_OVERLAP, DEFAULT_CHUNK_SIZE, Settings } from "../global";
|
||||||
|
import { MetadataAwareTextSplitter } from "./base";
|
||||||
|
import type { SplitterParams } from "./type";
|
||||||
|
import { splitByChar, splitBySep } from "./utils";
|
||||||
|
|
||||||
|
const DEFAULT_METADATA_FORMAT_LEN = 2;
|
||||||
|
|
||||||
|
const tokenTextSplitterSchema = z.object({
|
||||||
|
chunkSize: z.number().positive().default(DEFAULT_CHUNK_SIZE),
|
||||||
|
chunkOverlap: z.number().nonnegative().default(DEFAULT_CHUNK_OVERLAP),
|
||||||
|
separator: z.string().default(" "),
|
||||||
|
backupSeparators: z.array(z.string()).default(["\n"]),
|
||||||
|
});
|
||||||
|
|
||||||
|
export class TokenTextSplitter extends MetadataAwareTextSplitter {
|
||||||
|
chunkSize: number = DEFAULT_CHUNK_SIZE;
|
||||||
|
chunkOverlap: number = DEFAULT_CHUNK_OVERLAP;
|
||||||
|
separator: string = " ";
|
||||||
|
backupSeparators: string[] = ["\n"];
|
||||||
|
#tokenizer: Tokenizer;
|
||||||
|
#splitFns: Array<(text: string) => string[]> = [];
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
params?: SplitterParams & Partial<z.infer<typeof tokenTextSplitterSchema>>,
|
||||||
|
) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
if (params) {
|
||||||
|
const parsedParams = tokenTextSplitterSchema.parse(params);
|
||||||
|
this.chunkSize = parsedParams.chunkSize;
|
||||||
|
this.chunkOverlap = parsedParams.chunkOverlap;
|
||||||
|
this.separator = parsedParams.separator;
|
||||||
|
this.backupSeparators = parsedParams.backupSeparators;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.chunkOverlap > this.chunkSize) {
|
||||||
|
throw new Error(
|
||||||
|
`Got a larger chunk overlap (${this.chunkOverlap}) than chunk size (${this.chunkSize}), should be smaller.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.#tokenizer = params?.tokenizer ?? Settings.tokenizer;
|
||||||
|
|
||||||
|
const allSeparators = [this.separator, ...this.backupSeparators];
|
||||||
|
this.#splitFns = allSeparators.map((sep) => splitBySep(sep));
|
||||||
|
this.#splitFns.push(splitByChar());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Split text into chunks, reserving space required for metadata string.
|
||||||
|
* @param text The text to split.
|
||||||
|
* @param metadata The metadata string.
|
||||||
|
* @returns An array of text chunks.
|
||||||
|
*/
|
||||||
|
splitTextMetadataAware(text: string, metadata: string): string[] {
|
||||||
|
const metadataLength =
|
||||||
|
this.tokenSize(metadata) + DEFAULT_METADATA_FORMAT_LEN;
|
||||||
|
const effectiveChunkSize = this.chunkSize - metadataLength;
|
||||||
|
|
||||||
|
if (effectiveChunkSize <= 0) {
|
||||||
|
throw new Error(
|
||||||
|
`Metadata length (${metadataLength}) is longer than chunk size (${this.chunkSize}). ` +
|
||||||
|
`Consider increasing the chunk size or decreasing the size of your metadata to avoid this.`,
|
||||||
|
);
|
||||||
|
} else if (effectiveChunkSize < 50) {
|
||||||
|
console.warn(
|
||||||
|
`Metadata length (${metadataLength}) is close to chunk size (${this.chunkSize}). ` +
|
||||||
|
`Resulting chunks are less than 50 tokens. Consider increasing the chunk size or decreasing the size of your metadata to avoid this.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this._splitText(text, effectiveChunkSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Split text into chunks.
|
||||||
|
* @param text The text to split.
|
||||||
|
* @returns An array of text chunks.
|
||||||
|
*/
|
||||||
|
splitText(text: string): string[] {
|
||||||
|
return this._splitText(text, this.chunkSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal method to split text into chunks up to a specified size.
|
||||||
|
* @param text The text to split.
|
||||||
|
* @param chunkSize The maximum size of each chunk.
|
||||||
|
* @returns An array of text chunks.
|
||||||
|
*/
|
||||||
|
private _splitText(text: string, chunkSize: number): string[] {
|
||||||
|
if (text === "") return [text];
|
||||||
|
|
||||||
|
// Dispatch chunking start event
|
||||||
|
Settings.callbackManager.dispatchEvent("chunking-start", { text: [text] });
|
||||||
|
|
||||||
|
const splits = this._split(text, chunkSize);
|
||||||
|
const chunks = this._merge(splits, chunkSize);
|
||||||
|
|
||||||
|
Settings.callbackManager.dispatchEvent("chunking-end", { chunks });
|
||||||
|
|
||||||
|
return chunks;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Break text into splits that are smaller than the chunk size.
|
||||||
|
* @param text The text to split.
|
||||||
|
* @param chunkSize The maximum size of each split.
|
||||||
|
* @returns An array of text splits.
|
||||||
|
*/
|
||||||
|
private _split(text: string, chunkSize: number): string[] {
|
||||||
|
if (this.tokenSize(text) <= chunkSize) {
|
||||||
|
return [text];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const splitFn of this.#splitFns) {
|
||||||
|
const splits = splitFn(text);
|
||||||
|
if (splits.length > 1) {
|
||||||
|
const newSplits: string[] = [];
|
||||||
|
for (const split of splits) {
|
||||||
|
const splitLen = this.tokenSize(split);
|
||||||
|
if (splitLen <= chunkSize) {
|
||||||
|
newSplits.push(split);
|
||||||
|
} else {
|
||||||
|
newSplits.push(...this._split(split, chunkSize));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newSplits;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [text];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merge splits into chunks with overlap.
|
||||||
|
* @param splits The array of text splits.
|
||||||
|
* @param chunkSize The maximum size of each chunk.
|
||||||
|
* @returns An array of merged text chunks.
|
||||||
|
*/
|
||||||
|
private _merge(splits: string[], chunkSize: number): string[] {
|
||||||
|
const chunks: string[] = [];
|
||||||
|
let currentChunk: string[] = [];
|
||||||
|
let currentLength = 0;
|
||||||
|
|
||||||
|
for (const split of splits) {
|
||||||
|
const splitLength = this.tokenSize(split);
|
||||||
|
|
||||||
|
if (splitLength > chunkSize) {
|
||||||
|
console.warn(
|
||||||
|
`Got a split of size ${splitLength}, larger than chunk size ${chunkSize}.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentLength + splitLength > chunkSize) {
|
||||||
|
const chunk = currentChunk.join("").trim();
|
||||||
|
if (chunk) {
|
||||||
|
chunks.push(chunk);
|
||||||
|
}
|
||||||
|
|
||||||
|
currentChunk = [];
|
||||||
|
currentLength = 0;
|
||||||
|
|
||||||
|
const overlapTokens = this.chunkOverlap;
|
||||||
|
const overlapSplits: string[] = [];
|
||||||
|
|
||||||
|
let overlapLength = 0;
|
||||||
|
while (
|
||||||
|
overlapSplits.length < splits.length &&
|
||||||
|
overlapLength < overlapTokens
|
||||||
|
) {
|
||||||
|
const overlapSplit = currentChunk.shift();
|
||||||
|
if (!overlapSplit) break;
|
||||||
|
overlapSplits.push(overlapSplit);
|
||||||
|
overlapLength += this.tokenSize(overlapSplit);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const overlapSplit of overlapSplits.reverse()) {
|
||||||
|
currentChunk.push(overlapSplit);
|
||||||
|
currentLength += this.tokenSize(overlapSplit);
|
||||||
|
if (currentLength >= overlapTokens) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
currentChunk.push(split);
|
||||||
|
currentLength += splitLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
const finalChunk = currentChunk.join("").trim();
|
||||||
|
if (finalChunk) {
|
||||||
|
chunks.push(finalChunk);
|
||||||
|
}
|
||||||
|
|
||||||
|
return chunks;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate the number of tokens in the text using the tokenizer.
|
||||||
|
* @param text The text to tokenize.
|
||||||
|
* @returns The number of tokens.
|
||||||
|
*/
|
||||||
|
private tokenSize(text: string): number {
|
||||||
|
return this.#tokenizer.encode(text).length;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,10 @@ import SentenceTokenizer from "./sentence_tokenizer";
|
|||||||
|
|
||||||
export type TextSplitterFn = (text: string) => string[];
|
export type TextSplitterFn = (text: string) => string[];
|
||||||
|
|
||||||
const truncateText = (text: string, textSplitter: TextSplitter): string => {
|
export const truncateText = (
|
||||||
|
text: string,
|
||||||
|
textSplitter: TextSplitter,
|
||||||
|
): string => {
|
||||||
const chunks = textSplitter.splitText(text);
|
const chunks = textSplitter.splitText(text);
|
||||||
return chunks[0] ?? text;
|
return chunks[0] ?? text;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
/**
|
||||||
|
* @todo refactor this module, most of the part is broken
|
||||||
|
* reference
|
||||||
|
* - https://github.com/run-llama/LlamaIndexTS/pull/531
|
||||||
|
* - https://github.com/run-llama/LlamaIndexTS/pull/416
|
||||||
|
*/
|
||||||
|
import type { MessageContent } from "../llms";
|
||||||
|
import { BaseRetriever } from "../retriever";
|
||||||
|
import { BaseNode, TextNode } from "../schema";
|
||||||
|
import { extractText } from "../utils";
|
||||||
|
|
||||||
|
// Assuming that necessary interfaces and classes (like OT, TextNode, BaseNode, etc.) are defined elsewhere
|
||||||
|
// Import statements (e.g., for TextNode, BaseNode) should be added based on your project's structure
|
||||||
|
export abstract class BaseObjectNodeMapping {
|
||||||
|
// TypeScript doesn't support Python's classmethod directly, but we can use static methods as an alternative
|
||||||
|
abstract fromObjects<OT>(objs: OT[], ...args: any[]): BaseObjectNodeMapping;
|
||||||
|
|
||||||
|
// Abstract methods in TypeScript
|
||||||
|
abstract objNodeMapping(): Record<any, any>;
|
||||||
|
abstract toNode(obj: any): TextNode;
|
||||||
|
|
||||||
|
// Concrete methods can be defined as usual
|
||||||
|
validateObject(obj: any): void {}
|
||||||
|
|
||||||
|
// Implementing the add object logic
|
||||||
|
addObj(obj: any): void {
|
||||||
|
this.validateObject(obj);
|
||||||
|
this._addObj(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Abstract method for internal add object logic
|
||||||
|
abstract _addObj(obj: any): void;
|
||||||
|
|
||||||
|
// Implementing toNodes method
|
||||||
|
toNodes(objs: any[]): TextNode[] {
|
||||||
|
return objs.map((obj) => this.toNode(obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Abstract method for internal from node logic
|
||||||
|
abstract _fromNode(node: BaseNode): any;
|
||||||
|
|
||||||
|
// Implementing fromNode method
|
||||||
|
fromNode(node: BaseNode): any {
|
||||||
|
const obj = this._fromNode(node);
|
||||||
|
this.validateObject(obj);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Abstract methods for persistence
|
||||||
|
abstract persist(persistDir: string, objNodeMappingFilename: string): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ObjectRetriever<T = unknown> {
|
||||||
|
_retriever: BaseRetriever;
|
||||||
|
_objectNodeMapping: BaseObjectNodeMapping;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
retriever: BaseRetriever,
|
||||||
|
objectNodeMapping: BaseObjectNodeMapping,
|
||||||
|
) {
|
||||||
|
this._retriever = retriever;
|
||||||
|
this._objectNodeMapping = objectNodeMapping;
|
||||||
|
}
|
||||||
|
|
||||||
|
// In TypeScript, getters are defined like this.
|
||||||
|
get retriever(): BaseRetriever {
|
||||||
|
return this._retriever;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Translating the retrieve method
|
||||||
|
async retrieve(strOrQueryBundle: MessageContent): Promise<T[]> {
|
||||||
|
const nodes = await this.retriever.retrieve({
|
||||||
|
query: extractText(strOrQueryBundle),
|
||||||
|
});
|
||||||
|
const objs = nodes.map((n) => this._objectNodeMapping.fromNode(n.node));
|
||||||
|
return objs;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,11 +12,15 @@ export {
|
|||||||
defaultCondenseQuestionPrompt,
|
defaultCondenseQuestionPrompt,
|
||||||
defaultContextSystemPrompt,
|
defaultContextSystemPrompt,
|
||||||
defaultKeywordExtractPrompt,
|
defaultKeywordExtractPrompt,
|
||||||
|
defaultNodeTextTemplate,
|
||||||
defaultQueryKeywordExtractPrompt,
|
defaultQueryKeywordExtractPrompt,
|
||||||
|
defaultQuestionExtractPrompt,
|
||||||
defaultRefinePrompt,
|
defaultRefinePrompt,
|
||||||
defaultSubQuestionPrompt,
|
defaultSubQuestionPrompt,
|
||||||
defaultSummaryPrompt,
|
defaultSummaryPrompt,
|
||||||
defaultTextQAPrompt,
|
defaultTextQAPrompt,
|
||||||
|
defaultTitleCombinePromptTemplate,
|
||||||
|
defaultTitleExtractorPromptTemplate,
|
||||||
defaultTreeSummarizePrompt,
|
defaultTreeSummarizePrompt,
|
||||||
} from "./prompt";
|
} from "./prompt";
|
||||||
export type {
|
export type {
|
||||||
@@ -25,9 +29,12 @@ export type {
|
|||||||
ContextSystemPrompt,
|
ContextSystemPrompt,
|
||||||
KeywordExtractPrompt,
|
KeywordExtractPrompt,
|
||||||
QueryKeywordExtractPrompt,
|
QueryKeywordExtractPrompt,
|
||||||
|
QuestionExtractPrompt,
|
||||||
RefinePrompt,
|
RefinePrompt,
|
||||||
SubQuestionPrompt,
|
SubQuestionPrompt,
|
||||||
SummaryPrompt,
|
SummaryPrompt,
|
||||||
TextQAPrompt,
|
TextQAPrompt,
|
||||||
|
TitleCombinePrompt,
|
||||||
|
TitleExtractorPrompt,
|
||||||
TreeSummarizePrompt,
|
TreeSummarizePrompt,
|
||||||
} from "./prompt";
|
} from "./prompt";
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user