Compare commits

..

1 Commits

Author SHA1 Message Date
Marcus Schiesser b7a7c7bdbc text: add cycle test 2024-09-30 12:47:05 +07:00
50 changed files with 117 additions and 643 deletions
-21
View File
@@ -1,26 +1,5 @@
# docs
## 0.0.83
### Patch Changes
- llamaindex@0.6.14
## 0.0.82
### Patch Changes
- llamaindex@0.6.13
## 0.0.81
### Patch Changes
- Updated dependencies [f7b4e94]
- Updated dependencies [78037a6]
- Updated dependencies [1d9e3b1]
- llamaindex@0.6.12
## 0.0.80
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "docs",
"version": "0.0.83",
"version": "0.0.80",
"private": true,
"scripts": {
"docusaurus": "docusaurus",
-21
View File
@@ -1,26 +1,5 @@
# @llamaindex/autotool
## 3.0.14
### Patch Changes
- llamaindex@0.6.14
## 3.0.13
### Patch Changes
- llamaindex@0.6.13
## 3.0.12
### Patch Changes
- Updated dependencies [f7b4e94]
- Updated dependencies [78037a6]
- Updated dependencies [1d9e3b1]
- llamaindex@0.6.12
## 3.0.11
### Patch Changes
@@ -1,29 +1,5 @@
# @llamaindex/autotool-01-node-example
## 0.0.23
### Patch Changes
- llamaindex@0.6.14
- @llamaindex/autotool@3.0.14
## 0.0.22
### Patch Changes
- llamaindex@0.6.13
- @llamaindex/autotool@3.0.13
## 0.0.21
### Patch Changes
- Updated dependencies [f7b4e94]
- Updated dependencies [78037a6]
- Updated dependencies [1d9e3b1]
- llamaindex@0.6.12
- @llamaindex/autotool@3.0.12
## 0.0.20
### Patch Changes
@@ -13,5 +13,5 @@
"scripts": {
"start": "node --import tsx --import @llamaindex/autotool/node ./src/index.ts"
},
"version": "0.0.23"
"version": "0.0.20"
}
@@ -1,29 +1,5 @@
# @llamaindex/autotool-02-next-example
## 0.1.67
### Patch Changes
- llamaindex@0.6.14
- @llamaindex/autotool@3.0.14
## 0.1.66
### Patch Changes
- llamaindex@0.6.13
- @llamaindex/autotool@3.0.13
## 0.1.65
### Patch Changes
- Updated dependencies [f7b4e94]
- Updated dependencies [78037a6]
- Updated dependencies [1d9e3b1]
- llamaindex@0.6.12
- @llamaindex/autotool@3.0.12
## 0.1.64
### Patch Changes
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/autotool-02-next-example",
"private": true,
"version": "0.1.67",
"version": "0.1.64",
"scripts": {
"dev": "next dev",
"build": "next build",
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/autotool",
"type": "module",
"version": "3.0.14",
"version": "3.0.11",
"description": "auto transpile your JS function to LLM Agent compatible",
"files": [
"dist",
-6
View File
@@ -1,11 +1,5 @@
# @llamaindex/cloud
## 0.2.10
### Patch Changes
- 981811e: fix(cloud): llama parse reader save image incorrectly
## 0.2.9
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/cloud",
"version": "0.2.10",
"version": "0.2.9",
"type": "module",
"license": "MIT",
"scripts": {
+14 -6
View File
@@ -1,11 +1,11 @@
import { type Client, createClient, createConfig } from "@hey-api/client-fetch";
import { createClient, createConfig, type Client } from "@hey-api/client-fetch";
import { Document, FileReader } from "@llamaindex/core/schema";
import { fs, getEnv, path } from "@llamaindex/env";
import { fs, getEnv } from "@llamaindex/env";
import { filetypeinfo } from "magic-bytes.js";
import {
ParsingService,
type Body_upload_file_api_v1_parsing_upload_post,
type ParserLanguages,
ParsingService,
} from "./api";
import { sleep } from "./utils";
@@ -510,7 +510,14 @@ export class LlamaParseReader extends FileReader {
jobId: string,
imageName: string,
): Promise<string> {
return path.join(downloadPath, `${jobId}-${imageName}`);
// Get the full path
let imagePath = `${downloadPath}/${jobId}-${imageName}`;
// Get a valid image path
if (!imagePath.endsWith(".png") && !imagePath.endsWith(".jpg")) {
imagePath += ".png";
}
return imagePath;
}
private async fetchAndSaveImage(
@@ -531,9 +538,10 @@ export class LlamaParseReader extends FileReader {
if (response.error) {
throw new Error(`Failed to download image: ${response.error.detail}`);
}
const blob = (await response.data) as Blob;
const arrayBuffer = (await response.data) as ArrayBuffer;
const buffer = new Uint8Array(arrayBuffer);
// Write the image buffer to the specified imagePath
await fs.writeFile(imagePath, new Uint8Array(await blob.arrayBuffer()));
await fs.writeFile(imagePath, buffer);
}
// Filters out invalid values (null, undefined, empty string) of specific params.
-13
View File
@@ -1,18 +1,5 @@
# @llamaindex/community
## 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
+2 -4
View File
@@ -5,11 +5,9 @@
## Current Features:
- Bedrock support for the Anthropic Claude Models [usage](https://ts.llamaindex.ai/modules/llms/available_llms/bedrock)
- Bedrock support for the Meta LLama 2, 3, 3.1 and 3.2 Models [usage](https://ts.llamaindex.ai/modules/llms/available_llms/bedrock)
- Meta LLama3.1 405b and Llama3.2 tool call support
- Meta 3.2 11B and 90B vision support
- Bedrock support for the Meta LLama 2, 3 and 3.1 Models [usage](https://ts.llamaindex.ai/modules/llms/available_llms/bedrock)
- Meta LLama3.1 405b tool call 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
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/community",
"description": "Community package for LlamaIndexTS",
"version": "0.0.44",
"version": "0.0.42",
"type": "module",
"types": "dist/type/index.d.ts",
"main": "dist/cjs/index.js",
-2
View File
@@ -2,7 +2,5 @@ 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";
@@ -6,10 +6,7 @@ import type {
MessageContentDetail,
ToolCallLLMMessageOptions,
} from "@llamaindex/core/llms";
import {
extractDataUrlComponents,
mapMessageContentToMessageContentDetails,
} from "../utils";
import { mapMessageContentToMessageContentDetails } from "../utils";
import type {
AnthropicContent,
AnthropicImageContent,
@@ -146,6 +143,27 @@ export const mapTextContent = (text: string): AnthropicTextContent => {
return { type: "text", text };
};
export const extractDataUrlComponents = (
dataUrl: string,
): {
mimeType: string;
base64: string;
} => {
const parts = dataUrl.split(";base64,");
if (parts.length !== 2 || !parts[0]!.startsWith("data:")) {
throw new Error("Invalid data URL");
}
const mimeType = parts[0]!.slice(5);
const base64 = parts[1]!;
return {
mimeType,
base64,
};
};
export const mapImageContent = (imageUrl: string): AnthropicImageContent => {
if (!imageUrl.startsWith("data:"))
throw new Error(
+36 -118
View File
@@ -47,96 +47,35 @@ export type BedrockChatParamsNonStreaming = LLMChatParamsNonStreaming<
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",
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",
MISTRAL_7B_INSTRUCT: "mistral.mistral-7b-instruct-v0:2",
MISTRAL_MIXTRAL_7B_INSTRUCT: "mistral.mixtral-8x7b-instruct-v0:1",
MISTRAL_MIXTRAL_LARGE_2402: "mistral.mistral-large-2402-v1:0",
};
export type BEDROCK_MODELS =
(typeof BEDROCK_MODELS)[keyof typeof BEDROCK_MODELS];
export const INFERENCE_BEDROCK_MODELS = {
US_ANTHROPIC_CLAUDE_3_HAIKU: "us.anthropic.claude-3-haiku-20240307-v1:0",
US_ANTHROPIC_CLAUDE_3_OPUS: "us.anthropic.claude-3-opus-20240229-v1:0",
US_ANTHROPIC_CLAUDE_3_SONNET: "us.anthropic.claude-3-sonnet-20240229-v1:0",
US_ANTHROPIC_CLAUDE_3_5_SONNET:
"us.anthropic.claude-3-5-sonnet-20240620-v1:0",
US_META_LLAMA_3_2_1B_INSTRUCT: "us.meta.llama3-2-1b-instruct-v1:0",
US_META_LLAMA_3_2_3B_INSTRUCT: "us.meta.llama3-2-3b-instruct-v1:0",
US_META_LLAMA_3_2_11B_INSTRUCT: "us.meta.llama3-2-11b-instruct-v1:0",
US_META_LLAMA_3_2_90B_INSTRUCT: "us.meta.llama3-2-90b-instruct-v1:0",
EU_ANTHROPIC_CLAUDE_3_HAIKU: "eu.anthropic.claude-3-haiku-20240307-v1:0",
EU_ANTHROPIC_CLAUDE_3_SONNET: "eu.anthropic.claude-3-sonnet-20240229-v1:0",
EU_ANTHROPIC_CLAUDE_3_5_SONNET:
"eu.anthropic.claude-3-5-sonnet-20240620-v1:0",
EU_META_LLAMA_3_2_1B_INSTRUCT: "eu.meta.llama3-2-1b-instruct-v1:0",
EU_META_LLAMA_3_2_3B_INSTRUCT: "eu.meta.llama3-2-3b-instruct-v1:0",
};
export type INFERENCE_BEDROCK_MODELS =
(typeof INFERENCE_BEDROCK_MODELS)[keyof typeof INFERENCE_BEDROCK_MODELS];
export const INFERENCE_TO_BEDROCK_MAP: Record<
INFERENCE_BEDROCK_MODELS,
BEDROCK_MODELS
> = {
[INFERENCE_BEDROCK_MODELS.US_ANTHROPIC_CLAUDE_3_HAIKU]:
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_HAIKU,
[INFERENCE_BEDROCK_MODELS.US_ANTHROPIC_CLAUDE_3_OPUS]:
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_OPUS,
[INFERENCE_BEDROCK_MODELS.US_ANTHROPIC_CLAUDE_3_SONNET]:
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_SONNET,
[INFERENCE_BEDROCK_MODELS.US_ANTHROPIC_CLAUDE_3_5_SONNET]:
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_5_SONNET,
[INFERENCE_BEDROCK_MODELS.US_META_LLAMA_3_2_1B_INSTRUCT]:
BEDROCK_MODELS.META_LLAMA3_2_1B_INSTRUCT,
[INFERENCE_BEDROCK_MODELS.US_META_LLAMA_3_2_3B_INSTRUCT]:
BEDROCK_MODELS.META_LLAMA3_2_3B_INSTRUCT,
[INFERENCE_BEDROCK_MODELS.US_META_LLAMA_3_2_11B_INSTRUCT]:
BEDROCK_MODELS.META_LLAMA3_2_11B_INSTRUCT,
[INFERENCE_BEDROCK_MODELS.US_META_LLAMA_3_2_90B_INSTRUCT]:
BEDROCK_MODELS.META_LLAMA3_2_90B_INSTRUCT,
[INFERENCE_BEDROCK_MODELS.EU_ANTHROPIC_CLAUDE_3_HAIKU]:
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_HAIKU,
[INFERENCE_BEDROCK_MODELS.EU_ANTHROPIC_CLAUDE_3_SONNET]:
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_SONNET,
[INFERENCE_BEDROCK_MODELS.EU_ANTHROPIC_CLAUDE_3_5_SONNET]:
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_5_SONNET,
[INFERENCE_BEDROCK_MODELS.EU_META_LLAMA_3_2_1B_INSTRUCT]:
BEDROCK_MODELS.META_LLAMA3_2_1B_INSTRUCT,
[INFERENCE_BEDROCK_MODELS.EU_META_LLAMA_3_2_3B_INSTRUCT]:
BEDROCK_MODELS.META_LLAMA3_2_3B_INSTRUCT,
};
export enum 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",
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",
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",
}
/*
* Values taken from https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters.html#model-parameters-claude
@@ -170,10 +109,6 @@ const CHAT_ONLY_MODELS = {
[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.MISTRAL_7B_INSTRUCT]: 32000,
[BEDROCK_MODELS.MISTRAL_MIXTRAL_7B_INSTRUCT]: 32000,
[BEDROCK_MODELS.MISTRAL_MIXTRAL_LARGE_2402]: 32000,
@@ -204,25 +139,17 @@ export const STREAMING_MODELS = new Set([
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.MISTRAL_7B_INSTRUCT,
BEDROCK_MODELS.MISTRAL_MIXTRAL_7B_INSTRUCT,
BEDROCK_MODELS.MISTRAL_MIXTRAL_LARGE_2402,
]);
export const TOOL_CALL_MODELS: BEDROCK_MODELS[] = [
export const TOOL_CALL_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.META_LLAMA3_1_405B_INSTRUCT,
BEDROCK_MODELS.META_LLAMA3_2_1B_INSTRUCT,
BEDROCK_MODELS.META_LLAMA3_2_3B_INSTRUCT,
BEDROCK_MODELS.META_LLAMA3_2_11B_INSTRUCT,
BEDROCK_MODELS.META_LLAMA3_2_90B_INSTRUCT,
];
const getProvider = (model: string): Provider => {
@@ -239,7 +166,7 @@ const getProvider = (model: string): Provider => {
};
export type BedrockModelParams = {
model: BEDROCK_MODELS | INFERENCE_BEDROCK_MODELS;
model: keyof typeof BEDROCK_FOUNDATION_LLMS;
temperature?: number;
topP?: number;
maxTokens?: number;
@@ -258,10 +185,6 @@ export const BEDROCK_MODEL_MAX_TOKENS: Partial<Record<BEDROCK_MODELS, number>> =
[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,
};
const DEFAULT_BEDROCK_PARAMS = {
@@ -270,15 +193,14 @@ const DEFAULT_BEDROCK_PARAMS = {
maxTokens: 1024, // required by anthropic
};
export type BedrockParams = BedrockRuntimeClientConfig & BedrockModelParams;
export type BedrockParams = BedrockModelParams & BedrockRuntimeClientConfig;
/**
* ToolCallLLM for Bedrock
*/
export class Bedrock extends ToolCallLLM<BedrockAdditionalChatOptions> {
private client: BedrockRuntimeClient;
protected actualModel: BEDROCK_MODELS | INFERENCE_BEDROCK_MODELS;
model: BEDROCK_MODELS;
model: keyof typeof BEDROCK_FOUNDATION_LLMS;
temperature: number;
topP: number;
maxTokens?: number;
@@ -295,8 +217,8 @@ export class Bedrock extends ToolCallLLM<BedrockAdditionalChatOptions> {
...params
}: BedrockParams) {
super();
this.actualModel = model;
this.model = INFERENCE_TO_BEDROCK_MAP[model] ?? model;
this.model = model;
this.provider = getProvider(this.model);
this.maxTokens = maxTokens ?? DEFAULT_BEDROCK_PARAMS.maxTokens;
this.temperature = temperature ?? DEFAULT_BEDROCK_PARAMS.temperature;
@@ -319,7 +241,7 @@ export class Bedrock extends ToolCallLLM<BedrockAdditionalChatOptions> {
temperature: this.temperature,
topP: this.topP,
maxTokens: this.maxTokens,
contextWindow: BEDROCK_FOUNDATION_LLMS[this.model] ?? 128000,
contextWindow: BEDROCK_FOUNDATION_LLMS[this.model],
tokenizer: undefined,
};
}
@@ -334,8 +256,6 @@ export class Bedrock extends ToolCallLLM<BedrockAdditionalChatOptions> {
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) {
@@ -367,8 +287,6 @@ export class Bedrock extends ToolCallLLM<BedrockAdditionalChatOptions> {
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);
@@ -67,26 +67,21 @@ export class MetaProvider extends Provider<MetaStreamEvent> {
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
event.prompt_token_count !== null
)
continue;
if (delta.startsWith(TOKENS.TOOL_CALL)) {
if (delta === 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: [
@@ -115,18 +110,11 @@ export class MetaProvider extends Provider<MetaStreamEvent> {
getRequestBody<T extends ChatMessage>(
metadata: LLMMetadata,
messages: T[],
tools: BaseTool[] = [],
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;
prompt = mapChatMessagesToMetaLlama3Messages(messages, tools);
} else if (metadata.model.startsWith("meta.llama2")) {
prompt = mapChatMessagesToMetaLlama2Messages(messages);
} else {
@@ -139,7 +127,6 @@ export class MetaProvider extends Provider<MetaStreamEvent> {
accept: "application/json",
body: JSON.stringify({
prompt,
images: images.length ? images : undefined,
max_gen_len: metadata.maxTokens,
temperature: metadata.temperature,
top_p: metadata.topP,
@@ -1,12 +1,9 @@
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 => {
@@ -27,7 +24,7 @@ const getToolCallParametersString = (tool: BaseTool): string => {
// 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[]) => {
export const getToolsPrompt = (tools?: BaseTool[]) => {
if (!tools?.length) return "";
const customToolParams = tools.map((tool) => {
@@ -80,46 +77,6 @@ Reminder:
`;
};
export const getToolsPrompt_3_2 = (tools?: BaseTool[]) => {
if (!tools?.length) return "";
return `
You are an expert in composing functions. You are given a question and a set of possible functions.
Based on the question, you will need to make one or more function/tool calls to achieve the purpose.
If none of the function can be used, point it out. If the given question lacks the parameters required by the function,
also point it out. You should only return the function call in tools call sections.
If you decide to invoke any of the function(s), you MUST put it in the format of and start with the token: ${TOKENS.TOOL_CALL}:
{
"name": function_name,
"parameters": parameters,
}
where
{
"name": function_name,
"parameters": parameters, => a JSON dict with the function argument name as key and function argument value as value.
}
Here is an example,
{
"name": "example_function_name",
"parameters": {"example_name": "example_value"}
}
Reminder:
- Function calls MUST follow the specified format
- Required parameters MUST be specified
- Only call one function at a time
- You SHOULD NOT include any other text in the response
- Put the entire function call reply on one line
Here is a list of functions in JSON format that you can invoke.
${JSON.stringify(tools)}
`;
};
export const mapChatRoleToMetaRole = (
role: ChatMessage["role"],
): MetaMessage["role"] => {
@@ -168,46 +125,16 @@ export const mapChatMessagesToMetaMessages = <
/**
* 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);
}
});
export const mapChatMessagesToMetaLlama3Messages = <T extends ChatMessage>(
messages: T[],
tools?: BaseTool[],
): string => {
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) {
if (tools?.length) {
parts.push(
"<|begin_of_text|>",
"<|start_header_id|>system<|end_header_id|>",
toolsPrompt,
getToolsPrompt(tools),
"<|eot_id|>",
);
}
@@ -227,9 +154,7 @@ export const mapChatMessagesToMetaLlama3Messages = <T extends ChatMessage>({
...mapped,
"<|start_header_id|>assistant<|end_header_id|>",
);
const prompt = parts.join("\n");
return { prompt, images };
return parts.join("\n");
};
/**
@@ -11,24 +11,3 @@ export const mapMessageContentToMessageContentDetails = (
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,
};
};
-6
View File
@@ -1,11 +1,5 @@
# @llamaindex/core
## 0.2.9
### Patch Changes
- b17d439: Fix #1278: resolved issue where the id\_ was not correctly passed as the id when creating a TextNode. As a result, the upsert operation to the vector database was using a generated ID instead of the provided document ID, if available.
## 0.2.8
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/core",
"type": "module",
"version": "0.2.9",
"version": "0.2.8",
"description": "LlamaIndex Core Module",
"exports": {
"./agent": {
+2 -2
View File
@@ -479,7 +479,7 @@ export function buildNodeFromSplits(
) {
const imageDoc = doc as ImageNode;
const imageNode = new ImageNode({
id_: imageDoc.id_ ?? idGenerator(i, imageDoc),
id_: idGenerator(i, imageDoc),
text: textChunk,
image: imageDoc.image,
embedding: imageDoc.embedding,
@@ -496,7 +496,7 @@ export function buildNodeFromSplits(
) {
const textDoc = doc as TextNode;
const node = new TextNode({
id_: textDoc.id_ ?? idGenerator(i, textDoc),
id_: idGenerator(i, textDoc),
text: textChunk,
embedding: textDoc.embedding,
excludedEmbedMetadataKeys: [...textDoc.excludedEmbedMetadataKeys],
-21
View File
@@ -1,26 +1,5 @@
# @llamaindex/experimental
## 0.0.92
### Patch Changes
- llamaindex@0.6.14
## 0.0.91
### Patch Changes
- llamaindex@0.6.13
## 0.0.90
### Patch Changes
- Updated dependencies [f7b4e94]
- Updated dependencies [78037a6]
- Updated dependencies [1d9e3b1]
- llamaindex@0.6.12
## 0.0.89
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/experimental",
"description": "Experimental package for LlamaIndexTS",
"version": "0.0.92",
"version": "0.0.89",
"type": "module",
"types": "dist/type/index.d.ts",
"main": "dist/cjs/index.js",
-25
View File
@@ -1,30 +1,5 @@
# llamaindex
## 0.6.14
### Patch Changes
- Updated dependencies [b17d439]
- @llamaindex/core@0.2.9
- @llamaindex/ollama@0.0.4
- @llamaindex/openai@0.1.11
- @llamaindex/groq@0.0.10
## 0.6.13
### Patch Changes
- Updated dependencies [981811e]
- @llamaindex/cloud@0.2.10
## 0.6.12
### Patch Changes
- f7b4e94: feat: add filters for pinecone
- 78037a6: fix: bypass service context embed model
- 1d9e3b1: fix: export llama reader in non-nodejs runtime
## 0.6.11
### Patch Changes
@@ -1,26 +1,5 @@
# @llamaindex/cloudflare-worker-agent-test
## 0.0.76
### Patch Changes
- llamaindex@0.6.14
## 0.0.75
### Patch Changes
- llamaindex@0.6.13
## 0.0.74
### Patch Changes
- Updated dependencies [f7b4e94]
- Updated dependencies [78037a6]
- Updated dependencies [1d9e3b1]
- llamaindex@0.6.12
## 0.0.73
### Patch Changes
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/cloudflare-worker-agent-test",
"version": "0.0.76",
"version": "0.0.73",
"type": "module",
"private": true,
"scripts": {
@@ -1,12 +1,5 @@
# @llamaindex/llama-parse-browser-test
## 0.0.6
### Patch Changes
- Updated dependencies [981811e]
- @llamaindex/cloud@0.2.10
## 0.0.5
### Patch Changes
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/llama-parse-browser-test",
"private": true,
"version": "0.0.6",
"version": "0.0.5",
"type": "module",
"scripts": {
"dev": "vite",
@@ -1,26 +1,5 @@
# @llamaindex/next-agent-test
## 0.1.76
### Patch Changes
- llamaindex@0.6.14
## 0.1.75
### Patch Changes
- llamaindex@0.6.13
## 0.1.74
### Patch Changes
- Updated dependencies [f7b4e94]
- Updated dependencies [78037a6]
- Updated dependencies [1d9e3b1]
- llamaindex@0.6.12
## 0.1.73
### Patch Changes
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/next-agent-test",
"version": "0.1.76",
"version": "0.1.73",
"private": true,
"scripts": {
"dev": "next dev",
@@ -1,26 +1,5 @@
# test-edge-runtime
## 0.1.75
### Patch Changes
- llamaindex@0.6.14
## 0.1.74
### Patch Changes
- llamaindex@0.6.13
## 0.1.73
### Patch Changes
- Updated dependencies [f7b4e94]
- Updated dependencies [78037a6]
- Updated dependencies [1d9e3b1]
- llamaindex@0.6.12
## 0.1.72
### Patch Changes
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/nextjs-edge-runtime-test",
"version": "0.1.75",
"version": "0.1.72",
"private": true,
"scripts": {
"dev": "next dev",
@@ -1,26 +1,5 @@
# @llamaindex/next-node-runtime
## 0.0.57
### Patch Changes
- llamaindex@0.6.14
## 0.0.56
### Patch Changes
- llamaindex@0.6.13
## 0.0.55
### Patch Changes
- Updated dependencies [f7b4e94]
- Updated dependencies [78037a6]
- Updated dependencies [1d9e3b1]
- llamaindex@0.6.12
## 0.0.54
### Patch Changes
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/next-node-runtime-test",
"version": "0.0.57",
"version": "0.0.54",
"private": true,
"scripts": {
"dev": "next dev",
@@ -1,26 +1,5 @@
# @llamaindex/waku-query-engine-test
## 0.0.76
### Patch Changes
- llamaindex@0.6.14
## 0.0.75
### Patch Changes
- llamaindex@0.6.13
## 0.0.74
### Patch Changes
- Updated dependencies [f7b4e94]
- Updated dependencies [78037a6]
- Updated dependencies [1d9e3b1]
- llamaindex@0.6.12
## 0.0.73
### Patch Changes
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/waku-query-engine-test",
"version": "0.0.76",
"version": "0.0.73",
"type": "module",
"private": true,
"scripts": {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "llamaindex",
"version": "0.6.14",
"version": "0.6.11",
"license": "MIT",
"type": "module",
"keywords": [
-5
View File
@@ -1,8 +1,3 @@
export {
LlamaParseReader,
type Language,
type ResultType,
} from "@llamaindex/cloud/reader";
export * from "@llamaindex/core/agent";
export * from "@llamaindex/core/chat-engine";
export {
@@ -203,10 +203,7 @@ export class VectorStoreIndex extends BaseIndex<IndexDict> {
} = {},
): Promise<VectorStoreIndex> {
args.storageContext =
args.storageContext ??
(await storageContextFromDefaults({
serviceContext: args.serviceContext,
}));
args.storageContext ?? (await storageContextFromDefaults({}));
args.vectorStores = args.vectorStores ?? args.storageContext.vectorStores;
args.docStoreStrategy =
args.docStoreStrategy ??
@@ -5,7 +5,6 @@ import {
import { ModalityType, ObjectType } from "@llamaindex/core/schema";
import { path } from "@llamaindex/env";
import { getImageEmbedModel } from "../internal/settings/image-embed-model.js";
import type { ServiceContext } from "../ServiceContext.js";
import { SimpleVectorStore } from "../vector-store/SimpleVectorStore.js";
import type { VectorStore, VectorStoreByType } from "../vector-store/types.js";
import { SimpleDocumentStore } from "./docStore/SimpleDocumentStore.js";
@@ -26,10 +25,6 @@ type BuilderParams = {
vectorStores: VectorStoreByType;
storeImages: boolean;
persistDir: string;
/**
* @deprecated Please use `Settings` instead
*/
serviceContext?: ServiceContext | undefined;
};
export async function storageContextFromDefaults({
@@ -39,7 +34,6 @@ export async function storageContextFromDefaults({
vectorStores,
storeImages,
persistDir,
serviceContext,
}: Partial<BuilderParams>): Promise<StorageContext> {
vectorStores = vectorStores ?? {};
if (!persistDir) {
@@ -54,7 +48,6 @@ export async function storageContextFromDefaults({
});
}
} else {
const embedModel = serviceContext?.embedModel;
docStore =
docStore ||
(await SimpleDocumentStore.fromPersistDir(persistDir, DEFAULT_NAMESPACE));
@@ -62,8 +55,7 @@ export async function storageContextFromDefaults({
indexStore || (await SimpleIndexStore.fromPersistDir(persistDir));
if (!(ObjectType.TEXT in vectorStores)) {
vectorStores[ModalityType.TEXT] =
vectorStore ??
(await SimpleVectorStore.fromPersistDir(persistDir, embedModel));
vectorStore ?? (await SimpleVectorStore.fromPersistDir(persistDir));
}
if (storeImages && !(ObjectType.IMAGE in vectorStores)) {
vectorStores[ModalityType.IMAGE] = await SimpleVectorStore.fromPersistDir(
@@ -1,6 +1,4 @@
import {
FilterCondition,
FilterOperator,
VectorStoreBase,
type IEmbedModel,
type MetadataFilter,
@@ -200,60 +198,14 @@ export class PineconeVectorStore
}
toPineconeFilter(stdFilters?: MetadataFilters) {
if (!stdFilters) return undefined;
const transformCondition = (
condition: `${FilterCondition}` = "and",
): string => {
if (condition === "and") return "$and";
if (condition === "or") return "$or";
throw new Error(`Filter condition ${condition} not supported`);
};
const transformOperator = (operator: `${FilterOperator}`): string => {
switch (operator) {
case "!=":
return "$ne";
case "==":
return "$eq";
case ">":
return "$gt";
case "<":
return "$lt";
case ">=":
return "$gte";
case "<=":
return "$lte";
case "in":
return "$in";
case "nin":
return "$nin";
default:
throw new Error(`Filter operator ${operator} not supported`);
return stdFilters?.filters?.reduce((carry: any, item: MetadataFilter) => {
// Use MetadataFilter with EQ operator to replace ExactMatchFilter
// TODO: support filter with other operators
if (item.operator === "==") {
carry[item.key] = item.value;
}
};
const convertFilterItem = (filter: MetadataFilter) => {
return {
[filter.key]: {
[transformOperator(filter.operator)]: filter.value,
},
};
};
const convertFilter = (filter: MetadataFilters) => {
const filtersList = filter.filters
.map((f) => convertFilterItem(f))
.filter((f) => Object.keys(f).length > 0);
if (filtersList.length === 0) return undefined;
if (filtersList.length === 1) return filtersList[0];
const condition = transformCondition(filter.condition);
return { [condition]: filtersList };
};
return convertFilter(stdFilters);
return carry;
}, {});
}
textFromResultRow(row: ScoredPineconeRecord<Metadata>): string {
@@ -27,7 +27,7 @@ describe("VectorStoreIndex", () => {
runs: number = 2,
): Promise<Array<number>> => {
const documents = [new Document({ text: "lorem ipsem", id_: "1" })];
const entries: number[] = [];
const entries = [];
for (let i = 0; i < runs; i++) {
await VectorStoreIndex.fromDocuments(documents, {
serviceContext,
@@ -43,7 +43,7 @@ describe("VectorStoreIndex", () => {
test("fromDocuments stores duplicates without a doc store strategy", async () => {
const entries = await testStrategy(DocStoreStrategy.NONE);
expect(entries[0]).toBe(entries[1]);
expect(entries[0]! + 1).toBe(entries[1]);
});
test("fromDocuments ignores duplicates with upserts doc store strategy", async () => {
-6
View File
@@ -1,11 +1,5 @@
# @llamaindex/groq
## 0.0.10
### Patch Changes
- @llamaindex/openai@0.1.11
## 0.0.9
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/groq",
"description": "Groq Adapter for LlamaIndex",
"version": "0.0.10",
"version": "0.0.9",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
-7
View File
@@ -1,12 +1,5 @@
# @llamaindex/ollama
## 0.0.4
### Patch Changes
- Updated dependencies [b17d439]
- @llamaindex/core@0.2.9
## 0.0.3
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/ollama",
"description": "Ollama Adapter for LlamaIndex",
"version": "0.0.4",
"version": "0.0.3",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
-7
View File
@@ -1,12 +1,5 @@
# @llamaindex/openai
## 0.1.11
### Patch Changes
- Updated dependencies [b17d439]
- @llamaindex/core@0.2.9
## 0.1.10
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/openai",
"description": "OpenAI Adapter for LlamaIndex",
"version": "0.1.11",
"version": "0.1.10",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",