Compare commits

..

8 Commits

Author SHA1 Message Date
github-actions[bot] 38487da65d Release 0.11.23 (#2136)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: marcusschiesser <17126+marcusschiesser@users.noreply.github.com>
2025-07-28 14:07:23 +08:00
Marcus Schiesser f29799e385 feat: Add toolcall callbacks to agent workflows (#2137) 2025-07-24 15:37:14 +08:00
Marcus Schiesser 9bca30620b fix: docs build 2025-07-23 12:55:35 +08:00
Marcus Schiesser 7224c06409 feat: Add logger and callbacks to llm.exec (#2135) 2025-07-23 12:37:02 +08:00
github-actions[bot] 29c7cf0989 Release 0.11.22 (#2131)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-07-23 11:30:04 +08:00
Marcus Schiesser c65a2dc4a7 chore: Deprecate community package and link to AWS package (#2134) 2025-07-23 11:05:50 +08:00
Terence Sim f1c5079290 docs: updated bedrock import and supported models (#2129)
Co-authored-by: Terence Sim <40583743+InTheAxis@users.noreply.github.com>
2025-07-23 10:40:49 +08:00
Terence Sim 9ed31958a7 chore: add logger as param to AgentWorkflow constructor (#2130)
Co-authored-by: Terence Sim <40583743+InTheAxis@users.noreply.github.com>
Co-authored-by: Marcus Schiesser <marcus.schiesser@googlemail.com>
2025-07-22 16:35:28 +08:00
157 changed files with 4000 additions and 217 deletions
+22
View File
@@ -1,5 +1,27 @@
# @llamaindex/doc
## 0.2.46
### Patch Changes
- Updated dependencies [f29799e]
- Updated dependencies [7224c06]
- @llamaindex/workflow@1.1.19
- @llamaindex/core@0.6.18
- llamaindex@0.11.23
- @llamaindex/cloud@4.0.27
- @llamaindex/node-parser@2.0.18
- @llamaindex/openai@0.4.13
- @llamaindex/readers@3.1.17
## 0.2.45
### Patch Changes
- Updated dependencies [9ed3195]
- @llamaindex/workflow@1.1.18
- llamaindex@0.11.22
## 0.2.44
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/doc",
"version": "0.2.44",
"version": "0.2.46",
"private": true,
"scripts": {
"postinstall": "fumadocs-mdx",
@@ -0,0 +1,164 @@
---
title: Low-Level LLM Execution
---
Sometimes your need more control over LLM interactions than what high-level agents provide. The `llm.exec` method makes it simple for you to make a single LLM call with tools but hides the complexity of executing the tools and generating the tool messages.
## When to Use `llm.exec`
Use `llm.exec` when you need to:
- Build custom agent logic in [workflow](/docs/llamaindex/modules/agents/workflows) steps
- Have precise control over message handling and tool execution
## Basic Usage
The `llm.exec` method takes messages and tools as parameter and executes one LLM call.
The LLM might either request to call one or more of the tools or generate an assistant message as result.
For each tool call that is requested, `llm.exec` executes it and generates the two tool call messages (call and result). If no tool call is requested, just the assistant message is returned.
```ts
import { openai } from "@llamaindex/openai";
import { ChatMessage, tool } from "llamaindex";
import z from "zod";
const llm = openai({ model: "gpt-4.1-mini" });
const messages = [
{
content: "What's the weather like in San Francisco?",
role: "user",
} as ChatMessage,
];
const { newMessages, toolCalls } = await llm.exec({
messages,
tools: [
tool({
name: "get_weather",
description: "Get the current weather for a location",
parameters: z.object({
address: z.string().describe("The address"),
}),
execute: ({ address }) => {
return `It's sunny in ${address}!`;
},
}),
],
});
// Add the new messages (including tool calls and responses) to your conversation
messages.push(...newMessages);
```
> `newMessages` is an array as each tool call generates two messages: a tool call message and the tool call result message.
## Agent Loop Pattern
A common pattern is to use `llm.exec` in a loop until the LLM stops making tool calls:
```ts
import { openai } from "@llamaindex/openai";
import { ChatMessage, tool } from "llamaindex";
import z from "zod";
async function runAgentLoop() {
const llm = openai({ model: "gpt-4.1-mini" });
const messages = [
{
content: "What's the weather like in San Francisco?",
role: "user",
} as ChatMessage,
];
let exit = false;
do {
const { newMessages, toolCalls } = await llm.exec({
messages,
tools: [
tool({
name: "get_weather",
description: "Get the current weather for a location",
parameters: z.object({
address: z.string().describe("The address"),
}),
execute: ({ address }) => {
return `It's sunny in ${address}!`;
},
}),
],
});
console.log(newMessages);
messages.push(...newMessages);
// Exit when no more tool calls are made
exit = toolCalls.length === 0;
} while (!exit);
}
```
## Streaming Support
For real-time responses, use the `stream` option to get the assistant's response as streamed tokens:
```ts
import { openai } from "@llamaindex/openai";
import { tool } from "llamaindex";
import z from "zod";
async function streamingAgentLoop() {
const llm = openai({ model: "gpt-4o-mini" });
const messages = [
{
content: "What's the weather like in San Francisco?",
role: "user",
} as ChatMessage,
];
let exit = false;
do {
const { stream, newMessages, toolCalls } = await llm.exec({
messages,
tools: [
tool({
name: "get_weather",
description: "Get the current weather for a location",
parameters: z.object({
address: z.string().describe("The address"),
}),
execute: ({ address }) => {
return `It's sunny in ${address}!`;
},
}),
],
stream: true,
});
// Stream the response token by token
for await (const chunk of stream) {
process.stdout.write(chunk.delta);
}
messages.push(...newMessages());
exit = toolCalls.length === 0;
} while (!exit);
}
```
> `newMessages` is a function when streaming. The reason is that the result only is available after streaming. Calling it before, will throw an error.
## Return Values
`llm.exec` returns an object with:
- **`newMessages`**: Array of new chat messages including the LLM response and any tool call messages (call or result). This is a function return the array when streaming.
- **`toolCalls`**: Array of tool calls made by the LLM
- **`stream`**: Async iterable for streaming responses (only when `stream: true`)
## Best Practices
For using `llm.exec` in an agent loop, take care to:
1. **Maintain message history**: Always add `newMessages` to your conversation history
2. **Set exit conditions**: Implement proper logic to avoid infinite loops
@@ -1,4 +1,10 @@
{
"title": "Agents",
"pages": ["tool", "agent_workflow", "workflows", "natural_language_workflow"]
"pages": [
"tool",
"agent_workflow",
"workflows",
"low-level",
"natural_language_workflow"
]
}
@@ -5,13 +5,13 @@ title: Bedrock
## Installation
```package-install
npm i llamaindex @llamaindex/community
npm i llamaindex @llamaindex/aws
```
## Usage
```ts
import { BEDROCK_MODELS, Bedrock } from "@llamaindex/community";
import { BEDROCK_MODELS, Bedrock } from "@llamaindex/aws";
Settings.llm = new Bedrock({
model: BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_HAIKU,
@@ -23,9 +23,19 @@ Settings.llm = new Bedrock({
});
```
Currently only supports Anthropic and Meta models:
Supported models are listed below (accessible by BEDROCK_MODELS).
```ts
AMAZON_TITAN_TG1_LARGE = "amazon.titan-tg1-large";
AMAZON_TITAN_TEXT_EXPRESS_V1 = "amazon.titan-text-express-v1";
AI21_J2_GRANDE_INSTRUCT = "ai21.j2-grande-instruct";
AI21_J2_JUMBO_INSTRUCT = "ai21.j2-jumbo-instruct";
AI21_J2_MID = "ai21.j2-mid";
AI21_J2_MID_V1 = "ai21.j2-mid-v1";
AI21_J2_ULTRA = "ai21.j2-ultra";
AI21_J2_ULTRA_V1 = "ai21.j2-ultra-v1";
COHERE_COMMAND_TEXT_V14 = "cohere.command-text-v14";
ANTHROPIC_CLAUDE_INSTANT_1 = "anthropic.claude-instant-v1";
ANTHROPIC_CLAUDE_2 = "anthropic.claude-v2";
ANTHROPIC_CLAUDE_2_1 = "anthropic.claude-v2:1";
@@ -33,7 +43,12 @@ 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_OPUS = "anthropic.claude-3-opus-20240229-v1:0"; // available on us-west-2
ANTHROPIC_CLAUDE_3_5_SONNET = "anthropic.claude-3-5-sonnet-20240620-v1:0";
ANTHROPIC_CLAUDE_3_5_SONNET_V2 = "anthropic.claude-3-5-sonnet-20241022-v2:0";
ANTHROPIC_CLAUDE_3_5_HAIKU = "anthropic.claude-3-5-haiku-20241022-v1:0";
ANTHROPIC_CLAUDE_3_7_SONNET = "anthropic.claude-3-7-sonnet-20250219-v1:0";
ANTHROPIC_CLAUDE_4_SONNET = "anthropic.claude-sonnet-4-20250514-v1:0";
ANTHROPIC_CLAUDE_4_OPUS = "anthropic.claude-opus-4-20250514-v1:0";
META_LLAMA2_13B_CHAT = "meta.llama2-13b-chat-v1";
META_LLAMA2_70B_CHAT = "meta.llama2-70b-chat-v1";
META_LLAMA3_8B_INSTRUCT = "meta.llama3-8b-instruct-v1:0";
@@ -45,41 +60,66 @@ META_LLAMA3_2_1B_INSTRUCT = "meta.llama3-2-1b-instruct-v1:0"; // only available
META_LLAMA3_2_3B_INSTRUCT = "meta.llama3-2-3b-instruct-v1:0"; // only available via inference endpoints (see below)
META_LLAMA3_2_11B_INSTRUCT = "meta.llama3-2-11b-instruct-v1:0"; // only available via inference endpoints (see below), multimodal and function call supported
META_LLAMA3_2_90B_INSTRUCT = "meta.llama3-2-90b-instruct-v1:0"; // only available via inference endpoints (see below), multimodal and function call supported
META_LLAMA3_3_70B_INSTRUCT = "meta.llama3-3-70b-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";
AMAZON_NOVA_PREMIER_1 = "amazon.nova-premier-v1:0";
AMAZON_NOVA_PRO_1 = "amazon.nova-pro-v1:0";
AMAZON_NOVA_LITE_1 = "amazon.nova-lite-v1:0";
AMAZON_NOVA_MICRO_1 = "amazon.nova-micro-v1:0";
```
You can also use Bedrock's Inference endpoints by using the model names:
You can also use Bedrock's Inference endpoints by using the model names (accessible by INFERENCE_BEDROCK_MODELS).
Note that the region must be set correctly.
```ts
// US
//US
US_ANTHROPIC_CLAUDE_3_HAIKU = "us.anthropic.claude-3-haiku-20240307-v1:0";
US_ANTHROPIC_CLAUDE_3_5_HAIKU = "us.anthropic.claude-3-5-haiku-20241022-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_ANTHROPIC_CLAUDE_3_5_SONNET_V2 =
"us.anthropic.claude-3-5-sonnet-20241022-v2:0";
US_ANTHROPIC_CLAUDE_3_5_SONNET_V2 = "us.anthropic.claude-3-5-sonnet-20241022-v2:0";
US_ANTHROPIC_CLAUDE_3_7_SONNET = "us.anthropic.claude-3-7-sonnet-20250219-v1:0";
US_ANTHROPIC_CLAUDE_4_SONNET = "us.anthropic.claude-sonnet-4-20250514-v1:0";
US_ANTHROPIC_CLAUDE_4_OPUS = "us.anthropic.claude-opus-4-20250514-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";
US_AMAZON_NOVA_PRO_1 = "us.amazon.nova-premier-v1:0";
US_META_LLAMA_3_3_70B_INSTRUCT = "us.meta.llama3-3-70b-instruct-v1:0";
US_AMAZON_NOVA_PREMIER_1 = "us.amazon.nova-premier-v1:0";
US_AMAZON_NOVA_PRO_1 = "us.amazon.nova-pro-v1:0";
US_AMAZON_NOVA_LITE_1 = "us.amazon.nova-lite-v1:0";
US_AMAZON_NOVA_MICRO_1 = "us.amazon.nova-micro-v1:0";
// EU
//EU
EU_ANTHROPIC_CLAUDE_3_HAIKU = "eu.anthropic.claude-3-haiku-20240307-v1:0";
EU_ANTHROPIC_CLAUDE_3_5_HAIKU = "eu.anthropic.claude-3-5-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_ANTHROPIC_CLAUDE_3_7_SONNET = "eu.anthropic.claude-3-7-sonnet-20250219-v1:0";
EU_ANTHROPIC_CLAUDE_4_SONNET = "eu.anthropic.claude-sonnet-4-20250514-v1:0";
EU_ANTHROPIC_CLAUDE_4_OPUS = "eu.anthropic.claude-opus-4-20250514-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";
EU_AMAZON_NOVA_PRO_1 = "eu.amazon.nova-premier-v1:0";
EU_AMAZON_NOVA_PREMIER_1 = "eu.amazon.nova-premier-v1:0";
EU_AMAZON_NOVA_PRO_1 = "eu.amazon.nova-pro-v1:0";
EU_AMAZON_NOVA_LITE_1 = "eu.amazon.nova-lite-v1:0";
EU_AMAZON_NOVA_MICRO_1 = "eu.amazon.nova-micro-v1:0";
//APAC
APAC_ANTHROPIC_CLAUDE_3_5_SONNET = "apac.anthropic.claude-3-5-sonnet-20240620-v1:0";
APAC_ANTHROPIC_CLAUDE_3_5_SONNET_V2 = "apac.anthropic.claude-3-5-sonnet-20241022-v2:0";
APAC_ANTHROPIC_CLAUDE_3_7_SONNET = "apac.anthropic.claude-3-7-sonnet-20250219-v1:0";
APAC_ANTHROPIC_CLAUDE_3_HAIKU = "apac.anthropic.claude-3-haiku-20240307-v1:0";
APAC_ANTHROPIC_CLAUDE_3_SONNET = "apac.anthropic.claude-3-sonnet-20240229-v1:0";
APAC_AMAZON_NOVA_PRO_1 = "apac.amazon.nova-pro-v1:0";
APAC_AMAZON_NOVA_LITE_1 = "apac.amazon.nova-lite-v1:0";
APAC_AMAZON_NOVA_MICRO_1 = "apac.amazon.nova-micro-v1:0";
```
Sonnet, Haiku and Opus are multimodal, image_url only supports base64 data url format, e.g. `data:image/jpeg;base64,SGVsbG8sIFdvcmxkIQ==`
@@ -87,10 +127,11 @@ Sonnet, Haiku and Opus are multimodal, image_url only supports base64 data url f
## Full Example
```ts
import { BEDROCK_MODELS, Bedrock } from "llamaindex";
import { INFERENCE_BEDROCK_MODELS, Bedrock } from "@llamaindex/aws";
Settings.llm = new Bedrock({
model: BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_HAIKU,
model: INFERENCE_BEDROCK_MODELS.US_ANTHROPIC_CLAUDE_3_SONNET,
region: "us-east-1",
});
async function main() {
@@ -119,7 +160,7 @@ async function main() {
## Agent Example
```ts
import { BEDROCK_MODELS, Bedrock } from "@llamaindex/community";
import { BEDROCK_MODELS, Bedrock } from "@llamaindex/aws";
import { tool } from "llamaindex";
import { agent } from "@llamaindex/workflow";
import { z } from "zod";
@@ -1,5 +1,17 @@
# @llamaindex/cloudflare-worker-agent-test
## 0.0.184
### Patch Changes
- llamaindex@0.11.23
## 0.0.183
### Patch Changes
- llamaindex@0.11.22
## 0.0.182
### Patch Changes
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/cloudflare-worker-agent-test",
"version": "0.0.182",
"version": "0.0.184",
"type": "module",
"private": true,
"scripts": {
@@ -1,5 +1,11 @@
# @llamaindex/llama-parse-browser-test
## 0.0.82
### Patch Changes
- @llamaindex/cloud@4.0.27
## 0.0.81
### Patch Changes
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/llama-parse-browser-test",
"private": true,
"version": "0.0.81",
"version": "0.0.82",
"type": "module",
"scripts": {
"dev": "vite",
+12
View File
@@ -1,5 +1,17 @@
# @llamaindex/next-agent-test
## 0.1.184
### Patch Changes
- llamaindex@0.11.23
## 0.1.183
### Patch Changes
- llamaindex@0.11.22
## 0.1.182
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/next-agent-test",
"version": "0.1.182",
"version": "0.1.184",
"private": true,
"scripts": {
"dev": "next dev",
@@ -1,5 +1,17 @@
# test-edge-runtime
## 0.1.183
### Patch Changes
- llamaindex@0.11.23
## 0.1.182
### Patch Changes
- llamaindex@0.11.22
## 0.1.181
### Patch Changes
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/nextjs-edge-runtime-test",
"version": "0.1.181",
"version": "0.1.183",
"private": true,
"scripts": {
"dev": "next dev",
@@ -1,5 +1,19 @@
# @llamaindex/next-node-runtime
## 0.1.53
### Patch Changes
- llamaindex@0.11.23
- @llamaindex/huggingface@0.1.23
- @llamaindex/readers@3.1.17
## 0.1.52
### Patch Changes
- llamaindex@0.11.22
## 0.1.51
### Patch Changes
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/next-node-runtime-test",
"version": "0.1.51",
"version": "0.1.53",
"private": true,
"scripts": {
"dev": "next dev",
@@ -1,5 +1,17 @@
# vite-import-llamaindex
## 0.0.50
### Patch Changes
- llamaindex@0.11.23
## 0.0.49
### Patch Changes
- llamaindex@0.11.22
## 0.0.48
### Patch Changes
@@ -1,7 +1,7 @@
{
"name": "vite-import-llamaindex",
"private": true,
"version": "0.0.48",
"version": "0.0.50",
"type": "module",
"scripts": {
"build": "vite build",
@@ -1,5 +1,17 @@
# @llamaindex/waku-query-engine-test
## 0.0.184
### Patch Changes
- llamaindex@0.11.23
## 0.0.183
### Patch Changes
- llamaindex@0.11.22
## 0.0.182
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/waku-query-engine-test",
"version": "0.0.182",
"version": "0.0.184",
"type": "module",
"private": true,
"scripts": {
+53
View File
@@ -1,5 +1,58 @@
# examples
## 0.3.34
### Patch Changes
- Updated dependencies [f29799e]
- Updated dependencies [7224c06]
- @llamaindex/workflow@1.1.19
- @llamaindex/core@0.6.18
- llamaindex@0.11.23
- @llamaindex/cloud@4.0.27
- @llamaindex/node-parser@2.0.18
- @llamaindex/anthropic@0.3.20
- @llamaindex/assemblyai@0.1.17
- @llamaindex/clip@0.0.69
- @llamaindex/cohere@0.0.32
- @llamaindex/deepinfra@0.0.69
- @llamaindex/discord@0.1.17
- @llamaindex/google@0.3.17
- @llamaindex/huggingface@0.1.23
- @llamaindex/jinaai@0.0.29
- @llamaindex/mistral@0.1.18
- @llamaindex/mixedbread@0.0.32
- @llamaindex/notion@0.1.17
- @llamaindex/ollama@0.1.18
- @llamaindex/openai@0.4.13
- @llamaindex/perplexity@0.0.26
- @llamaindex/portkey-ai@0.0.60
- @llamaindex/replicate@0.0.60
- @llamaindex/bm25-retriever@0.0.7
- @llamaindex/astra@0.0.32
- @llamaindex/azure@0.1.30
- @llamaindex/chroma@0.0.32
- @llamaindex/elastic-search@0.1.18
- @llamaindex/firestore@1.0.25
- @llamaindex/milvus@0.1.27
- @llamaindex/mongodb@0.0.33
- @llamaindex/pinecone@0.1.18
- @llamaindex/postgres@0.0.61
- @llamaindex/qdrant@0.1.28
- @llamaindex/supabase@0.1.19
- @llamaindex/upstash@0.0.32
- @llamaindex/weaviate@0.0.33
- @llamaindex/vercel@0.1.18
- @llamaindex/voyage-ai@1.0.24
- @llamaindex/readers@3.1.17
- @llamaindex/tools@0.1.8
- @llamaindex/deepseek@0.0.30
- @llamaindex/fireworks@0.0.29
- @llamaindex/groq@0.0.85
- @llamaindex/together@0.0.29
- @llamaindex/vllm@0.0.55
- @llamaindex/xai@0.0.16
## 0.3.33
### Patch Changes
+47 -47
View File
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/examples",
"version": "0.3.33",
"version": "0.3.34",
"private": true,
"scripts": {
"lint": "eslint .",
@@ -11,52 +11,52 @@
"@azure/cosmos": "^4.1.1",
"@azure/identity": "^4.4.1",
"@azure/search-documents": "^12.1.0",
"@llamaindex/anthropic": "^0.3.19",
"@llamaindex/assemblyai": "^0.1.16",
"@llamaindex/astra": "^0.0.31",
"@llamaindex/azure": "^0.1.29",
"@llamaindex/bm25-retriever": "^0.0.6",
"@llamaindex/chroma": "^0.0.31",
"@llamaindex/clip": "^0.0.68",
"@llamaindex/cloud": "^4.0.26",
"@llamaindex/cohere": "^0.0.31",
"@llamaindex/core": "^0.6.17",
"@llamaindex/deepinfra": "^0.0.68",
"@llamaindex/deepseek": "^0.0.29",
"@llamaindex/discord": "^0.1.16",
"@llamaindex/elastic-search": "^0.1.17",
"@llamaindex/anthropic": "^0.3.20",
"@llamaindex/assemblyai": "^0.1.17",
"@llamaindex/astra": "^0.0.32",
"@llamaindex/azure": "^0.1.30",
"@llamaindex/bm25-retriever": "^0.0.7",
"@llamaindex/chroma": "^0.0.32",
"@llamaindex/clip": "^0.0.69",
"@llamaindex/cloud": "^4.0.27",
"@llamaindex/cohere": "^0.0.32",
"@llamaindex/core": "^0.6.18",
"@llamaindex/deepinfra": "^0.0.69",
"@llamaindex/deepseek": "^0.0.30",
"@llamaindex/discord": "^0.1.17",
"@llamaindex/elastic-search": "^0.1.18",
"@llamaindex/env": "^0.1.30",
"@llamaindex/firestore": "^1.0.24",
"@llamaindex/fireworks": "^0.0.28",
"@llamaindex/google": "^0.3.16",
"@llamaindex/groq": "^0.0.84",
"@llamaindex/huggingface": "^0.1.22",
"@llamaindex/jinaai": "^0.0.28",
"@llamaindex/milvus": "^0.1.26",
"@llamaindex/mistral": "^0.1.17",
"@llamaindex/mixedbread": "^0.0.31",
"@llamaindex/mongodb": "^0.0.32",
"@llamaindex/node-parser": "^2.0.17",
"@llamaindex/notion": "^0.1.16",
"@llamaindex/ollama": "^0.1.17",
"@llamaindex/openai": "^0.4.12",
"@llamaindex/perplexity": "^0.0.25",
"@llamaindex/pinecone": "^0.1.17",
"@llamaindex/portkey-ai": "^0.0.59",
"@llamaindex/postgres": "^0.0.60",
"@llamaindex/qdrant": "^0.1.27",
"@llamaindex/readers": "^3.1.16",
"@llamaindex/replicate": "^0.0.59",
"@llamaindex/supabase": "^0.1.18",
"@llamaindex/together": "^0.0.28",
"@llamaindex/tools": "^0.1.7",
"@llamaindex/upstash": "^0.0.31",
"@llamaindex/vercel": "^0.1.17",
"@llamaindex/vllm": "^0.0.54",
"@llamaindex/voyage-ai": "^1.0.23",
"@llamaindex/weaviate": "^0.0.32",
"@llamaindex/workflow": "^1.1.17",
"@llamaindex/xai": "^0.0.15",
"@llamaindex/firestore": "^1.0.25",
"@llamaindex/fireworks": "^0.0.29",
"@llamaindex/google": "^0.3.17",
"@llamaindex/groq": "^0.0.85",
"@llamaindex/huggingface": "^0.1.23",
"@llamaindex/jinaai": "^0.0.29",
"@llamaindex/milvus": "^0.1.27",
"@llamaindex/mistral": "^0.1.18",
"@llamaindex/mixedbread": "^0.0.32",
"@llamaindex/mongodb": "^0.0.33",
"@llamaindex/node-parser": "^2.0.18",
"@llamaindex/notion": "^0.1.17",
"@llamaindex/ollama": "^0.1.18",
"@llamaindex/openai": "^0.4.13",
"@llamaindex/perplexity": "^0.0.26",
"@llamaindex/pinecone": "^0.1.18",
"@llamaindex/portkey-ai": "^0.0.60",
"@llamaindex/postgres": "^0.0.61",
"@llamaindex/qdrant": "^0.1.28",
"@llamaindex/readers": "^3.1.17",
"@llamaindex/replicate": "^0.0.60",
"@llamaindex/supabase": "^0.1.19",
"@llamaindex/together": "^0.0.29",
"@llamaindex/tools": "^0.1.8",
"@llamaindex/upstash": "^0.0.32",
"@llamaindex/vercel": "^0.1.18",
"@llamaindex/vllm": "^0.0.55",
"@llamaindex/voyage-ai": "^1.0.24",
"@llamaindex/weaviate": "^0.0.33",
"@llamaindex/workflow": "^1.1.19",
"@llamaindex/xai": "^0.0.16",
"@notionhq/client": "^4.0.0",
"@pinecone-database/pinecone": "^4.0.0",
"@vercel/postgres": "^0.10.0",
@@ -65,7 +65,7 @@
"commander": "^12.1.0",
"dotenv": "^17.2.0",
"js-tiktoken": "^1.0.14",
"llamaindex": "^0.11.21",
"llamaindex": "^0.11.23",
"mongodb": "6.7.0",
"postgres": "^3.4.4",
"wikipedia": "^2.1.2",
+12
View File
@@ -1,5 +1,17 @@
# @llamaindex/autotool
## 8.0.23
### Patch Changes
- llamaindex@0.11.23
## 8.0.22
### Patch Changes
- llamaindex@0.11.22
## 8.0.21
### Patch Changes
@@ -1,5 +1,19 @@
# @llamaindex/autotool-01-node-example
## 0.0.131
### Patch Changes
- llamaindex@0.11.23
- @llamaindex/autotool@8.0.23
## 0.0.130
### Patch Changes
- llamaindex@0.11.22
- @llamaindex/autotool@8.0.22
## 0.0.129
### Patch Changes
@@ -13,5 +13,5 @@
"scripts": {
"start": "node --import tsx --import @llamaindex/autotool/node ./src/index.ts"
},
"version": "0.0.129"
"version": "0.0.131"
}
+1 -1
View File
@@ -6,7 +6,7 @@
"url": "git+https://github.com/run-llama/LlamaIndexTS.git",
"directory": "packages/autotool"
},
"version": "8.0.21",
"version": "8.0.23",
"description": "auto transpile your JS function to LLM Agent compatible",
"files": [
"dist",
+8
View File
@@ -1,5 +1,13 @@
# @llamaindex/cloud
## 4.0.27
### Patch Changes
- Updated dependencies [f29799e]
- Updated dependencies [7224c06]
- @llamaindex/core@0.6.18
## 4.0.26
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/cloud",
"version": "4.0.26",
"version": "4.0.27",
"type": "module",
"license": "MIT",
"scripts": {
+770
View File
@@ -0,0 +1,770 @@
# @llamaindex/community
## 0.0.100
### Patch Changes
- Updated dependencies [f29799e]
- Updated dependencies [7224c06]
- @llamaindex/core@0.6.18
## 0.0.99
### Patch Changes
- c65a2dc: Deprecate community package and link to AWS package
## 0.0.98
### Patch Changes
- Updated dependencies [9b2e25a]
- @llamaindex/core@0.6.4
- @llamaindex/env@0.1.30
## 0.0.97
### Patch Changes
- Updated dependencies [3ee8c83]
- @llamaindex/core@0.6.3
## 0.0.96
### Patch Changes
- e9bf442: fix: update the tool call schema for nova
## 0.0.95
### Patch Changes
- 411dcea: Add Nova Premier to AWS Nova models. Add EU endpoints
## 0.0.94
### Patch Changes
- Updated dependencies [9c63f3f]
- @llamaindex/core@0.6.2
## 0.0.93
### Patch Changes
- Updated dependencies [1b6f368]
- Updated dependencies [eaf326e]
- @llamaindex/core@0.6.1
## 0.0.92
### Patch Changes
- 1325178: fix: stringify all tool results for anthropic on bedrock
## 0.0.91
### Patch Changes
- 5189b44: fix: add retry handling logic to parser reader and fix lint issues
- 3fd4cc3: feat: use google's new gen ai library to support multimodal output
- Updated dependencies [21bebfc]
- Updated dependencies [93bc0ff]
- Updated dependencies [91a18e7]
- Updated dependencies [5189b44]
- @llamaindex/core@0.6.0
## 0.0.90
### Patch Changes
- Updated dependencies [40ee761]
- @llamaindex/core@0.5.8
## 0.0.89
### Patch Changes
- Updated dependencies [4bac71d]
- @llamaindex/core@0.5.7
## 0.0.88
### Patch Changes
- e28c29d: Added Llama 3.3 70B Instruct support
- Updated dependencies [beb922b]
- @llamaindex/env@0.1.29
- @llamaindex/core@0.5.6
## 0.0.87
### Patch Changes
- Updated dependencies [5668970]
- @llamaindex/core@0.5.5
## 0.0.86
### Patch Changes
- Updated dependencies [ad3c7f1]
- @llamaindex/core@0.5.4
## 0.0.85
### Patch Changes
- 1914b52: Added Claude 3.7 Sonnet support
- Updated dependencies [cb021e7]
- @llamaindex/core@0.5.3
## 0.0.84
### Patch Changes
- Updated dependencies [d952e68]
- @llamaindex/core@0.5.2
## 0.0.83
### Patch Changes
- Updated dependencies [cc50c9c]
- @llamaindex/env@0.1.28
- @llamaindex/core@0.5.1
## 0.0.82
### Patch Changes
- Updated dependencies [6a4a737]
- Updated dependencies [d924c63]
- @llamaindex/core@0.5.0
## 0.0.81
### Patch Changes
- 1c908fd: Revert previous release (not working with CJS)
- Updated dependencies [1c908fd]
- @llamaindex/core@0.4.23
- @llamaindex/env@0.1.27
## 0.0.80
### Patch Changes
- cb608b5: fix: bundle output incorrect
- Updated dependencies [cb608b5]
- @llamaindex/core@0.4.22
- @llamaindex/env@0.1.26
## 0.0.79
### Patch Changes
- Updated dependencies [9456616]
- Updated dependencies [1931bbc]
- @llamaindex/core@0.4.21
## 0.0.78
### Patch Changes
- Updated dependencies [d211b7a]
- @llamaindex/core@0.4.20
## 0.0.77
### Patch Changes
- 24caf93: fix: added inference profile mapping for nova models"
- Updated dependencies [a9b5b99]
- @llamaindex/core@0.4.19
## 0.0.76
### Patch Changes
- c1850ee: feat: Amazon Nova support via Bedrock
- Updated dependencies [b504303]
- Updated dependencies [e0f6cc3]
- @llamaindex/env@0.1.25
- @llamaindex/core@0.4.18
## 0.0.75
### Patch Changes
- Updated dependencies [3d1808b]
- @llamaindex/core@0.4.17
## 0.0.74
### Patch Changes
- 8be4589: chore: bump version
- Updated dependencies [8be4589]
- @llamaindex/core@0.4.16
- @llamaindex/env@0.1.24
## 0.0.73
### Patch Changes
- Updated dependencies [d2b2722]
- @llamaindex/env@0.1.23
- @llamaindex/core@0.4.15
## 0.0.72
### Patch Changes
- Updated dependencies [969365c]
- @llamaindex/env@0.1.22
- @llamaindex/core@0.4.14
## 0.0.71
### Patch Changes
- 90d265c: chore: bump version
- Updated dependencies [90d265c]
- @llamaindex/core@0.4.13
- @llamaindex/env@0.1.21
## 0.0.70
### Patch Changes
- Updated dependencies [ef4f63d]
- @llamaindex/core@0.4.12
## 0.0.69
### Patch Changes
- Updated dependencies [6d22fa2]
- @llamaindex/core@0.4.11
## 0.0.68
### Patch Changes
- Updated dependencies [a7b0ac3]
- Updated dependencies [c69605f]
- @llamaindex/core@0.4.10
## 0.0.67
### Patch Changes
- Updated dependencies [7ae6eaa]
- @llamaindex/core@0.4.9
## 0.0.66
### Patch Changes
- Updated dependencies [f865c98]
- @llamaindex/core@0.4.8
## 0.0.65
### Patch Changes
- Updated dependencies [d89ebe0]
- Updated dependencies [fd8c882]
- @llamaindex/core@0.4.7
## 0.0.64
### Patch Changes
- Updated dependencies [4fc001c]
- @llamaindex/env@0.1.20
- @llamaindex/core@0.4.6
## 0.0.63
### Patch Changes
- Updated dependencies [ad85bd0]
- @llamaindex/core@0.4.5
- @llamaindex/env@0.1.19
## 0.0.62
### Patch Changes
- Updated dependencies [a8d3fa6]
- @llamaindex/env@0.1.18
- @llamaindex/core@0.4.4
## 0.0.61
### Patch Changes
- 487782c: Add missing inference endpoints for Haiku 3.5
- Updated dependencies [95a5cc6]
- @llamaindex/core@0.4.3
## 0.0.60
### Patch Changes
- Updated dependencies [14cc9eb]
- @llamaindex/env@0.1.17
- @llamaindex/core@0.4.2
## 0.0.59
### Patch Changes
- 47a7c3e: feat: added support for Haiku 3.5 via Bedrock
## 0.0.58
### Patch Changes
- Updated dependencies [9c73f0a]
- @llamaindex/core@0.4.1
## 0.0.57
### Patch Changes
- Updated dependencies [359fd33]
- Updated dependencies [efb7e1b]
- Updated dependencies [98ba1e7]
- Updated dependencies [620c63c]
- @llamaindex/core@0.4.0
## 0.0.56
### Patch Changes
- Updated dependencies [60b185f]
- @llamaindex/core@0.3.7
## 0.0.55
### Patch Changes
- Updated dependencies [691c5bc]
- @llamaindex/core@0.3.6
## 0.0.54
### Patch Changes
- Updated dependencies [fa60fc6]
- @llamaindex/env@0.1.16
- @llamaindex/core@0.3.5
## 0.0.53
### Patch Changes
- Updated dependencies [e2a0876]
- @llamaindex/core@0.3.4
## 0.0.52
### Patch Changes
- a5a75f6: feat: added sonnet 3.5 v2
## 0.0.51
### Patch Changes
- Updated dependencies [0493f67]
- @llamaindex/core@0.3.3
## 0.0.50
### Patch Changes
- Updated dependencies [4ba2cfe]
- @llamaindex/env@0.1.15
- @llamaindex/core@0.3.2
## 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
### Patch Changes
- Updated dependencies [749b43a]
- @llamaindex/core@0.2.2
## 0.0.35
### Patch Changes
- Updated dependencies [ac07e3c]
- Updated dependencies [70ccb4a]
- Updated dependencies [1a6137b]
- Updated dependencies [ac07e3c]
- @llamaindex/core@0.2.1
- @llamaindex/env@0.1.11
## 0.0.34
### Patch Changes
- Updated dependencies [11feef8]
- @llamaindex/core@0.2.0
## 0.0.33
### Patch Changes
- Updated dependencies [711c814]
- @llamaindex/core@0.1.12
## 0.0.32
### Patch Changes
- Updated dependencies [4648da6]
- @llamaindex/env@0.1.10
- @llamaindex/core@0.1.11
## 0.0.31
### Patch Changes
- Updated dependencies [0148354]
- @llamaindex/core@0.1.10
## 0.0.30
### Patch Changes
- Updated dependencies [e27e7dd]
- @llamaindex/core@0.1.9
## 0.0.29
### Patch Changes
- 58abc57: fix: align version
- Updated dependencies [58abc57]
- @llamaindex/core@0.1.8
- @llamaindex/env@0.1.9
## 0.0.28
### Patch Changes
- Updated dependencies [04b2f8e]
- @llamaindex/core@0.1.7
## 0.0.27
### Patch Changes
- Updated dependencies [0452af9]
- @llamaindex/core@0.1.6
## 0.0.26
### Patch Changes
- 224d507: fix: prevent tool calling getting mixed with conversation
- 376d29a: feat: added tool calling and agent support for llama3.1 504B
## 0.0.25
### Patch Changes
- Updated dependencies [91d02a4]
- @llamaindex/core@0.1.5
## 0.0.24
### Patch Changes
- 3d9a802: feat: added llama 3.1
- Updated dependencies [15962b3]
- @llamaindex/core@0.1.4
## 0.0.23
### Patch Changes
- Updated dependencies [6cf6ae6]
- @llamaindex/core@0.1.3
## 0.0.22
### Patch Changes
- Updated dependencies [b974eea]
- @llamaindex/core@0.1.2
## 0.0.21
### Patch Changes
- Updated dependencies [b3681bf]
- @llamaindex/core@0.1.1
## 0.0.20
### Patch Changes
- 56746c2: fix: llama3 patched to handle empty content (can happen with system) and added max tokens export
## 0.0.19
### Patch Changes
- 16ef5dd: refactor: depends on core pacakge instead of llamaindex
- Updated dependencies [16ef5dd]
- Updated dependencies [16ef5dd]
- @llamaindex/core@0.1.0
## 0.0.18
### Patch Changes
- llamaindex@0.4.14
## 0.0.17
### Patch Changes
- Updated dependencies [e8f8bea]
- Updated dependencies [304484b]
- llamaindex@0.4.13
## 0.0.16
### Patch Changes
- f326ab8: chore: bump version
- Updated dependencies [f326ab8]
- llamaindex@0.4.12
## 0.0.15
### Patch Changes
- Updated dependencies [8bf5b4a]
- llamaindex@0.4.11
## 0.0.14
### Patch Changes
- Updated dependencies [7dce3d2]
- llamaindex@0.4.10
## 0.0.13
### Patch Changes
- Updated dependencies [3a96a48]
- llamaindex@0.4.9
## 0.0.12
### Patch Changes
- Updated dependencies [83ebdfb]
- llamaindex@0.4.8
## 0.0.11
### Patch Changes
- Updated dependencies [41fe871]
- Updated dependencies [321c39d]
- Updated dependencies [f7f1af0]
- llamaindex@0.4.7
## 0.0.10
### Patch Changes
- Updated dependencies [1feb23b]
- Updated dependencies [08c55ec]
- llamaindex@0.4.6
## 0.0.9
### Patch Changes
- Updated dependencies [6c3e5d0]
- llamaindex@0.4.5
## 0.0.8
### Patch Changes
- Updated dependencies [42eb73a]
- llamaindex@0.4.4
## 0.0.7
### Patch Changes
- Updated dependencies [2ef62a9]
- llamaindex@0.4.3
## 0.0.6
### Patch Changes
- a87a4d1: feat: added tool support calling for Bedrock's Calude and general llm support for agents
- Updated dependencies [a87a4d1]
- Updated dependencies [0730140]
- llamaindex@0.4.2
## 0.0.5
### Patch Changes
- ed467a9: Add model ids for Anthropic Claude 3.5 Sonnet model on Anthropic and Bedrock
- Updated dependencies [3c47910]
- Updated dependencies [ed467a9]
- Updated dependencies [cba5406]
- llamaindex@0.4.1
## 0.0.4
### Patch Changes
- b1a4a74: docs: updated Bedrock Opus region and added a basic README
- Updated dependencies [436bc41]
- Updated dependencies [a44e54f]
- Updated dependencies [a51ed8d]
- Updated dependencies [d3b635b]
- llamaindex@0.4.0
## 0.0.3
### Patch Changes
- Updated dependencies [6bc5bdd]
- Updated dependencies [bf25ff6]
- Updated dependencies [e6d6576]
- llamaindex@0.3.17
## 0.0.2
### Patch Changes
- 8832669: Community bedrock support added
- Updated dependencies [11ae926]
- Updated dependencies [631f000]
- Updated dependencies [1378ec4]
- Updated dependencies [6b1ded4]
- Updated dependencies [4d4bd85]
- Updated dependencies [24a9d1e]
- Updated dependencies [45952de]
- Updated dependencies [54230f0]
- Updated dependencies [a29d835]
- Updated dependencies [73819bf]
- llamaindex@0.3.16
+17
View File
@@ -0,0 +1,17 @@
# @llamaindex/community
AWS package for LlamaIndexTS, deprecated, use [@llamaindex/aws](https://www.npmjs.com/package/@llamaindex/aws) instead.
## Current Features:
- Bedrock support for Amazon Nova models Pro, Lite and Micro
- Bedrock support for the Anthropic Claude Models [usage](https://ts.llamaindex.ai/docs/llamaindex/modules/llms/bedrock) including the latest Sonnet 3.5 v2 and Haiku 3.5
- Bedrock support for the Meta LLama 2, 3, 3.1 and 3.2 Models [usage](https://ts.llamaindex.ai/docs/llamaindex/modules/llms/bedrock)
- 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
MIT
+53
View File
@@ -0,0 +1,53 @@
{
"name": "@llamaindex/community",
"description": "Community package for LlamaIndexTS",
"version": "0.0.100",
"type": "module",
"types": "dist/type/index.d.ts",
"main": "dist/cjs/index.js",
"exports": {
".": {
"import": {
"types": "./dist/type/index.d.ts",
"default": "./dist/index.js"
},
"require": {
"types": "./dist/type/index.d.ts",
"default": "./dist/index.cjs"
}
},
"./llm/bedrock": {
"import": {
"types": "./dist/type/llm/bedrock.d.ts",
"default": "./dist/llm/bedrock/index.js"
},
"require": {
"types": "./dist/type/llm/bedrock.d.ts",
"default": "./dist/llm/bedrock/index.cjs"
}
}
},
"files": [
"dist",
"CHANGELOG.md",
"!**/*.tsbuildinfo"
],
"repository": {
"type": "git",
"url": "git+https://github.com/run-llama/LlamaIndexTS.git",
"directory": "packages/community"
},
"scripts": {
"build": "bunchee",
"dev": "bunchee --watch"
},
"devDependencies": {
"@types/node": "^22.9.0"
},
"dependencies": {
"@aws-sdk/client-bedrock-agent-runtime": "^3.706.0",
"@aws-sdk/client-bedrock-runtime": "^3.706.0",
"@llamaindex/core": "workspace:*",
"@llamaindex/env": "workspace:*"
}
}
+8
View File
@@ -0,0 +1,8 @@
export {
BEDROCK_MODELS,
BEDROCK_MODEL_MAX_TOKENS,
Bedrock,
INFERENCE_BEDROCK_MODELS,
INFERENCE_TO_BEDROCK_MAP,
} from "./llm/bedrock/index.js";
export { AmazonKnowledgeBaseRetriever } from "./retrievers/bedrock.js";
@@ -0,0 +1,134 @@
import type {
ContentBlockDelta,
ConverseOutput,
ConverseRequest,
ConverseResponse,
ConverseStreamOutput,
InvokeModelCommandInput,
InvokeModelWithResponseStreamCommandInput,
ResponseStream,
} from "@aws-sdk/client-bedrock-runtime";
import type {
BaseTool,
ChatMessage,
LLMMetadata,
ToolCall,
ToolCallLLMMessageOptions,
} from "@llamaindex/core/llms";
import { toUtf8 } from "../utils";
import { Provider, type BedrockChatStreamResponse } from "../provider";
import {
mapBaseToolsToAmazonTools,
mapChatMessagesToAmazonMessages,
} from "./utils";
export class AmazonProvider extends Provider<ConverseStreamOutput> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
getResultFromResponse(response: Record<string, any>): ConverseResponse {
return JSON.parse(toUtf8(response.body));
}
getToolsFromResponse<ToolContent>(response: ConverseOutput): ToolContent[] {
return (
response.message?.content
?.filter((item) => item.toolUse)
.map(
(item) =>
({
id: item.toolUse!.toolUseId,
name: item.toolUse!.name,
input: item.toolUse!.input
? JSON.parse(item.toolUse!.input as string)
: "",
}) as ToolContent,
) ?? []
);
}
getTextFromResponse(response: ConverseResponse): string {
const result = this.getResultFromResponse(response);
const content = result.output?.message?.content ?? [];
return content.map((item) => item.text).join(" ");
}
getTextFromStreamResponse(response: ResponseStream): string {
const event: ConverseStreamOutput | undefined =
this.getStreamingEventResponse(response);
if (!event || !event.contentBlockDelta) return "";
const delta: ContentBlockDelta | undefined = event.contentBlockDelta.delta;
return delta?.text || "";
}
async *reduceStream(
stream: AsyncIterable<ResponseStream>,
): BedrockChatStreamResponse {
let toolId: string | undefined = undefined;
let toolName: string | undefined = undefined;
for await (const response of stream) {
const event = this.getStreamingEventResponse(response);
const delta = this.getTextFromStreamResponse(response);
let options: undefined | ToolCallLLMMessageOptions = undefined;
if (event?.contentBlockStart && event.contentBlockStart.start?.toolUse) {
toolId = event.contentBlockStart.start?.toolUse.toolUseId;
toolName = event.contentBlockStart.start?.toolUse.name;
continue;
}
if (
toolId &&
toolName &&
event?.contentBlockDelta?.delta?.toolUse?.input
) {
options = {
toolCall: [
{
id: toolId,
name: toolName,
input: JSON.parse(event?.contentBlockDelta?.delta?.toolUse.input),
} as ToolCall,
],
};
toolId = undefined;
toolName = undefined;
}
if (!delta && !options) continue;
yield {
delta: options ? "" : delta,
options,
raw: response,
};
}
}
getRequestBody<T extends ChatMessage>(
metadata: LLMMetadata,
messages: T[],
tools: BaseTool[] = [],
options: Omit<ConverseRequest, "modelId" | "messages" | "inferenceConfig">,
): InvokeModelCommandInput | InvokeModelWithResponseStreamCommandInput {
const request: Omit<ConverseRequest, "modelId"> = {
...options,
messages: mapChatMessagesToAmazonMessages(messages),
inferenceConfig: {
maxTokens: metadata.maxTokens,
temperature: metadata.temperature,
topP: metadata.topP,
},
};
if (tools.length) {
request.toolConfig = {
tools: mapBaseToolsToAmazonTools(tools),
};
}
return {
modelId: metadata.model,
contentType: "application/json",
accept: "application/json",
body: JSON.stringify(request),
};
}
}
@@ -0,0 +1,5 @@
import type { ConverseRequest, Message } from "@aws-sdk/client-bedrock-runtime";
export type AmazonMessages = ConverseRequest["messages"];
export type AmazonMessage = Message;
@@ -0,0 +1,141 @@
import type {
ImageBlock,
ImageFormat,
Message,
Tool,
} from "@aws-sdk/client-bedrock-runtime";
import type {
BaseTool,
ChatMessage,
MessageContentDetail,
ToolCallLLMMessageOptions,
} from "@llamaindex/core/llms";
import { extractDataUrlComponents } from "../utils";
import type { JSONObject } from "@llamaindex/core/global";
import { mapMessageContentToMessageContentDetails } from "../../utils";
import type { AmazonMessage, AmazonMessages } from "./types";
const ACCEPTED_IMAGE_MIME_TYPES = [
"image/jpeg",
"image/png",
"image/webp",
"image/gif",
] as const;
const ACCEPTED_IMAGE_MIME_TYPE_FORMAT_MAP: Record<
(typeof ACCEPTED_IMAGE_MIME_TYPES)[number],
ImageFormat
> = {
"image/jpeg": "jpeg",
"image/png": "png",
"image/webp": "webp",
"image/gif": "gif",
};
export const mapImageContent = (imageUrl: string): ImageBlock => {
if (!imageUrl.startsWith("data:"))
throw new Error(
"For Amazon please only use base64 data url, e.g.: data:image/jpeg;base64,SGVsbG8sIFdvcmxkIQ==",
);
const { mimeType, base64: data } = extractDataUrlComponents(imageUrl);
if (
!ACCEPTED_IMAGE_MIME_TYPES.includes(
mimeType as keyof typeof ACCEPTED_IMAGE_MIME_TYPE_FORMAT_MAP,
)
)
throw new Error(
`Amazon only accepts the following mimeTypes: ${ACCEPTED_IMAGE_MIME_TYPES.join("\n")}`,
);
return {
format:
ACCEPTED_IMAGE_MIME_TYPE_FORMAT_MAP[
mimeType as keyof typeof ACCEPTED_IMAGE_MIME_TYPE_FORMAT_MAP
],
// @ts-expect-error: there's a mistake in the "@aws-sdk/client-bedrock-runtime" compared to the actual api
source: { bytes: data },
};
};
export const mapMessageContentDetailToAmazonContent = <
T extends MessageContentDetail,
>(
detail: T,
): Message["content"] => {
let content: Message["content"] = [];
if (detail.type === "text") {
content = [{ text: detail.text }];
} else if (detail.type === "image_url") {
content = [{ image: mapImageContent(detail.image_url.url) }];
} else {
throw new Error("Unsupported content detail type");
}
return content;
};
export const mapChatMessagesToAmazonMessages = <
T extends ChatMessage<ToolCallLLMMessageOptions>,
>(
messages: T[],
): AmazonMessages => {
return messages.flatMap((msg: T): AmazonMessage[] => {
return mapMessageContentToMessageContentDetails(msg.content).map(
(detail: MessageContentDetail): AmazonMessage => {
if (msg.options && "toolCall" in msg.options) {
return {
role: "assistant",
content: msg.options.toolCall.map((call) => ({
toolUse: {
toolUseId: call.id,
name: call.name,
input: call.input as JSONObject,
},
})),
};
}
if (msg.options && "toolResult" in msg.options) {
return {
role: "user",
content: [
{
toolResult: {
toolUseId: msg.options.toolResult.id,
content: [
{
text: msg.options.toolResult.result,
},
],
},
},
],
};
}
return {
role: msg.role === "assistant" ? "assistant" : "user",
content: mapMessageContentDetailToAmazonContent(detail),
};
},
);
});
};
export const mapBaseToolsToAmazonTools = (tools?: BaseTool[]): Tool[] => {
if (!tools) return [];
return tools.map((tool: BaseTool) => {
const {
metadata: { parameters, ...options },
} = tool;
return {
toolSpec: {
...options,
inputSchema: {
json: parameters,
},
},
} as Tool;
});
};
@@ -0,0 +1,156 @@
import {
type InvokeModelCommandInput,
type InvokeModelWithResponseStreamCommandInput,
ResponseStream,
} from "@aws-sdk/client-bedrock-runtime";
import type {
BaseTool,
ChatMessage,
LLMMetadata,
PartialToolCall,
ToolCall,
ToolCallLLMMessageOptions,
} from "@llamaindex/core/llms";
import { type BedrockChatStreamResponse, Provider } from "../provider";
import { toUtf8 } from "../utils";
import type {
AnthropicAdditionalChatOptions,
AnthropicNoneStreamingResponse,
AnthropicStreamEvent,
AnthropicTextContent,
ToolBlock,
} from "./types";
import {
mapBaseToolsToAnthropicTools,
mapChatMessagesToAnthropicMessages,
} from "./utils";
export class AnthropicProvider extends Provider<AnthropicStreamEvent> {
getResultFromResponse(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
response: Record<string, any>,
): AnthropicNoneStreamingResponse {
return JSON.parse(toUtf8(response.body));
}
getToolsFromResponse<AnthropicToolContent>(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
response: Record<string, any>,
): AnthropicToolContent[] {
const result = this.getResultFromResponse(response);
return result.content
.filter((item) => item.type === "tool_use")
.map((item) => item as AnthropicToolContent);
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
getTextFromResponse(response: Record<string, any>): string {
const result = this.getResultFromResponse(response);
return result.content
.filter((item) => item.type === "text")
.map((item) => (item as AnthropicTextContent).text)
.join(" ");
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
getTextFromStreamResponse(response: Record<string, any>): string {
const event = this.getStreamingEventResponse(response);
if (event?.type === "content_block_delta") {
if (event.delta.type === "text_delta") return event.delta.text;
if (event.delta.type === "input_json_delta")
return event.delta.partial_json;
}
return "";
}
async *reduceStream(
stream: AsyncIterable<ResponseStream>,
): BedrockChatStreamResponse {
let collecting = [];
let tool: ToolBlock | undefined = undefined;
// #TODO this should be broken down into a separate consumer
for await (const response of stream) {
const delta = this.getTextFromStreamResponse(response);
const event = this.getStreamingEventResponse(response);
if (
event?.type === "content_block_start" &&
event.content_block.type === "tool_use"
) {
tool = event.content_block;
continue;
}
if (
event?.type === "content_block_delta" &&
event.delta.type === "input_json_delta"
) {
collecting.push(event.delta.partial_json);
}
let options: undefined | ToolCallLLMMessageOptions = undefined;
if (tool && collecting.length) {
const input = collecting.filter((item) => item).join("");
// We have all we need to parse the tool_use json
if (event?.type === "content_block_stop") {
options = {
toolCall: [
{
id: tool.id,
name: tool.name,
input: JSON.parse(input),
} as ToolCall,
],
};
// reset the collection/tool
collecting = [];
tool = undefined;
} else {
options = {
toolCall: [
{
id: tool.id,
name: tool.name,
input,
} as PartialToolCall,
],
};
}
}
if (!delta && !options) continue;
yield {
delta: options ? "" : delta,
options,
raw: response,
};
}
}
getRequestBody<T extends ChatMessage<ToolCallLLMMessageOptions>>(
metadata: LLMMetadata,
messages: T[],
tools?: BaseTool[],
options?: AnthropicAdditionalChatOptions,
): InvokeModelCommandInput | InvokeModelWithResponseStreamCommandInput {
const extra: Record<string, unknown> = {};
if (options?.toolChoice) {
extra["tool_choice"] = options?.toolChoice;
}
const mapped = mapChatMessagesToAnthropicMessages(messages);
return {
modelId: metadata.model,
contentType: "application/json",
accept: "application/json",
body: JSON.stringify({
anthropic_version: "bedrock-2023-05-31",
messages: mapped,
tools: mapBaseToolsToAnthropicTools(tools),
max_tokens: metadata.maxTokens,
temperature: metadata.temperature,
top_p: metadata.topP,
...extra,
}),
};
}
}
@@ -0,0 +1,161 @@
import type { ToolMetadata } from "@llamaindex/core/llms";
import type { InvocationMetrics } from "../types";
export type ToolChoice =
| { type: "any" }
| { type: "auto" }
| { type: "tool"; name: string };
export interface ThinkingConfigDisabled {
type: "disabled";
}
export interface ThinkingConfigEnabled {
budget_tokens: number;
type: "enabled";
}
export type AnthropicAdditionalChatOptions = {
toolChoice: ToolChoice;
thinking?: ThinkingConfigDisabled | ThinkingConfigEnabled;
};
type Usage = {
input_tokens: number;
output_tokens: number;
};
type Message = {
id: string;
type: string;
role: string;
content: string[];
model: string;
stop_reason: string | null;
stop_sequence: string | null;
usage: Usage;
};
export type ToolBlock = {
id: string;
input: unknown;
name: string;
type: "tool_use";
};
export type TextBlock = {
type: "text";
text: string;
};
type ContentBlockStart = {
type: "content_block_start";
index: number;
content_block: ToolBlock | TextBlock;
};
type Delta =
| {
type: "text_delta";
text: string;
}
| {
type: "input_json_delta";
partial_json: string;
};
type ContentBlockDelta = {
type: "content_block_delta";
index: number;
delta: Delta;
};
type ContentBlockStop = {
type: "content_block_stop";
index: number;
};
type MessageDelta = {
type: "message_delta";
delta: {
stop_reason: string;
stop_sequence: string | null;
};
usage: Usage;
};
export type MessageStop = {
type: "message_stop";
"amazon-bedrock-invocationMetrics": InvocationMetrics;
};
export type AnthropicStreamEvent =
| { type: "message_start"; message: Message }
| ContentBlockStart
| ContentBlockDelta
| ContentBlockStop
| MessageDelta
| MessageStop;
export type AnthropicContent =
| AnthropicTextContent
| AnthropicImageContent
| AnthropicToolContent
| AnthropicToolResultContent;
export type AnthropicTextContent = {
type: "text";
text: string;
};
export type AnthropicToolContent = {
type: "tool_use";
id: string;
name: string;
input: Record<string, unknown>;
};
export type AnthropicToolResultContent = {
type: "tool_result";
tool_use_id: string;
content: string;
};
export type AnthropicMediaTypes =
| "image/jpeg"
| "image/png"
| "image/webp"
| "image/gif";
export type AnthropicImageSource = {
type: "base64";
media_type: AnthropicMediaTypes;
data: string; // base64 encoded image bytes
};
export type AnthropicImageContent = {
type: "image";
source: AnthropicImageSource;
};
export type AnthropicMessage = {
role: "user" | "assistant";
content: AnthropicContent[];
};
export type AnthropicNoneStreamingResponse = {
id: string;
type: "message";
role: "assistant";
content: AnthropicContent[];
model: string;
stop_reason: "end_turn" | "max_tokens" | "stop_sequence";
stop_sequence?: string;
usage: { input_tokens: number; output_tokens: number };
};
export type AnthropicTool = {
name: string;
description: string;
input_schema: ToolMetadata["parameters"];
};
@@ -0,0 +1,166 @@
import type { JSONObject } from "@llamaindex/core/global";
import type {
BaseTool,
ChatMessage,
MessageContent,
MessageContentDetail,
ToolCallLLMMessageOptions,
} from "@llamaindex/core/llms";
import { mapMessageContentToMessageContentDetails } from "../../utils";
import { extractDataUrlComponents } from "../utils";
import type {
AnthropicContent,
AnthropicImageContent,
AnthropicMediaTypes,
AnthropicMessage,
AnthropicTextContent,
AnthropicTool,
} from "./types.js";
const ACCEPTED_IMAGE_MIME_TYPES = [
"image/jpeg",
"image/png",
"image/webp",
"image/gif",
];
export const mergeNeighboringSameRoleMessages = (
messages: AnthropicMessage[],
): AnthropicMessage[] => {
return messages.reduce(
(result: AnthropicMessage[], current: AnthropicMessage, index: number) => {
if (index > 0 && messages[index - 1]!.role === current.role) {
result[result.length - 1]!.content = [
...result[result.length - 1]!.content,
...current.content,
];
} else {
result.push(current);
}
return result;
},
[],
);
};
export const mapMessageContentDetailToAnthropicContent = <
T extends MessageContentDetail,
>(
detail: T,
): AnthropicContent => {
let content: AnthropicContent;
if (detail.type === "text") {
content = mapTextContent(detail.text);
} else if (detail.type === "image_url") {
content = mapImageContent(detail.image_url.url);
} else {
throw new Error("Unsupported content detail type");
}
return content;
};
export const mapMessageContentToAnthropicContent = <T extends MessageContent>(
content: T,
): AnthropicContent[] => {
return mapMessageContentToMessageContentDetails(content).map(
mapMessageContentDetailToAnthropicContent,
);
};
export const mapBaseToolsToAnthropicTools = (
tools?: BaseTool[],
): AnthropicTool[] => {
if (!tools) return [];
return tools.map((tool: BaseTool) => {
const {
metadata: { parameters, ...options },
} = tool;
return {
...options,
input_schema: parameters,
};
});
};
export const mapChatMessagesToAnthropicMessages = <
T extends ChatMessage<ToolCallLLMMessageOptions>,
>(
messages: T[],
): AnthropicMessage[] => {
const mapped = messages
.flatMap((msg: T): AnthropicMessage[] => {
if (msg.options && "toolCall" in msg.options) {
return [
{
role: "assistant",
content: msg.options.toolCall.map((call) => ({
type: "tool_use",
id: call.id,
name: call.name,
input: call.input as JSONObject,
})),
},
];
}
if (msg.options && "toolResult" in msg.options) {
return [
{
role: "user",
content: [
{
type: "tool_result",
tool_use_id: msg.options.toolResult.id,
content: JSON.stringify(msg.options.toolResult.result),
},
],
},
];
}
return mapMessageContentToMessageContentDetails(msg.content).map(
(detail: MessageContentDetail): AnthropicMessage => {
const content = mapMessageContentDetailToAnthropicContent(detail);
return {
role: msg.role === "assistant" ? "assistant" : "user",
content: [content],
};
},
);
})
.filter((message: AnthropicMessage) => {
const content = message.content[0]!;
if (content.type === "text" && !content.text) return false;
if (content.type === "image" && !content.source.data) return false;
if (content.type === "image" && message.role === "assistant")
return false;
return true;
});
return mergeNeighboringSameRoleMessages(mapped);
};
export const mapTextContent = (text: string): AnthropicTextContent => {
return { type: "text", text };
};
export const mapImageContent = (imageUrl: string): AnthropicImageContent => {
if (!imageUrl.startsWith("data:"))
throw new Error(
"For Anthropic please only use base64 data url, e.g.: data:image/jpeg;base64,SGVsbG8sIFdvcmxkIQ==",
);
const { mimeType, base64: data } = extractDataUrlComponents(imageUrl);
if (!ACCEPTED_IMAGE_MIME_TYPES.includes(mimeType))
throw new Error(
`Anthropic only accepts the following mimeTypes: ${ACCEPTED_IMAGE_MIME_TYPES.join("\n")}`,
);
return {
type: "image",
source: {
type: "base64",
media_type: mimeType as AnthropicMediaTypes,
data,
},
};
};
+513
View File
@@ -0,0 +1,513 @@
import {
BedrockRuntimeClient,
type BedrockRuntimeClientConfig,
InvokeModelCommand,
InvokeModelWithResponseStreamCommand,
} from "@aws-sdk/client-bedrock-runtime";
import {
type ChatMessage,
type ChatResponse,
type CompletionResponse,
type LLMChatParamsNonStreaming,
type LLMChatParamsStreaming,
type LLMCompletionParamsNonStreaming,
type LLMCompletionParamsStreaming,
type LLMMetadata,
ToolCallLLM,
type ToolCallLLMMessageOptions,
} from "@llamaindex/core/llms";
import { streamConverter } from "@llamaindex/core/utils";
import {
type BedrockAdditionalChatOptions,
type BedrockChatStreamResponse,
Provider,
} from "./provider";
import { wrapLLMEvent } from "@llamaindex/core/decorator";
import { mapMessageContentToMessageContentDetails } from "../utils";
import { AmazonProvider } from "./amazon/provider";
import { AnthropicProvider } from "./anthropic/provider";
import { MetaProvider } from "./meta/provider";
// Other providers should go here
export const PROVIDERS: { [key: string]: Provider } = {
anthropic: new AnthropicProvider(),
meta: new MetaProvider(),
amazon: new AmazonProvider(),
};
export type BedrockChatParamsStreaming = LLMChatParamsStreaming<
BedrockAdditionalChatOptions,
ToolCallLLMMessageOptions
>;
export type BedrockChatParamsNonStreaming = LLMChatParamsNonStreaming<
BedrockAdditionalChatOptions,
ToolCallLLMMessageOptions
>;
export type BedrockChatNonStreamResponse =
ChatResponse<ToolCallLLMMessageOptions>;
export const BEDROCK_MODELS = {
AMAZON_TITAN_TG1_LARGE: "amazon.titan-tg1-large",
AMAZON_TITAN_TEXT_EXPRESS_V1: "amazon.titan-text-express-v1",
AI21_J2_GRANDE_INSTRUCT: "ai21.j2-grande-instruct",
AI21_J2_JUMBO_INSTRUCT: "ai21.j2-jumbo-instruct",
AI21_J2_MID: "ai21.j2-mid",
AI21_J2_MID_V1: "ai21.j2-mid-v1",
AI21_J2_ULTRA: "ai21.j2-ultra",
AI21_J2_ULTRA_V1: "ai21.j2-ultra-v1",
COHERE_COMMAND_TEXT_V14: "cohere.command-text-v14",
ANTHROPIC_CLAUDE_INSTANT_1: "anthropic.claude-instant-v1",
ANTHROPIC_CLAUDE_1: "anthropic.claude-v1", // EOF: No longer supported
ANTHROPIC_CLAUDE_2: "anthropic.claude-v2",
ANTHROPIC_CLAUDE_2_1: "anthropic.claude-v2:1",
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_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_V2: "anthropic.claude-3-5-sonnet-20241022-v2:0",
ANTHROPIC_CLAUDE_3_5_HAIKU: "anthropic.claude-3-5-haiku-20241022-v1:0",
ANTHROPIC_CLAUDE_3_7_SONNET: "anthropic.claude-3-7-sonnet-20250219-v1:0",
META_LLAMA2_13B_CHAT: "meta.llama2-13b-chat-v1",
META_LLAMA2_70B_CHAT: "meta.llama2-70b-chat-v1",
META_LLAMA3_8B_INSTRUCT: "meta.llama3-8b-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_70B_INSTRUCT: "meta.llama3-1-70b-instruct-v1:0",
META_LLAMA3_1_405B_INSTRUCT: "meta.llama3-1-405b-instruct-v1:0",
META_LLAMA3_2_1B_INSTRUCT: "meta.llama3-2-1b-instruct-v1:0",
META_LLAMA3_2_3B_INSTRUCT: "meta.llama3-2-3b-instruct-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",
META_LLAMA3_3_70B_INSTRUCT: "meta.llama3-3-70b-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",
AMAZON_NOVA_PREMIER_1: "amazon.nova-premier-v1:0",
AMAZON_NOVA_PRO_1: "amazon.nova-pro-v1:0",
AMAZON_NOVA_LITE_1: "amazon.nova-lite-v1:0",
AMAZON_NOVA_MICRO_1: "amazon.nova-micro-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_5_HAIKU: "us.anthropic.claude-3-5-haiku-20241022-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_ANTHROPIC_CLAUDE_3_5_SONNET_V2:
"us.anthropic.claude-3-5-sonnet-20241022-v2:0",
US_ANTHROPIC_CLAUDE_3_7_SONNET:
"us.anthropic.claude-3-7-sonnet-20250219-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",
US_META_LLAMA_3_3_70B_INSTRUCT: "us.meta.llama3-3-70b-instruct-v1:0",
US_AMAZON_NOVA_PREMIER_1: "us.amazon.nova-premier-v1:0",
US_AMAZON_NOVA_PRO_1: "us.amazon.nova-pro-v1:0",
US_AMAZON_NOVA_LITE_1: "us.amazon.nova-lite-v1:0",
US_AMAZON_NOVA_MICRO_1: "us.amazon.nova-micro-v1:0",
EU_ANTHROPIC_CLAUDE_3_HAIKU: "eu.anthropic.claude-3-haiku-20240307-v1:0",
EU_ANTHROPIC_CLAUDE_3_5_HAIKU: "eu.anthropic.claude-3-5-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_ANTHROPIC_CLAUDE_3_7_SONNET:
"eu.anthropic.claude-3-7-sonnet-20250219-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",
EU_AMAZON_NOVA_PREMIER_1: "eu.amazon.nova-premier-v1:0",
EU_AMAZON_NOVA_PRO_1: "eu.amazon.nova-pro-v1:0",
EU_AMAZON_NOVA_LITE_1: "eu.amazon.nova-lite-v1:0",
EU_AMAZON_NOVA_MICRO_1: "eu.amazon.nova-micro-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_ANTHROPIC_CLAUDE_3_7_SONNET]:
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_7_SONNET,
[INFERENCE_BEDROCK_MODELS.US_ANTHROPIC_CLAUDE_3_5_SONNET_V2]:
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_5_SONNET_V2,
[INFERENCE_BEDROCK_MODELS.US_ANTHROPIC_CLAUDE_3_5_HAIKU]:
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_5_HAIKU,
[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.US_META_LLAMA_3_3_70B_INSTRUCT]:
BEDROCK_MODELS.META_LLAMA3_3_70B_INSTRUCT,
[INFERENCE_BEDROCK_MODELS.US_AMAZON_NOVA_PREMIER_1]:
BEDROCK_MODELS.AMAZON_NOVA_PREMIER_1,
[INFERENCE_BEDROCK_MODELS.US_AMAZON_NOVA_PRO_1]:
BEDROCK_MODELS.AMAZON_NOVA_PRO_1,
[INFERENCE_BEDROCK_MODELS.US_AMAZON_NOVA_LITE_1]:
BEDROCK_MODELS.AMAZON_NOVA_LITE_1,
[INFERENCE_BEDROCK_MODELS.US_AMAZON_NOVA_MICRO_1]:
BEDROCK_MODELS.AMAZON_NOVA_MICRO_1,
[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_ANTHROPIC_CLAUDE_3_7_SONNET]:
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_7_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,
[INFERENCE_BEDROCK_MODELS.EU_AMAZON_NOVA_PREMIER_1]:
BEDROCK_MODELS.AMAZON_NOVA_PREMIER_1,
[INFERENCE_BEDROCK_MODELS.EU_AMAZON_NOVA_PRO_1]:
BEDROCK_MODELS.AMAZON_NOVA_PRO_1,
[INFERENCE_BEDROCK_MODELS.EU_AMAZON_NOVA_LITE_1]:
BEDROCK_MODELS.AMAZON_NOVA_LITE_1,
[INFERENCE_BEDROCK_MODELS.EU_AMAZON_NOVA_MICRO_1]:
BEDROCK_MODELS.AMAZON_NOVA_MICRO_1,
};
/*
* Values taken from https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters.html#model-parameters-claude
*/
const COMPLETION_MODELS = {
[BEDROCK_MODELS.AMAZON_TITAN_TG1_LARGE]: 8000,
[BEDROCK_MODELS.AMAZON_TITAN_TEXT_EXPRESS_V1]: 8000,
[BEDROCK_MODELS.AI21_J2_GRANDE_INSTRUCT]: 8000,
[BEDROCK_MODELS.AI21_J2_JUMBO_INSTRUCT]: 8000,
[BEDROCK_MODELS.AI21_J2_MID]: 8000,
[BEDROCK_MODELS.AI21_J2_MID_V1]: 8000,
[BEDROCK_MODELS.AI21_J2_ULTRA]: 8000,
[BEDROCK_MODELS.AI21_J2_ULTRA_V1]: 8000,
[BEDROCK_MODELS.COHERE_COMMAND_TEXT_V14]: 4096,
};
const CHAT_ONLY_MODELS = {
[BEDROCK_MODELS.ANTHROPIC_CLAUDE_INSTANT_1]: 100000,
[BEDROCK_MODELS.ANTHROPIC_CLAUDE_1]: 100000,
[BEDROCK_MODELS.ANTHROPIC_CLAUDE_2]: 100000,
[BEDROCK_MODELS.ANTHROPIC_CLAUDE_2_1]: 200000,
[BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_SONNET]: 200000,
[BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_HAIKU]: 200000,
[BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_OPUS]: 200000,
[BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_5_SONNET]: 200000,
[BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_5_SONNET_V2]: 200000,
[BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_5_HAIKU]: 200000,
[BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_7_SONNET]: 200000,
[BEDROCK_MODELS.META_LLAMA2_13B_CHAT]: 2048,
[BEDROCK_MODELS.META_LLAMA2_70B_CHAT]: 4096,
[BEDROCK_MODELS.META_LLAMA3_8B_INSTRUCT]: 8192,
[BEDROCK_MODELS.META_LLAMA3_70B_INSTRUCT]: 8192,
[BEDROCK_MODELS.META_LLAMA3_1_8B_INSTRUCT]: 128000,
[BEDROCK_MODELS.META_LLAMA3_1_70B_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.META_LLAMA3_3_70B_INSTRUCT]: 128000,
[BEDROCK_MODELS.MISTRAL_7B_INSTRUCT]: 32000,
[BEDROCK_MODELS.MISTRAL_MIXTRAL_7B_INSTRUCT]: 32000,
[BEDROCK_MODELS.MISTRAL_MIXTRAL_LARGE_2402]: 32000,
[BEDROCK_MODELS.AMAZON_NOVA_PREMIER_1]: 300000,
[BEDROCK_MODELS.AMAZON_NOVA_PRO_1]: 300000,
[BEDROCK_MODELS.AMAZON_NOVA_LITE_1]: 300000,
[BEDROCK_MODELS.AMAZON_NOVA_MICRO_1]: 130000,
};
const BEDROCK_FOUNDATION_LLMS = { ...COMPLETION_MODELS, ...CHAT_ONLY_MODELS };
/*
* Only the following models support streaming as
* per result of Bedrock.Client.list_foundation_models
* https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/bedrock/client/list_foundation_models.html
*/
export const STREAMING_MODELS = new Set([
BEDROCK_MODELS.AMAZON_TITAN_TG1_LARGE,
BEDROCK_MODELS.AMAZON_TITAN_TEXT_EXPRESS_V1,
BEDROCK_MODELS.ANTHROPIC_CLAUDE_INSTANT_1,
BEDROCK_MODELS.ANTHROPIC_CLAUDE_1,
BEDROCK_MODELS.ANTHROPIC_CLAUDE_2,
BEDROCK_MODELS.ANTHROPIC_CLAUDE_2_1,
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_SONNET,
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_HAIKU,
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_OPUS,
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_5_SONNET,
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_5_SONNET_V2,
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_5_HAIKU,
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_7_SONNET,
BEDROCK_MODELS.META_LLAMA2_13B_CHAT,
BEDROCK_MODELS.META_LLAMA2_70B_CHAT,
BEDROCK_MODELS.META_LLAMA3_8B_INSTRUCT,
BEDROCK_MODELS.META_LLAMA3_70B_INSTRUCT,
BEDROCK_MODELS.META_LLAMA3_1_8B_INSTRUCT,
BEDROCK_MODELS.META_LLAMA3_1_70B_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.META_LLAMA3_3_70B_INSTRUCT,
BEDROCK_MODELS.MISTRAL_7B_INSTRUCT,
BEDROCK_MODELS.MISTRAL_MIXTRAL_7B_INSTRUCT,
BEDROCK_MODELS.MISTRAL_MIXTRAL_LARGE_2402,
BEDROCK_MODELS.AMAZON_NOVA_PREMIER_1,
BEDROCK_MODELS.AMAZON_NOVA_PRO_1,
BEDROCK_MODELS.AMAZON_NOVA_LITE_1,
BEDROCK_MODELS.AMAZON_NOVA_MICRO_1,
]);
export const TOOL_CALL_MODELS: BEDROCK_MODELS[] = [
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_SONNET,
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_HAIKU,
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_OPUS,
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_5_SONNET,
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_5_SONNET_V2,
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_5_HAIKU,
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_7_SONNET,
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.META_LLAMA3_3_70B_INSTRUCT,
BEDROCK_MODELS.AMAZON_NOVA_PREMIER_1,
BEDROCK_MODELS.AMAZON_NOVA_PRO_1,
BEDROCK_MODELS.AMAZON_NOVA_LITE_1,
BEDROCK_MODELS.AMAZON_NOVA_MICRO_1,
];
const getProvider = (model: string): Provider => {
const providerName = model.split(".")[0];
if (!providerName) {
throw new Error(`Model ${model} is not supported`);
}
if (!(providerName in PROVIDERS)) {
throw new Error(
`Provider ${providerName} for model ${model} is not supported`,
);
}
return PROVIDERS[providerName]!;
};
export type BedrockModelParams = {
model: BEDROCK_MODELS | INFERENCE_BEDROCK_MODELS;
temperature?: number;
topP?: number;
maxTokens?: number;
};
export const BEDROCK_MODEL_MAX_TOKENS: Partial<Record<BEDROCK_MODELS, number>> =
{
[BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_SONNET]: 4096,
[BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_HAIKU]: 4096,
[BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_OPUS]: 4096,
[BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_5_SONNET]: 4096,
[BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_5_SONNET_V2]: 8192,
[BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_5_HAIKU]: 8192,
[BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_7_SONNET]: 8192,
[BEDROCK_MODELS.META_LLAMA2_13B_CHAT]: 2048,
[BEDROCK_MODELS.META_LLAMA2_70B_CHAT]: 2048,
[BEDROCK_MODELS.META_LLAMA3_8B_INSTRUCT]: 2048,
[BEDROCK_MODELS.META_LLAMA3_70B_INSTRUCT]: 2048,
[BEDROCK_MODELS.META_LLAMA3_1_8B_INSTRUCT]: 2048,
[BEDROCK_MODELS.META_LLAMA3_1_70B_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,
[BEDROCK_MODELS.META_LLAMA3_3_70B_INSTRUCT]: 2048,
};
const DEFAULT_BEDROCK_PARAMS = {
temperature: 0.1,
topP: 1,
maxTokens: 1024, // required by anthropic
};
export type BedrockParams = BedrockRuntimeClientConfig & BedrockModelParams;
/**
* ToolCallLLM for Bedrock
*/
export class Bedrock extends ToolCallLLM<BedrockAdditionalChatOptions> {
private client: BedrockRuntimeClient;
protected actualModel: BEDROCK_MODELS | INFERENCE_BEDROCK_MODELS;
model: BEDROCK_MODELS;
temperature: number;
topP: number;
maxTokens?: number;
provider: Provider;
topK?: number;
// there should be no check for env variables. Bedrock can be authenticated in various ways
// AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_REGION are the env variables used directly by the sdk
constructor({
temperature,
topP,
maxTokens,
model,
...params
}: BedrockParams) {
super();
this.actualModel = model;
this.model = INFERENCE_TO_BEDROCK_MAP[model] ?? model;
this.provider = getProvider(this.model);
this.maxTokens = maxTokens ?? DEFAULT_BEDROCK_PARAMS.maxTokens;
this.temperature = temperature ?? DEFAULT_BEDROCK_PARAMS.temperature;
this.topP = topP ?? DEFAULT_BEDROCK_PARAMS.topP;
this.client = new BedrockRuntimeClient(params);
}
get supportToolCall(): boolean {
return TOOL_CALL_MODELS.includes(this.model);
}
get metadata(): LLMMetadata {
// NOTE, Anthropic supports top_k but LLMMetadata does not
return {
model: this.model,
temperature: this.temperature,
topP: this.topP,
maxTokens: this.maxTokens,
contextWindow: BEDROCK_FOUNDATION_LLMS[this.model] ?? 128000,
tokenizer: undefined,
structuredOutput: false,
};
}
protected async nonStreamChat(
params: BedrockChatParamsNonStreaming,
): Promise<BedrockChatNonStreamResponse> {
if (!this.supportToolCall && params.tools?.length) {
console.warn(`The model "${this.model}" doesn't support ToolCall`);
}
const input = this.provider.getRequestBody(
this.metadata,
params.messages,
params.tools,
params.additionalChatOptions,
);
const command = new InvokeModelCommand(input);
command.input.modelId = this.actualModel;
const response = await this.client.send(command);
let options: ToolCallLLMMessageOptions = {};
if (this.supportToolCall) {
const tools = this.provider.getToolsFromResponse(response);
if (tools.length) {
options = { toolCall: tools };
}
}
return {
raw: response,
message: {
role: "assistant",
content: this.provider.getTextFromResponse(response),
options,
},
};
}
protected async *streamChat(
params: BedrockChatParamsStreaming,
): BedrockChatStreamResponse {
if (!STREAMING_MODELS.has(this.model))
throw new Error(`The model: ${this.model} does not support streaming`);
if (!this.supportToolCall && params.tools?.length) {
console.warn(`The model "${this.model}" doesn't support ToolCall`);
}
const input = this.provider.getRequestBody(
this.metadata,
params.messages,
params.tools,
params.additionalChatOptions,
);
const command = new InvokeModelWithResponseStreamCommand(input);
command.input.modelId = this.actualModel;
const response = await this.client.send(command);
if (response.body) yield* this.provider.reduceStream(response.body);
}
chat(params: BedrockChatParamsStreaming): Promise<BedrockChatStreamResponse>;
chat(
params: BedrockChatParamsNonStreaming,
): Promise<BedrockChatNonStreamResponse>;
@wrapLLMEvent
async chat(
params: BedrockChatParamsStreaming | BedrockChatParamsNonStreaming,
): Promise<BedrockChatStreamResponse | BedrockChatNonStreamResponse> {
if (params.stream) {
return this.streamChat(params);
}
return this.nonStreamChat(params);
}
complete(
params: LLMCompletionParamsStreaming,
): Promise<AsyncIterable<CompletionResponse>>;
complete(
params: LLMCompletionParamsNonStreaming,
): Promise<CompletionResponse>;
async complete(
params: LLMCompletionParamsStreaming | LLMCompletionParamsNonStreaming,
): Promise<CompletionResponse | AsyncIterable<CompletionResponse>> {
const message: ChatMessage = {
role: "user",
content: mapMessageContentToMessageContentDetails(params.prompt),
};
const input = this.provider.getRequestBody(this.metadata, [message]);
if (params.stream) {
const command = new InvokeModelWithResponseStreamCommand(input);
const response = await this.client.send(command);
if (response.body)
return streamConverter(response.body, (response) => {
return {
text: this.provider.getTextFromStreamResponse(response),
raw: response,
};
});
}
const command = new InvokeModelCommand(input);
const response = await this.client.send(command);
return {
text: this.provider.getTextFromResponse(response),
raw: response,
};
}
}
@@ -0,0 +1,3 @@
export const TOKENS = {
TOOL_CALL: "<|python_tag|>",
};
@@ -0,0 +1,153 @@
import type {
InvokeModelCommandInput,
InvokeModelWithResponseStreamCommandInput,
ResponseStream,
} from "@aws-sdk/client-bedrock-runtime";
import type {
BaseTool,
ChatMessage,
LLMMetadata,
ToolCall,
ToolCallLLMMessageOptions,
} from "@llamaindex/core/llms";
import { toUtf8 } from "../utils";
import type { MetaNoneStreamingResponse, MetaStreamEvent } from "./types";
import { randomUUID } from "@llamaindex/env";
import { Provider, type BedrockChatStreamResponse } from "../provider";
import { TOKENS } from "./constants";
import {
mapChatMessagesToMetaLlama2Messages,
mapChatMessagesToMetaLlama3Messages,
} from "./utils";
export class MetaProvider extends Provider<MetaStreamEvent> {
getResultFromResponse(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
response: Record<string, any>,
): MetaNoneStreamingResponse {
return JSON.parse(toUtf8(response.body));
}
getToolsFromResponse<ToolContent>(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
response: Record<string, any>,
): ToolContent[] {
const result = this.getResultFromResponse(response);
if (!result.generation.trim().startsWith(TOKENS.TOOL_CALL)) return [];
const tool = JSON.parse(
result.generation.trim().split(TOKENS.TOOL_CALL)[1]!,
);
return [
{
id: randomUUID(),
name: tool.name,
input: tool.parameters,
} as ToolContent,
];
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
getTextFromResponse(response: Record<string, any>): string {
const result = this.getResultFromResponse(response);
if (result.generation.trim().startsWith(TOKENS.TOOL_CALL)) return "";
return result.generation;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
getTextFromStreamResponse(response: Record<string, any>): string {
const event = this.getStreamingEventResponse(response);
if (event?.generation) {
return event.generation;
}
return "";
}
async *reduceStream(
stream: AsyncIterable<ResponseStream>,
): BedrockChatStreamResponse {
const collecting: string[] = [];
let toolId: string | undefined = undefined;
for await (const response of stream) {
const event = this.getStreamingEventResponse(response);
const delta = this.getTextFromStreamResponse(response);
// odd quirk of llama3.1, start token is \n\n
if (
!toolId &&
!event?.generation.trim() &&
event?.generation_token_count === 1 &&
event?.prompt_token_count !== null
)
continue;
if (delta.startsWith(TOKENS.TOOL_CALL)) {
toolId = randomUUID();
const parts = delta.split(TOKENS.TOOL_CALL).filter((part) => part);
collecting.push(...parts);
continue;
}
let options: undefined | ToolCallLLMMessageOptions = undefined;
if (toolId && event?.stop_reason === "stop") {
if (delta) collecting.push(delta);
const tool = JSON.parse(collecting.join(""));
options = {
toolCall: [
{
id: toolId,
name: tool.name,
input: tool.parameters,
} as ToolCall,
],
};
} else if (toolId && !event?.stop_reason) {
collecting.push(delta);
continue;
}
if (!delta && !options) continue;
yield {
delta: options ? "" : delta,
options,
raw: response,
};
}
}
getRequestBody<T extends ChatMessage>(
metadata: LLMMetadata,
messages: T[],
tools: BaseTool[] = [],
): InvokeModelCommandInput | InvokeModelWithResponseStreamCommandInput {
let prompt: string = "";
let images: string[] = [];
if (metadata.model.startsWith("meta.llama3")) {
const mapped = mapChatMessagesToMetaLlama3Messages({
messages,
tools,
model: metadata.model,
});
prompt = mapped.prompt;
images = mapped.images;
} else if (metadata.model.startsWith("meta.llama2")) {
prompt = mapChatMessagesToMetaLlama2Messages(messages);
} else {
throw new Error(`Meta model ${metadata.model} is not supported`);
}
return {
modelId: metadata.model,
contentType: "application/json",
accept: "application/json",
body: JSON.stringify({
prompt,
images: images.length ? images : undefined,
max_gen_len: metadata.maxTokens,
temperature: metadata.temperature,
top_p: metadata.topP,
}),
};
}
}
@@ -0,0 +1,21 @@
import type { InvocationMetrics } from "../types";
export type MetaTextContent = string;
export type MetaMessage = {
role: "user" | "assistant" | "system" | "ipython";
content: MetaTextContent;
};
type MetaResponse = {
generation: string;
prompt_token_count: number;
generation_token_count: number;
stop_reason: "stop" | "length";
};
export type MetaStreamEvent = MetaResponse & {
"amazon-bedrock-invocationMetrics": InvocationMetrics;
};
export type MetaNoneStreamingResponse = MetaResponse;
@@ -0,0 +1,273 @@
import type {
BaseTool,
ChatMessage,
LLMMetadata,
MessageContentTextDetail,
ToolCallLLMMessageOptions,
} from "@llamaindex/core/llms";
import { extractDataUrlComponents } from "../utils";
import { TOKENS } from "./constants";
import type { MetaMessage } from "./types";
const getToolCallInstructionString = (tool: BaseTool): string => {
return `Use the function '${tool.metadata.name}' to '${tool.metadata.description}'`;
};
const getToolCallParametersString = (tool: BaseTool): string => {
return JSON.stringify({
name: tool.metadata.name,
description: tool.metadata.description,
parameters: tool.metadata.parameters
? Object.entries(tool.metadata.parameters.properties).map(
([name, definition]) => ({ [name]: definition }),
)
: {},
});
};
// 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
export const getToolsPrompt_3_1 = (tools?: BaseTool[]) => {
if (!tools?.length) return "";
const customToolParams = tools.map((tool) => {
return [
getToolCallInstructionString(tool),
getToolCallParametersString(tool),
].join("\n\n");
});
return `
Environment: node
# Tool Instructions
- Never use ipython, always use javascript in node
Cutting Knowledge Date: December 2023
Today Date: ${new Date().toLocaleString("en-US", { year: "numeric", month: "long" })}
You have access to the following functions:
${customToolParams}
Think very carefully before calling functions.
If a you choose to call a function ONLY reply in the following json format:
{
"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
- Put the entire function call reply on one line
- Always add your sources when using search results to answer the user query
`;
};
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 = (
role: ChatMessage["role"],
): MetaMessage["role"] => {
if (role === "assistant") return "assistant";
if (role === "user") return "user";
return "system";
};
export const mapChatMessagesToMetaMessages = <
T extends ChatMessage<ToolCallLLMMessageOptions>,
>(
messages: T[],
): MetaMessage[] => {
return messages.flatMap((msg) => {
if (msg.options && "toolCall" in msg.options) {
return msg.options.toolCall.map((call) => ({
role: "assistant",
content: JSON.stringify({
id: call.id,
name: call.name,
parameters: call.input,
}),
}));
}
if (msg.options && "toolResult" in msg.options) {
return {
role: "ipython",
content: JSON.stringify(msg.options.toolResult),
};
}
let content: string = "";
if (typeof msg.content === "string") {
content = msg.content;
} else if (msg.content.length) {
content = (msg.content[0] as MessageContentTextDetail).text;
}
return {
role: mapChatRoleToMetaRole(msg.role),
content,
};
});
};
/**
* Documentation at https://llama.meta.com/docs/model-cards-and-prompt-formats/meta-llama-3
*/
export const mapChatMessagesToMetaLlama3Messages = <T extends ChatMessage>({
messages,
model,
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[] = [];
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(
"<|begin_of_text|>",
"<|start_header_id|>system<|end_header_id|>",
toolsPrompt,
"<|eot_id|>",
);
}
const mapped = mapChatMessagesToMetaMessages(messages).map((message) => {
return [
"<|start_header_id|>",
message.role,
"<|end_header_id|>",
message.content,
"<|eot_id|>",
].join("\n");
});
parts.push(
"<|begin_of_text|>",
...mapped,
"<|start_header_id|>assistant<|end_header_id|>",
);
const prompt = parts.join("\n");
return { prompt, images };
};
/**
* Documentation at https://llama.meta.com/docs/model-cards-and-prompt-formats/meta-llama-2
*/
export const mapChatMessagesToMetaLlama2Messages = <T extends ChatMessage>(
messages: T[],
): string => {
const mapped = mapChatMessagesToMetaMessages(messages);
let output = "<s>";
let insideInst = false;
let needsStartAgain = false;
for (const message of mapped) {
if (needsStartAgain) {
output += "<s>";
needsStartAgain = false;
}
const text = message.content;
if (message.role === "system") {
if (!insideInst) {
output += "[INST] ";
insideInst = true;
}
output += `<<SYS>>\n${text}\n<</SYS>>\n`;
} else if (message.role === "user") {
output += text;
if (insideInst) {
output += " [/INST]";
insideInst = false;
}
} else if (message.role === "assistant") {
if (insideInst) {
output += " [/INST]";
insideInst = false;
}
output += ` ${text} </s>\n`;
needsStartAgain = true;
}
}
return output;
};
@@ -0,0 +1,63 @@
import {
type InvokeModelCommandInput,
type InvokeModelWithResponseStreamCommandInput,
ResponseStream,
} from "@aws-sdk/client-bedrock-runtime";
import {
type BaseTool,
type ChatMessage,
type ChatResponseChunk,
type LLMMetadata,
type ToolCallLLMMessageOptions,
} from "@llamaindex/core/llms";
import { streamConverter } from "@llamaindex/core/utils";
import { toUtf8 } from "./utils";
export type BedrockAdditionalChatOptions = Record<string, unknown>;
export type BedrockChatStreamResponse = AsyncIterable<
ChatResponseChunk<ToolCallLLMMessageOptions>
>;
export abstract class Provider<ProviderStreamEvent extends object = object> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
abstract getTextFromResponse(response: Record<string, any>): string;
// Return tool calls from none streaming calls
abstract getToolsFromResponse<T extends object = object>(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
response: Record<string, any>,
): T[];
getStreamingEventResponse(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
response: Record<string, any>,
): ProviderStreamEvent | undefined {
return response.chunk?.bytes
? (JSON.parse(toUtf8(response.chunk?.bytes)) as ProviderStreamEvent)
: undefined;
}
async *reduceStream(
stream: AsyncIterable<ResponseStream>,
): BedrockChatStreamResponse {
yield* streamConverter(stream, (response) => {
return {
delta: this.getTextFromStreamResponse(response),
raw: response,
};
});
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
getTextFromStreamResponse(response: Record<string, any>): string {
return this.getTextFromResponse(response);
}
abstract getRequestBody<T extends ChatMessage>(
metadata: LLMMetadata,
messages: T[],
tools?: BaseTool[],
options?: BedrockAdditionalChatOptions,
): InvokeModelCommandInput | InvokeModelWithResponseStreamCommandInput;
}
@@ -0,0 +1,6 @@
export type InvocationMetrics = {
inputTokenCount: number;
outputTokenCount: number;
invocationLatency: number;
firstByteLatency: number;
};
@@ -0,0 +1,23 @@
export const toUtf8 = (input: Uint8Array): string =>
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,
};
};
+10
View File
@@ -0,0 +1,10 @@
import type {
MessageContent,
MessageContentDetail,
} from "@llamaindex/core/llms";
export const mapMessageContentToMessageContentDetails = (
content: MessageContent,
): MessageContentDetail[] => {
return Array.isArray(content) ? content : [{ type: "text", text: content }];
};
@@ -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,
);
}
}
+19
View File
@@ -0,0 +1,19 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist/type",
"tsBuildInfoFile": "./dist/.tsbuildinfo",
"emitDeclarationOnly": true,
"module": "ESNext",
"moduleResolution": "bundler",
"types": ["node"]
},
"include": ["./src"],
"exclude": ["node_modules"],
"references": [
{
"path": "../llamaindex/tsconfig.json"
}
]
}
+7
View File
@@ -1,5 +1,12 @@
# @llamaindex/core
## 0.6.18
### Patch Changes
- f29799e: Add toolcall callbacks to agent workflows
- 7224c06: Add logger and callbacks to llm.exec
## 0.6.17
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/core",
"type": "module",
"version": "0.6.17",
"version": "0.6.18",
"description": "LlamaIndex Core Module",
"exports": {
"./agent": {
+2
View File
@@ -15,6 +15,7 @@ import type {
} from "../llms";
import { baseToolWithCallSchema } from "../schema";
import {
assertIsJSONValue,
isAsyncIterable,
prettifyError,
stringifyJSONToMessageContent,
@@ -227,6 +228,7 @@ export async function callTool(
`Tool ${tool.metadata.name} (remote:${toolCall.name}) succeeded.`,
);
logger.log(`Output: ${JSON.stringify(output)}`);
assertIsJSONValue(output);
const toolOutput: ToolOutput = {
tool,
input,
+16 -9
View File
@@ -1,6 +1,7 @@
import { emptyLogger } from "@llamaindex/env";
import { extractText } from "../utils/llms";
import { streamConverter } from "../utils/stream";
import { callTool, getToolCallsFromResponse } from "./tool-call";
import { callToolToMessage, getToolCallsFromResponse } from "./tool-call";
import type {
ChatMessage,
ChatResponse,
@@ -99,16 +100,19 @@ export abstract class BaseLLM<
if (params.stream) {
return this.streamExec(params);
}
const logger = params.logger ?? emptyLogger;
const newMessages: ChatMessage<AdditionalMessageOptions>[] = [];
const response = await this.chat(params);
newMessages.push(response.message);
const toolCalls = getToolCallsFromResponse(response);
if (params.tools && toolCalls.length > 0) {
for (const toolCall of toolCalls) {
const toolResultMessage = await callTool<AdditionalMessageOptions>(
params.tools,
toolCall,
);
const toolResultMessage =
await callToolToMessage<AdditionalMessageOptions>(
params.tools,
toolCall,
logger,
);
if (toolResultMessage) {
newMessages.push(toolResultMessage);
}
@@ -126,6 +130,7 @@ export abstract class BaseLLM<
AdditionalMessageOptions
>,
): Promise<ExecStreamResponse<AdditionalMessageOptions>> {
const logger = params.logger ?? emptyLogger;
const responseStream = await this.chat(params);
const iterator = responseStream[Symbol.asyncIterator]();
const first = await iterator.next();
@@ -220,10 +225,12 @@ export abstract class BaseLLM<
} as AdditionalMessageOptions,
});
for (const toolCall of toolCalls) {
const toolResultMessage = await callTool<AdditionalMessageOptions>(
params.tools,
toolCall,
);
const toolResultMessage =
await callToolToMessage<AdditionalMessageOptions>(
params.tools,
toolCall,
logger,
);
if (toolResultMessage) {
messages.push(toolResultMessage);
}
+20 -17
View File
@@ -1,3 +1,5 @@
import { type Logger } from "@llamaindex/env";
import { callTool } from "../agent/utils.js";
import { stringifyJSONToMessageContent } from "../utils";
import type {
BaseTool,
@@ -35,27 +37,28 @@ export const getToolCallsFromResponse = (
return [];
};
export const callTool = async <
export const callToolToMessage = async <
AdditionalMessageOptions extends object = object,
>(
tools: BaseTool[],
toolCall: ToolCall,
logger: Logger,
): Promise<ChatMessage<AdditionalMessageOptions> | null> => {
const tool = tools?.find((t) => t.metadata.name === toolCall.name);
// TODO: consider using BaseToolWithCall instead of BaseTool to avoid checking for tool.call
if (tool && tool.call) {
const result = await tool.call(toolCall.input);
const toolResultMessage: ChatMessage<AdditionalMessageOptions> = {
role: "user",
content: stringifyJSONToMessageContent(result),
options: {
toolResult: {
id: toolCall.id,
result,
},
} as AdditionalMessageOptions,
};
return toolResultMessage;
}
return null;
const toolOutput = await callTool(tool, toolCall, logger);
const toolResultMessage: ChatMessage<AdditionalMessageOptions> = {
role: "user",
content: stringifyJSONToMessageContent(toolOutput.output),
options: {
toolResult: {
id: toolCall.id,
result: toolOutput.output,
isError: toolOutput.isError,
},
} as AdditionalMessageOptions,
};
return toolResultMessage;
};
+2
View File
@@ -1,3 +1,4 @@
import type { Logger } from "@llamaindex/env";
import type { Tokenizers } from "@llamaindex/env/tokenizers";
import type { JSONSchemaType } from "ajv";
import { z } from "zod";
@@ -139,6 +140,7 @@ export interface LLMChatParamsBase<
additionalChatOptions?: AdditionalChatOptions | undefined;
tools?: BaseTool[] | undefined;
responseFormat?: z.ZodType | object | undefined;
logger?: Logger | undefined;
}
export interface LLMChatParamsStreaming<
+12
View File
@@ -1,5 +1,17 @@
# @llamaindex/experimental
## 0.0.200
### Patch Changes
- llamaindex@0.11.23
## 0.0.199
### Patch Changes
- llamaindex@0.11.22
## 0.0.198
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/experimental",
"description": "Experimental package for LlamaIndexTS",
"version": "0.0.198",
"version": "0.0.200",
"type": "module",
"types": "dist/type/index.d.ts",
"main": "dist/cjs/index.js",
+18
View File
@@ -1,5 +1,23 @@
# llamaindex
## 0.11.23
### Patch Changes
- Updated dependencies [f29799e]
- Updated dependencies [7224c06]
- @llamaindex/workflow@1.1.19
- @llamaindex/core@0.6.18
- @llamaindex/cloud@4.0.27
- @llamaindex/node-parser@2.0.18
## 0.11.22
### Patch Changes
- Updated dependencies [9ed3195]
- @llamaindex/workflow@1.1.18
## 0.11.21
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "llamaindex",
"version": "0.11.21",
"version": "0.11.23",
"license": "MIT",
"type": "module",
"keywords": [
+6
View File
@@ -1,5 +1,11 @@
# @llamaindex/core-test
## 0.1.14
### Patch Changes
- @llamaindex/openai@0.4.13
## 0.1.13
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/llamaindex-test",
"private": true,
"version": "0.1.13",
"version": "0.1.14",
"type": "module",
"scripts": {
"test": "vitest run"
+8
View File
@@ -1,5 +1,13 @@
# @llamaindex/node-parser
## 2.0.18
### Patch Changes
- Updated dependencies [f29799e]
- Updated dependencies [7224c06]
- @llamaindex/core@0.6.18
## 2.0.17
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/node-parser",
"version": "2.0.17",
"version": "2.0.18",
"description": "Node parser for LlamaIndex",
"type": "module",
"exports": {
@@ -1,5 +1,13 @@
# @llamaindex/anthropic
## 0.3.20
### Patch Changes
- Updated dependencies [f29799e]
- Updated dependencies [7224c06]
- @llamaindex/core@0.6.18
## 0.3.19
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/anthropic",
"description": "Anthropic Adapter for LlamaIndex",
"version": "0.3.19",
"version": "0.3.20",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
@@ -1,5 +1,13 @@
# @llamaindex/assemblyai
## 0.1.17
### Patch Changes
- Updated dependencies [f29799e]
- Updated dependencies [7224c06]
- @llamaindex/core@0.6.18
## 0.1.16
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/assemblyai",
"description": "AssemblyAI Reader for LlamaIndex",
"version": "0.1.16",
"version": "0.1.17",
"type": "module",
"types": "dist/index.d.ts",
"main": "dist/index.cjs",
+14
View File
@@ -1,5 +1,19 @@
# @llamaindex/community
## 0.0.114
### Patch Changes
- Updated dependencies [f29799e]
- Updated dependencies [7224c06]
- @llamaindex/core@0.6.18
## 0.0.113
### Patch Changes
- c65a2dc: Deprecate community package and link to AWS package
## 0.0.112
### Patch Changes
+22 -5
View File
@@ -1,17 +1,34 @@
# @llamaindex/community
# @llamaindex/aws
> Tools written by the community for llamaindex
AWS package for LlamaIndexTS
## Current Features:
- Bedrock support for Amazon Nova models Pro, Lite and Micro
- Bedrock support for the Anthropic Claude Models [usage](https://ts.llamaindex.ai/docs/llamaindex/modules/llms/bedrock) including the latest Sonnet 3.5 v2 and Haiku 3.5
- Bedrock support for the Meta LLama 2, 3, 3.1 and 3.2 Models [usage](https://ts.llamaindex.ai/docs/llamaindex/modules/llms/bedrock)
- Bedrock support for Amazon Nova models (Premier, Pro, Lite and Micro)
- Bedrock support for the Anthropic Claude Models including the latest Claude 4 (Sonnet and Opus)
- Bedrock support for the Meta LLama 2, 3, 3.1, 3.2 and 3.3 Models
- Meta LLama3.1 405b and Llama3.2 tool call support
- Meta 3.2 11B and 90B vision support
- Anthropic Claude models (Sonnet, Haiku, Opus) multimodal support
- Bedrock support for querying Knowledge Base
- Support for Bedrock Inference endpoints with regional models
- Bedrock: [Supported Regions and models for cross-region inference](https://docs.aws.amazon.com/bedrock/latest/userguide/cross-region-inference-support.html)
## Basic Usage
```ts
import { BEDROCK_MODELS, Bedrock } from "@llamaindex/aws";
Settings.llm = new Bedrock({
model: BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_HAIKU,
region: "us-east-1", // can be provided via env AWS_REGION
credentials: {
accessKeyId: "...", // optional and can be provided via env AWS_ACCESS_KEY_ID
secretAccessKey: "...", // optional and can be provided via env AWS_SECRET_ACCESS_KEY
},
});
```
## LICENSE
MIT
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/aws",
"description": "AWS package for LlamaIndexTS",
"version": "0.0.112",
"version": "0.0.114",
"type": "module",
"types": "dist/type/index.d.ts",
"main": "dist/cjs/index.js",
+9
View File
@@ -1,5 +1,14 @@
# @llamaindex/clip
## 0.0.69
### Patch Changes
- Updated dependencies [f29799e]
- Updated dependencies [7224c06]
- @llamaindex/core@0.6.18
- @llamaindex/openai@0.4.13
## 0.0.68
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/clip",
"description": "Clip Embedding Adapter for LlamaIndex",
"version": "0.0.68",
"version": "0.0.69",
"type": "module",
"types": "dist/index.d.ts",
"main": "dist/index.cjs",
+8
View File
@@ -1,5 +1,13 @@
# @llamaindex/cohere
## 0.0.32
### Patch Changes
- Updated dependencies [f29799e]
- Updated dependencies [7224c06]
- @llamaindex/core@0.6.18
## 0.0.31
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/cohere",
"description": "Cohere Adapter for LlamaIndex",
"version": "0.0.31",
"version": "0.0.32",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
@@ -1,5 +1,14 @@
# @llamaindex/deepinfra
## 0.0.69
### Patch Changes
- Updated dependencies [f29799e]
- Updated dependencies [7224c06]
- @llamaindex/core@0.6.18
- @llamaindex/openai@0.4.13
## 0.0.68
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/deepinfra",
"description": "Deepinfra Adapter for LlamaIndex",
"version": "0.0.68",
"version": "0.0.69",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
+6
View File
@@ -1,5 +1,11 @@
# @llamaindex/deepseek
## 0.0.30
### Patch Changes
- @llamaindex/openai@0.4.13
## 0.0.29
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/deepseek",
"description": "DeepSeek Adapter for LlamaIndex",
"version": "0.0.29",
"version": "0.0.30",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
+8
View File
@@ -1,5 +1,13 @@
# @llamaindex/discord
## 0.1.17
### Patch Changes
- Updated dependencies [f29799e]
- Updated dependencies [7224c06]
- @llamaindex/core@0.6.18
## 0.1.16
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/discord",
"description": "Discord Reader for LlamaIndex",
"version": "0.1.16",
"version": "0.1.17",
"type": "module",
"types": "dist/index.d.ts",
"main": "dist/index.cjs",
+8
View File
@@ -1,5 +1,13 @@
# @llamaindex/excel
## 0.1.18
### Patch Changes
- Updated dependencies [f29799e]
- Updated dependencies [7224c06]
- @llamaindex/core@0.6.18
## 0.1.17
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/excel",
"description": "Excel Reader for LlamaIndex",
"version": "0.1.17",
"version": "0.1.18",
"type": "module",
"types": "dist/index.d.ts",
"main": "dist/index.cjs",
@@ -1,5 +1,11 @@
# @llamaindex/fireworks
## 0.0.29
### Patch Changes
- @llamaindex/openai@0.4.13
## 0.0.28
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/fireworks",
"description": "Fireworks Adapter for LlamaIndex",
"version": "0.0.28",
"version": "0.0.29",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
+8
View File
@@ -1,5 +1,13 @@
# @llamaindex/google
## 0.3.17
### Patch Changes
- Updated dependencies [f29799e]
- Updated dependencies [7224c06]
- @llamaindex/core@0.6.18
## 0.3.16
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/google",
"description": "Google Adapter for LlamaIndex",
"version": "0.3.16",
"version": "0.3.17",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
+6
View File
@@ -1,5 +1,11 @@
# @llamaindex/groq
## 0.0.85
### Patch Changes
- @llamaindex/openai@0.4.13
## 0.0.84
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/groq",
"description": "Groq Adapter for LlamaIndex",
"version": "0.0.84",
"version": "0.0.85",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
@@ -1,5 +1,14 @@
# @llamaindex/huggingface
## 0.1.23
### Patch Changes
- Updated dependencies [f29799e]
- Updated dependencies [7224c06]
- @llamaindex/core@0.6.18
- @llamaindex/openai@0.4.13
## 0.1.22
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/huggingface",
"description": "Huggingface Adapter for LlamaIndex",
"version": "0.1.22",
"version": "0.1.23",
"type": "module",
"types": "dist/index.d.ts",
"main": "dist/index.cjs",
+9
View File
@@ -1,5 +1,14 @@
# @llamaindex/jinaai
## 0.0.29
### Patch Changes
- Updated dependencies [f29799e]
- Updated dependencies [7224c06]
- @llamaindex/core@0.6.18
- @llamaindex/openai@0.4.13
## 0.0.28
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/jinaai",
"description": "JinaAI Adapter for LlamaIndex",
"version": "0.0.28",
"version": "0.0.29",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
+8
View File
@@ -1,5 +1,13 @@
# @llamaindex/mistral
## 0.1.18
### Patch Changes
- Updated dependencies [f29799e]
- Updated dependencies [7224c06]
- @llamaindex/core@0.6.18
## 0.1.17
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/mistral",
"description": "Mistral Adapter for LlamaIndex",
"version": "0.1.17",
"version": "0.1.18",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
@@ -1,5 +1,13 @@
# @llamaindex/mixedbread
## 0.0.32
### Patch Changes
- Updated dependencies [f29799e]
- Updated dependencies [7224c06]
- @llamaindex/core@0.6.18
## 0.0.31
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/mixedbread",
"description": "Mixedbread Adapter for LlamaIndex",
"version": "0.0.31",
"version": "0.0.32",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
+8
View File
@@ -1,5 +1,13 @@
# @llamaindex/notion
## 0.1.17
### Patch Changes
- Updated dependencies [f29799e]
- Updated dependencies [7224c06]
- @llamaindex/core@0.6.18
## 0.1.16
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/notion",
"description": "Notion Reader for LlamaIndex",
"version": "0.1.16",
"version": "0.1.17",
"type": "module",
"types": "dist/index.d.ts",
"main": "dist/index.cjs",
+8
View File
@@ -1,5 +1,13 @@
# @llamaindex/ollama
## 0.1.18
### Patch Changes
- Updated dependencies [f29799e]
- Updated dependencies [7224c06]
- @llamaindex/core@0.6.18
## 0.1.17
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/ollama",
"description": "Ollama Adapter for LlamaIndex",
"version": "0.1.17",
"version": "0.1.18",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
+8
View File
@@ -1,5 +1,13 @@
# @llamaindex/openai
## 0.4.13
### Patch Changes
- Updated dependencies [f29799e]
- Updated dependencies [7224c06]
- @llamaindex/core@0.6.18
## 0.4.12
### Patch Changes

Some files were not shown because too many files have changed in this diff Show More