mirror of
https://github.com/run-llama/LlamaIndexTS.git
synced 2026-07-01 22:14:03 -04:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7f7d110523 | |||
| 5d5cd44276 | |||
| ed37c645af | |||
| c40adafecc | |||
| 995b465205 | |||
| 8929dcf1dd | |||
| af0b79f1cd | |||
| 1995b38660 | |||
| 001a5159cf | |||
| 9d7d2052e7 | |||
| fd90e25f0e |
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"llamaindex": patch
|
||||
"@llamaindex/llamaindex-test": patch
|
||||
---
|
||||
|
||||
feat: vectorStoreIndex has new option progressCallback
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@llamaindex/anthropic": patch
|
||||
---
|
||||
|
||||
fix: anthropic temperature parameter not respecting value 0
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@llamaindex/google": patch
|
||||
---
|
||||
|
||||
Add latest google models to lib
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@llamaindex/aws": patch
|
||||
"@llamaindex/doc": patch
|
||||
---
|
||||
|
||||
Addition of APAC_ANTHROPIC_CLAUDE_4_SONNET type/record in @llamaindex/aws for APAC support for claude 4 sonnet per issue 2184.
|
||||
@@ -1,5 +1,16 @@
|
||||
# @llamaindex/doc
|
||||
|
||||
## 0.2.53
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1995b38]
|
||||
- Updated dependencies [001a515]
|
||||
- Updated dependencies [9d7d205]
|
||||
- @llamaindex/workflow@1.1.22
|
||||
- @llamaindex/openai@0.4.18
|
||||
- llamaindex@0.11.28
|
||||
|
||||
## 0.2.52
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/doc",
|
||||
"version": "0.2.52",
|
||||
"version": "0.2.53",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"postinstall": "fumadocs-mdx",
|
||||
|
||||
@@ -115,6 +115,7 @@ EU_AMAZON_NOVA_MICRO_1 = "eu.amazon.nova-micro-v1:0";
|
||||
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_4_SONNET = "apac.anthropic.claude-sonnet-4-20250514-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";
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
---
|
||||
title: Custom Model Per Request
|
||||
---
|
||||
|
||||
There are scenarios, such as the case of a multi-tenant backend API, where it may be required to handle each request with a custom model.
|
||||
|
||||
In such a scenario, modifying the `Settings` object directly as follows is not recommended:
|
||||
|
||||
```typescript
|
||||
import { Settings } from 'llamaindex';
|
||||
import { OpenAIEmbedding } from '@llamaindex/embeddings-openai';
|
||||
|
||||
Settings.embedModel = new OpenAIEmbedding({ apiKey: 'CLIENT_API_KEY' });
|
||||
Settings.llm = openai({ apiKey: key, model: 'gpt-4o' })
|
||||
```
|
||||
|
||||
Setting `llm` and `embedModel` directly will lead to unpredictable responses, since `Settings` is global and mutable.
|
||||
This can lead to race conditions, as each request modifies `Settings.embedModel` or `Settings.llm`.
|
||||
|
||||
The recommended approach is to use `Settings.withEmbedModel` or `Settings.withLLM` as follows:
|
||||
|
||||
```typescript
|
||||
const embedModel = new OpenAIEmbedding({
|
||||
apiKey: process.env.OPENAI_API_KEY,
|
||||
});
|
||||
const llm = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
|
||||
|
||||
const llmResponse = await Settings.withEmbedModel(embedModel, async () => {
|
||||
return Settings.withLLM(llm, async () => {
|
||||
const path = "node_modules/llamaindex/examples/abramov.txt";
|
||||
const essay = await fs.readFile(path, "utf-8");
|
||||
// Create Document object with essay
|
||||
const document = new Document({ text: essay, id_: path });
|
||||
// Split text and create embeddings. Store them in a VectorStoreIndex
|
||||
const index = await VectorStoreIndex.fromDocuments([document]);
|
||||
// Query the index
|
||||
const queryEngine = index.asQueryEngine();
|
||||
const { message, sourceNodes } = await queryEngine.query({
|
||||
query: "What did the author do in college?",
|
||||
});
|
||||
// Return response with sources
|
||||
return message.content;
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
The full example can be found [here](https://github.com/run-llama/LlamaIndexTS/tree/main/examples/local-settings).
|
||||
@@ -7,6 +7,7 @@
|
||||
"workflows",
|
||||
"local_llm",
|
||||
"chatbot",
|
||||
"structured_data_extraction"
|
||||
"structured_data_extraction",
|
||||
"custom_model_per_request"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# @llamaindex/cloudflare-worker-agent-test
|
||||
|
||||
## 0.0.189
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.28
|
||||
|
||||
## 0.0.188
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/cloudflare-worker-agent-test",
|
||||
"version": "0.0.188",
|
||||
"version": "0.0.189",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.8.3",
|
||||
"vite": "^6.3.3",
|
||||
"vite": "^6.3.6",
|
||||
"vite-plugin-wasm": "^3.4.1"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# @llamaindex/next-agent-test
|
||||
|
||||
## 0.1.189
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.28
|
||||
|
||||
## 0.1.188
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/next-agent-test",
|
||||
"version": "0.1.188",
|
||||
"version": "0.1.189",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# test-edge-runtime
|
||||
|
||||
## 0.1.188
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.28
|
||||
|
||||
## 0.1.187
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/nextjs-edge-runtime-test",
|
||||
"version": "0.1.187",
|
||||
"version": "0.1.188",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
# @llamaindex/next-node-runtime
|
||||
|
||||
## 0.1.60
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.28
|
||||
- @llamaindex/huggingface@0.1.28
|
||||
|
||||
## 0.1.59
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/next-node-runtime-test",
|
||||
"version": "0.1.59",
|
||||
"version": "0.1.60",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# vite-import-llamaindex
|
||||
|
||||
## 0.0.55
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.28
|
||||
|
||||
## 0.0.54
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
{
|
||||
"name": "vite-import-llamaindex",
|
||||
"private": true,
|
||||
"version": "0.0.54",
|
||||
"version": "0.0.55",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "vite build",
|
||||
"size-limit": "size-limit"
|
||||
"size-limit": "size-limit",
|
||||
"ci-build": "pnpm -C ../../../ build && vite build"
|
||||
},
|
||||
"size-limit": [
|
||||
{
|
||||
@@ -16,7 +17,7 @@
|
||||
"@size-limit/preset-big-lib": "^11.1.6",
|
||||
"size-limit": "^11.1.6",
|
||||
"typescript": "^5.8.3",
|
||||
"vite": "^6.3.3"
|
||||
"vite": "^6.3.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"llamaindex": "workspace:*"
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# @llamaindex/waku-query-engine-test
|
||||
|
||||
## 0.0.189
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.28
|
||||
|
||||
## 0.0.188
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/waku-query-engine-test",
|
||||
"version": "0.0.188",
|
||||
"version": "0.0.189",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
||||
@@ -1,5 +1,28 @@
|
||||
# examples
|
||||
|
||||
## 0.3.40
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1995b38]
|
||||
- Updated dependencies [001a515]
|
||||
- Updated dependencies [9d7d205]
|
||||
- @llamaindex/workflow@1.1.22
|
||||
- @llamaindex/openai@0.4.18
|
||||
- llamaindex@0.11.28
|
||||
- @llamaindex/clip@0.0.74
|
||||
- @llamaindex/deepinfra@0.0.74
|
||||
- @llamaindex/deepseek@0.0.36
|
||||
- @llamaindex/fireworks@0.0.34
|
||||
- @llamaindex/groq@0.0.90
|
||||
- @llamaindex/huggingface@0.1.28
|
||||
- @llamaindex/jinaai@0.0.34
|
||||
- @llamaindex/perplexity@0.0.31
|
||||
- @llamaindex/azure@0.1.35
|
||||
- @llamaindex/together@0.0.34
|
||||
- @llamaindex/vllm@0.0.60
|
||||
- @llamaindex/xai@0.0.21
|
||||
|
||||
## 0.3.39
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -22,7 +22,7 @@ const { withState, getContext } = createStatefulMiddleware(() => ({
|
||||
const jokeFlow = withState(createWorkflow());
|
||||
|
||||
// Define handlers for each step
|
||||
jokeFlow.handle([startEvent], async (event) => {
|
||||
jokeFlow.handle([startEvent], async (context, event) => {
|
||||
// Prompt the LLM to write a joke
|
||||
const prompt = `Write your best joke about ${event.data}. Write the joke between <joke> and </joke> tags.`;
|
||||
const response = await llm.complete({ prompt });
|
||||
@@ -34,7 +34,7 @@ jokeFlow.handle([startEvent], async (event) => {
|
||||
return jokeEvent.with({ joke: joke });
|
||||
});
|
||||
|
||||
jokeFlow.handle([jokeEvent], async (event) => {
|
||||
jokeFlow.handle([jokeEvent], async (context, event) => {
|
||||
// Prompt the LLM to critique the joke
|
||||
const prompt = `Give a thorough critique of the following joke. If the joke needs improvement, put "IMPROVE" somewhere in the critique: ${event.data.joke}`;
|
||||
const response = await llm.complete({ prompt });
|
||||
@@ -50,9 +50,9 @@ jokeFlow.handle([jokeEvent], async (event) => {
|
||||
return resultEvent.with({ joke: event.data.joke, critique: response.text });
|
||||
});
|
||||
|
||||
jokeFlow.handle([critiqueEvent], async (event) => {
|
||||
jokeFlow.handle([critiqueEvent], async (context, event) => {
|
||||
// Keep track of the number of iterations
|
||||
const state = getContext().state;
|
||||
const state = context.state;
|
||||
state.numIterations++;
|
||||
|
||||
// Write a new joke based on the previous joke and critique
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
import { OpenAI, OpenAIEmbedding } from "@llamaindex/openai";
|
||||
import express, { Request, Response } from "express";
|
||||
import fs from "fs/promises";
|
||||
import { Document, Settings, VectorStoreIndex } from "llamaindex";
|
||||
|
||||
const app = express();
|
||||
const port = 3000;
|
||||
|
||||
app.get("/default", async (req: Request, res: Response) => {
|
||||
const embedModel = new OpenAIEmbedding({
|
||||
apiKey: process.env.OPENAI_API_KEY,
|
||||
});
|
||||
const llm = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
|
||||
|
||||
const llmResponse = await Settings.withEmbedModel(embedModel, async () => {
|
||||
return Settings.withLLM(llm, async () => {
|
||||
const path = "node_modules/llamaindex/examples/abramov.txt";
|
||||
const essay = await fs.readFile(path, "utf-8");
|
||||
// Create Document object with essay
|
||||
const document = new Document({ text: essay, id_: path });
|
||||
// Split text and create embeddings. Store them in a VectorStoreIndex
|
||||
const index = await VectorStoreIndex.fromDocuments([document]);
|
||||
// Query the index
|
||||
const queryEngine = index.asQueryEngine();
|
||||
const { message, sourceNodes } = await queryEngine.query({
|
||||
query: "What did the author do in college?",
|
||||
});
|
||||
// Return response with sources
|
||||
return message.content;
|
||||
});
|
||||
});
|
||||
// res.send(message.content)
|
||||
res.send(llmResponse);
|
||||
});
|
||||
|
||||
app.get("/custom", async (req: Request, res: Response) => {
|
||||
const embedModel = new OpenAIEmbedding({
|
||||
apiKey: process.env.OPENAI_API_KEY,
|
||||
model: "text-embedding-3-small",
|
||||
});
|
||||
const llm = new OpenAI({
|
||||
apiKey: process.env.OPENAI_API_KEY,
|
||||
model: "gpt-3.5-turbo",
|
||||
});
|
||||
|
||||
const llmResponse = await Settings.withEmbedModel(embedModel, async () => {
|
||||
return Settings.withLLM(llm, async () => {
|
||||
const path = "node_modules/llamaindex/examples/abramov.txt";
|
||||
const essay = await fs.readFile(path, "utf-8");
|
||||
// Create Document object with essay
|
||||
const document = new Document({ text: essay, id_: path });
|
||||
// Split text and create embeddings. Store them in a VectorStoreIndex
|
||||
const index = await VectorStoreIndex.fromDocuments([document]);
|
||||
// Query the index
|
||||
const queryEngine = index.asQueryEngine();
|
||||
const { message, sourceNodes } = await queryEngine.query({
|
||||
query: "What did the author do in college?",
|
||||
});
|
||||
// Return response with sources
|
||||
return message.content;
|
||||
});
|
||||
});
|
||||
// res.send(message.content)
|
||||
res.send(llmResponse);
|
||||
});
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Example app listening on port ${port}`);
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "local-settings",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"private": "true",
|
||||
"scripts": {
|
||||
"test": "echo \"No tests for example package\""
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"description": "",
|
||||
"devDependencies": {
|
||||
"@types/express": "^5.0.3",
|
||||
"typescript": "^5.9.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@llamaindex/openai": "^0.4.16",
|
||||
"express": "^5.1.0",
|
||||
"llamaindex": "^0.11.26"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"moduleResolution": "node",
|
||||
"types": ["node", "express"]
|
||||
},
|
||||
"include": ["*.ts"]
|
||||
}
|
||||
+17
-16
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/examples",
|
||||
"version": "0.3.39",
|
||||
"version": "0.3.40",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
@@ -14,24 +14,24 @@
|
||||
"@llamaindex/anthropic": "^0.3.23",
|
||||
"@llamaindex/assemblyai": "^0.1.19",
|
||||
"@llamaindex/astra": "^0.0.34",
|
||||
"@llamaindex/azure": "^0.1.34",
|
||||
"@llamaindex/azure": "^0.1.35",
|
||||
"@llamaindex/bm25-retriever": "^0.0.9",
|
||||
"@llamaindex/chroma": "^0.0.34",
|
||||
"@llamaindex/clip": "^0.0.73",
|
||||
"@llamaindex/clip": "^0.0.74",
|
||||
"@llamaindex/cloud": "^4.1.2",
|
||||
"@llamaindex/cohere": "^0.0.34",
|
||||
"@llamaindex/core": "^0.6.20",
|
||||
"@llamaindex/deepinfra": "^0.0.73",
|
||||
"@llamaindex/deepseek": "^0.0.35",
|
||||
"@llamaindex/deepinfra": "^0.0.74",
|
||||
"@llamaindex/deepseek": "^0.0.36",
|
||||
"@llamaindex/discord": "^0.1.19",
|
||||
"@llamaindex/elastic-search": "^0.1.20",
|
||||
"@llamaindex/env": "^0.1.30",
|
||||
"@llamaindex/firestore": "^1.0.27",
|
||||
"@llamaindex/fireworks": "^0.0.33",
|
||||
"@llamaindex/fireworks": "^0.0.34",
|
||||
"@llamaindex/google": "^0.3.20",
|
||||
"@llamaindex/groq": "^0.0.89",
|
||||
"@llamaindex/huggingface": "^0.1.27",
|
||||
"@llamaindex/jinaai": "^0.0.33",
|
||||
"@llamaindex/groq": "^0.0.90",
|
||||
"@llamaindex/huggingface": "^0.1.28",
|
||||
"@llamaindex/jinaai": "^0.0.34",
|
||||
"@llamaindex/milvus": "^0.1.29",
|
||||
"@llamaindex/mistral": "^0.1.20",
|
||||
"@llamaindex/mixedbread": "^0.0.34",
|
||||
@@ -39,8 +39,8 @@
|
||||
"@llamaindex/node-parser": "^2.0.20",
|
||||
"@llamaindex/notion": "^0.1.19",
|
||||
"@llamaindex/ollama": "^0.1.21",
|
||||
"@llamaindex/openai": "^0.4.17",
|
||||
"@llamaindex/perplexity": "^0.0.30",
|
||||
"@llamaindex/openai": "^0.4.18",
|
||||
"@llamaindex/perplexity": "^0.0.31",
|
||||
"@llamaindex/pinecone": "^0.1.20",
|
||||
"@llamaindex/portkey-ai": "^0.0.62",
|
||||
"@llamaindex/postgres": "^0.0.63",
|
||||
@@ -48,15 +48,15 @@
|
||||
"@llamaindex/readers": "^3.1.19",
|
||||
"@llamaindex/replicate": "^0.0.62",
|
||||
"@llamaindex/supabase": "^0.1.21",
|
||||
"@llamaindex/together": "^0.0.33",
|
||||
"@llamaindex/together": "^0.0.34",
|
||||
"@llamaindex/tools": "^0.1.10",
|
||||
"@llamaindex/upstash": "^0.0.34",
|
||||
"@llamaindex/vercel": "^0.1.20",
|
||||
"@llamaindex/vllm": "^0.0.59",
|
||||
"@llamaindex/vllm": "^0.0.60",
|
||||
"@llamaindex/voyage-ai": "^1.0.26",
|
||||
"@llamaindex/weaviate": "^0.0.35",
|
||||
"@llamaindex/workflow": "^1.1.21",
|
||||
"@llamaindex/xai": "^0.0.20",
|
||||
"@llamaindex/workflow": "^1.1.22",
|
||||
"@llamaindex/xai": "^0.0.21",
|
||||
"@notionhq/client": "^4.0.0",
|
||||
"@pinecone-database/pinecone": "^4.0.0",
|
||||
"@vercel/postgres": "^0.10.0",
|
||||
@@ -65,13 +65,14 @@
|
||||
"commander": "^12.1.0",
|
||||
"dotenv": "^17.2.0",
|
||||
"js-tiktoken": "^1.0.14",
|
||||
"llamaindex": "^0.11.27",
|
||||
"llamaindex": "^0.11.28",
|
||||
"mongodb": "6.7.0",
|
||||
"postgres": "^3.4.4",
|
||||
"wikipedia": "^2.1.2",
|
||||
"zod": "^3.25.76"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/express": "^5.0.3",
|
||||
"@types/node": "^24.0.13",
|
||||
"tsx": "^4.20.3",
|
||||
"typescript": "^5.8.3"
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# @llamaindex/autotool
|
||||
|
||||
## 8.0.28
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.28
|
||||
|
||||
## 8.0.27
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
# @llamaindex/autotool-01-node-example
|
||||
|
||||
## 0.0.136
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.28
|
||||
- @llamaindex/autotool@8.0.28
|
||||
|
||||
## 0.0.135
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -13,5 +13,5 @@
|
||||
"scripts": {
|
||||
"start": "node --import tsx --import @llamaindex/autotool/node ./src/index.ts"
|
||||
},
|
||||
"version": "0.0.135"
|
||||
"version": "0.0.136"
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"url": "git+https://github.com/run-llama/LlamaIndexTS.git",
|
||||
"directory": "packages/autotool"
|
||||
},
|
||||
"version": "8.0.27",
|
||||
"version": "8.0.28",
|
||||
"description": "auto transpile your JS function to LLM Agent compatible",
|
||||
"files": [
|
||||
"dist",
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# @llamaindex/experimental
|
||||
|
||||
## 0.0.205
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.28
|
||||
|
||||
## 0.0.204
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/experimental",
|
||||
"description": "Experimental package for LlamaIndexTS",
|
||||
"version": "0.0.204",
|
||||
"version": "0.0.205",
|
||||
"type": "module",
|
||||
"types": "dist/type/index.d.ts",
|
||||
"main": "dist/cjs/index.js",
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
# llamaindex
|
||||
|
||||
## 0.11.28
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1995b38]
|
||||
- @llamaindex/workflow@1.1.22
|
||||
|
||||
## 0.11.27
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "llamaindex",
|
||||
"version": "0.11.27",
|
||||
"version": "0.11.28",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"keywords": [
|
||||
|
||||
@@ -54,6 +54,7 @@ export interface VectorIndexOptions extends IndexStructOptions {
|
||||
storageContext?: StorageContext | undefined;
|
||||
vectorStores?: VectorStoreByType | undefined;
|
||||
logProgress?: boolean | undefined;
|
||||
progressCallback?: ((progress: number, total: number) => void) | undefined;
|
||||
}
|
||||
|
||||
export interface VectorIndexConstructorProps extends BaseIndexInit<IndexDict> {
|
||||
@@ -121,6 +122,7 @@ export class VectorStoreIndex extends BaseIndex<IndexDict> {
|
||||
// If nodes are passed in, then we need to update the index
|
||||
await index.buildIndexFromNodes(options.nodes, {
|
||||
logProgress: options.logProgress,
|
||||
progressCallback: options.progressCallback,
|
||||
});
|
||||
}
|
||||
return index;
|
||||
@@ -170,7 +172,12 @@ export class VectorStoreIndex extends BaseIndex<IndexDict> {
|
||||
*/
|
||||
async getNodeEmbeddingResults(
|
||||
nodes: BaseNode[],
|
||||
options?: { logProgress?: boolean | undefined },
|
||||
options?: {
|
||||
logProgress?: boolean | undefined;
|
||||
progressCallback?:
|
||||
| ((progress: number, total: number) => void)
|
||||
| undefined;
|
||||
},
|
||||
): Promise<BaseNode[]> {
|
||||
const nodeMap = splitNodesByType(nodes);
|
||||
for (const type in nodeMap) {
|
||||
@@ -180,6 +187,7 @@ export class VectorStoreIndex extends BaseIndex<IndexDict> {
|
||||
if (embedModel && nodes) {
|
||||
await embedModel(nodes, {
|
||||
logProgress: options?.logProgress,
|
||||
progressCallback: options?.progressCallback,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -193,7 +201,12 @@ export class VectorStoreIndex extends BaseIndex<IndexDict> {
|
||||
*/
|
||||
async buildIndexFromNodes(
|
||||
nodes: BaseNode[],
|
||||
options?: { logProgress?: boolean | undefined },
|
||||
options?: {
|
||||
logProgress?: boolean | undefined;
|
||||
progressCallback?:
|
||||
| ((progress: number, total: number) => void)
|
||||
| undefined;
|
||||
},
|
||||
) {
|
||||
await this.insertNodes(nodes, options);
|
||||
}
|
||||
@@ -361,7 +374,12 @@ export class VectorStoreIndex extends BaseIndex<IndexDict> {
|
||||
|
||||
async insertNodes(
|
||||
nodes: BaseNode[],
|
||||
options?: { logProgress?: boolean | undefined },
|
||||
options?: {
|
||||
logProgress?: boolean | undefined;
|
||||
progressCallback?:
|
||||
| ((progress: number, total: number) => void)
|
||||
| undefined;
|
||||
},
|
||||
): Promise<void> {
|
||||
if (!nodes || nodes.length === 0) {
|
||||
return;
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
# @llamaindex/core-test
|
||||
|
||||
## 0.1.19
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [001a515]
|
||||
- Updated dependencies [9d7d205]
|
||||
- @llamaindex/openai@0.4.18
|
||||
|
||||
## 0.1.18
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -89,4 +89,42 @@ describe("[VectorStoreIndex] use embedding model", () => {
|
||||
expect(customSpy).toHaveBeenCalled();
|
||||
expect(settingsSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe("[VectorStoreIndex] call progressCallback", () => {
|
||||
it("should call progressCallback with correct values", async () => {
|
||||
const documents = Array.from(
|
||||
{ length: 20 },
|
||||
(_, i) => new Document({ text: `This is document ${i + 1}` }),
|
||||
);
|
||||
|
||||
const progressCalls: Array<{ current: number; total: number }> = [];
|
||||
const progressCallback = (current: number, total: number) => {
|
||||
progressCalls.push({ current, total });
|
||||
};
|
||||
|
||||
const embedModel = new OpenAIEmbedding();
|
||||
mockEmbeddingModel(embedModel);
|
||||
const embedSpy = vi.spyOn(embedModel, "getTextEmbeddingsBatch");
|
||||
|
||||
Settings.embedModel = embedModel;
|
||||
const storageContext = await mockStorageContext(testDir, embedModel);
|
||||
|
||||
await VectorStoreIndex.fromDocuments(documents, {
|
||||
storageContext,
|
||||
logProgress: true,
|
||||
progressCallback,
|
||||
});
|
||||
|
||||
// Expect the embedding model to be called
|
||||
expect(embedSpy).toHaveBeenCalled();
|
||||
|
||||
// Verify that progressCallback was called with correct values
|
||||
expect(progressCalls.length).toBeGreaterThan(0);
|
||||
expect(progressCalls[0]).toEqual({ current: 10, total: 20 });
|
||||
expect(progressCalls[progressCalls.length - 1]).toEqual({
|
||||
current: 20,
|
||||
total: 20,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/llamaindex-test",
|
||||
"private": true,
|
||||
"version": "0.1.18",
|
||||
"version": "0.1.19",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "vitest run"
|
||||
|
||||
@@ -179,7 +179,7 @@ export class Anthropic extends ToolCallLLM<
|
||||
constructor(init?: Partial<Anthropic>) {
|
||||
super();
|
||||
this.model = init?.model ?? "claude-3-opus";
|
||||
this.temperature = init?.temperature ?? 1; // default in anthropic is 1
|
||||
this.temperature = init?.temperature != null ? init.temperature : 1; // default in anthropic is 1
|
||||
this.topP = init?.topP;
|
||||
this.maxTokens = init?.maxTokens ?? undefined;
|
||||
|
||||
|
||||
@@ -134,13 +134,14 @@ export const INFERENCE_BEDROCK_MODELS = {
|
||||
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_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_4_SONNET:
|
||||
"apac.anthropic.claude-sonnet-4-20250514-v1:0q",
|
||||
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",
|
||||
@@ -226,6 +227,8 @@ export const INFERENCE_TO_BEDROCK_MAP: Record<
|
||||
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_5_SONNET_V2,
|
||||
[INFERENCE_BEDROCK_MODELS.APAC_ANTHROPIC_CLAUDE_3_7_SONNET]:
|
||||
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_7_SONNET,
|
||||
[INFERENCE_BEDROCK_MODELS.APAC_ANTHROPIC_CLAUDE_4_SONNET]:
|
||||
BEDROCK_MODELS.ANTHROPIC_CLAUDE_4_SONNET,
|
||||
[INFERENCE_BEDROCK_MODELS.APAC_ANTHROPIC_CLAUDE_3_HAIKU]:
|
||||
BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_HAIKU,
|
||||
[INFERENCE_BEDROCK_MODELS.APAC_ANTHROPIC_CLAUDE_3_SONNET]:
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
# @llamaindex/clip
|
||||
|
||||
## 0.0.74
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [001a515]
|
||||
- Updated dependencies [9d7d205]
|
||||
- @llamaindex/openai@0.4.18
|
||||
|
||||
## 0.0.73
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/clip",
|
||||
"description": "Clip Embedding Adapter for LlamaIndex",
|
||||
"version": "0.0.73",
|
||||
"version": "0.0.74",
|
||||
"type": "module",
|
||||
"types": "dist/index.d.ts",
|
||||
"main": "dist/index.cjs",
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
# @llamaindex/deepinfra
|
||||
|
||||
## 0.0.74
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [001a515]
|
||||
- Updated dependencies [9d7d205]
|
||||
- @llamaindex/openai@0.4.18
|
||||
|
||||
## 0.0.73
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/deepinfra",
|
||||
"description": "Deepinfra Adapter for LlamaIndex",
|
||||
"version": "0.0.73",
|
||||
"version": "0.0.74",
|
||||
"type": "module",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
# @llamaindex/deepseek
|
||||
|
||||
## 0.0.36
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [001a515]
|
||||
- Updated dependencies [9d7d205]
|
||||
- @llamaindex/openai@0.4.18
|
||||
|
||||
## 0.0.35
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/deepseek",
|
||||
"description": "DeepSeek Adapter for LlamaIndex",
|
||||
"version": "0.0.35",
|
||||
"version": "0.0.36",
|
||||
"type": "module",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
# @llamaindex/fireworks
|
||||
|
||||
## 0.0.34
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [001a515]
|
||||
- Updated dependencies [9d7d205]
|
||||
- @llamaindex/openai@0.4.18
|
||||
|
||||
## 0.0.33
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/fireworks",
|
||||
"description": "Fireworks Adapter for LlamaIndex",
|
||||
"version": "0.0.33",
|
||||
"version": "0.0.34",
|
||||
"type": "module",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
|
||||
@@ -27,6 +27,9 @@ export enum GEMINI_MODEL {
|
||||
GEMINI_2_5_PRO_PREVIEW = "gemini-2.5-pro-preview-03-25",
|
||||
GEMINI_2_5_PRO_PREVIEW_LATEST = "gemini-2.5-pro-preview-06-05",
|
||||
GEMINI_2_5_FLASH_PREVIEW = "gemini-2.5-flash-preview-05-20",
|
||||
GEMINI_2_5_PRO_LATEST = "gemini-2.5-pro",
|
||||
GEMINI_2_5_FLASH_LATEST = "gemini-2.5-flash",
|
||||
GEMINI_2_5_FLASH_LITE = "gemini-2.5-flash-lite",
|
||||
}
|
||||
|
||||
export const GEMINI_MODEL_INFO_MAP: Record<
|
||||
@@ -54,6 +57,9 @@ export const GEMINI_MODEL_INFO_MAP: Record<
|
||||
[GEMINI_MODEL.GEMINI_2_5_PRO_PREVIEW]: { contextWindow: 10 ** 6 },
|
||||
[GEMINI_MODEL.GEMINI_2_5_PRO_PREVIEW_LATEST]: { contextWindow: 10 ** 6 },
|
||||
[GEMINI_MODEL.GEMINI_2_5_FLASH_PREVIEW]: { contextWindow: 10 ** 6 },
|
||||
[GEMINI_MODEL.GEMINI_2_5_PRO_LATEST]: { contextWindow: 10 ** 6 },
|
||||
[GEMINI_MODEL.GEMINI_2_5_FLASH_LATEST]: { contextWindow: 10 ** 6 },
|
||||
[GEMINI_MODEL.GEMINI_2_5_FLASH_LITE]: { contextWindow: 10 ** 6 },
|
||||
};
|
||||
|
||||
export const SUPPORT_TOOL_CALL_MODELS: GEMINI_MODEL[] = [
|
||||
@@ -73,6 +79,9 @@ export const SUPPORT_TOOL_CALL_MODELS: GEMINI_MODEL[] = [
|
||||
GEMINI_MODEL.GEMINI_2_5_PRO_PREVIEW,
|
||||
GEMINI_MODEL.GEMINI_2_5_PRO_PREVIEW_LATEST,
|
||||
GEMINI_MODEL.GEMINI_2_5_FLASH_PREVIEW,
|
||||
GEMINI_MODEL.GEMINI_2_5_PRO_LATEST,
|
||||
GEMINI_MODEL.GEMINI_2_5_FLASH_LATEST,
|
||||
GEMINI_MODEL.GEMINI_2_5_FLASH_LITE,
|
||||
];
|
||||
|
||||
export const DEFAULT_GEMINI_PARAMS = {
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
# @llamaindex/groq
|
||||
|
||||
## 0.0.90
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [001a515]
|
||||
- Updated dependencies [9d7d205]
|
||||
- @llamaindex/openai@0.4.18
|
||||
|
||||
## 0.0.89
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/groq",
|
||||
"description": "Groq Adapter for LlamaIndex",
|
||||
"version": "0.0.89",
|
||||
"version": "0.0.90",
|
||||
"type": "module",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
# @llamaindex/huggingface
|
||||
|
||||
## 0.1.28
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [001a515]
|
||||
- Updated dependencies [9d7d205]
|
||||
- @llamaindex/openai@0.4.18
|
||||
|
||||
## 0.1.27
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/huggingface",
|
||||
"description": "Huggingface Adapter for LlamaIndex",
|
||||
"version": "0.1.27",
|
||||
"version": "0.1.28",
|
||||
"type": "module",
|
||||
"types": "dist/index.d.ts",
|
||||
"main": "dist/index.cjs",
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
# @llamaindex/jinaai
|
||||
|
||||
## 0.0.34
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [001a515]
|
||||
- Updated dependencies [9d7d205]
|
||||
- @llamaindex/openai@0.4.18
|
||||
|
||||
## 0.0.33
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/jinaai",
|
||||
"description": "JinaAI Adapter for LlamaIndex",
|
||||
"version": "0.0.33",
|
||||
"version": "0.0.34",
|
||||
"type": "module",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
# @llamaindex/openai
|
||||
|
||||
## 0.4.18
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 001a515: chore: add minimal reasoning effort for gpt5
|
||||
- 9d7d205: fix: fix the problem that the usage field in the streaming response was not handled correctly
|
||||
|
||||
## 0.4.17
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/openai",
|
||||
"description": "OpenAI Adapter for LlamaIndex",
|
||||
"version": "0.4.17",
|
||||
"version": "0.4.18",
|
||||
"type": "module",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
|
||||
@@ -40,6 +40,7 @@ import { OpenAILive } from "./live.js";
|
||||
import {
|
||||
ALL_AVAILABLE_OPENAI_MODELS,
|
||||
isFunctionCallingModel,
|
||||
isReasoningEffortSupported,
|
||||
isReasoningModel,
|
||||
isTemperatureSupported,
|
||||
type LLMInstance,
|
||||
@@ -54,7 +55,7 @@ export class OpenAI extends ToolCallLLM<OpenAIAdditionalChatOptions> {
|
||||
// string & {} is a hack to allow any string, but still give autocomplete
|
||||
| (string & {});
|
||||
temperature: number;
|
||||
reasoningEffort?: "low" | "medium" | "high" | undefined;
|
||||
reasoningEffort?: "low" | "medium" | "high" | "minimal" | undefined;
|
||||
topP: number;
|
||||
maxTokens?: number | undefined;
|
||||
additionalChatOptions?: OpenAIAdditionalChatOptions | undefined;
|
||||
@@ -90,9 +91,11 @@ export class OpenAI extends ToolCallLLM<OpenAIAdditionalChatOptions> {
|
||||
|
||||
this.model = init?.model ?? "gpt-4o";
|
||||
this.temperature = init?.temperature ?? 0.1;
|
||||
this.reasoningEffort = isReasoningModel(this.model)
|
||||
? init?.reasoningEffort
|
||||
: undefined;
|
||||
this.reasoningEffort =
|
||||
isReasoningModel(this.model) &&
|
||||
isReasoningEffortSupported(this.model, init?.reasoningEffort)
|
||||
? init?.reasoningEffort
|
||||
: undefined;
|
||||
this.topP = init?.topP ?? 1;
|
||||
this.maxTokens = init?.maxTokens ?? undefined;
|
||||
|
||||
@@ -370,25 +373,18 @@ export class OpenAI extends ToolCallLLM<OpenAIAdditionalChatOptions> {
|
||||
let currentToolCall: PartialToolCall | null = null;
|
||||
const toolCallMap = new Map<string, PartialToolCall>();
|
||||
for await (const part of stream) {
|
||||
if (part.choices.length === 0) {
|
||||
const choice = part.choices && part.choices[0];
|
||||
const hasValidContent =
|
||||
choice?.delta?.content ||
|
||||
choice?.delta?.tool_calls ||
|
||||
choice?.finish_reason;
|
||||
|
||||
if (!hasValidContent) {
|
||||
if (part.usage) {
|
||||
yield {
|
||||
raw: part,
|
||||
delta: "",
|
||||
};
|
||||
yield { raw: part, delta: "" };
|
||||
}
|
||||
continue;
|
||||
}
|
||||
const choice = part.choices[0]!;
|
||||
// skip parts that don't have any content
|
||||
if (
|
||||
!(
|
||||
choice.delta?.content ||
|
||||
choice.delta?.tool_calls ||
|
||||
choice.finish_reason
|
||||
)
|
||||
)
|
||||
continue;
|
||||
|
||||
let shouldEmitToolCall: PartialToolCall | null = null;
|
||||
if (
|
||||
|
||||
@@ -187,6 +187,16 @@ export function isReasoningModel(model: ChatModel | string): boolean {
|
||||
return isO1 || isO3 || isO4 || isGPT5;
|
||||
}
|
||||
|
||||
export function isReasoningEffortSupported(
|
||||
model: ChatModel | string,
|
||||
effort: string | undefined,
|
||||
): boolean {
|
||||
const supportedReasoningEffort = ["low", "medium", "high", undefined];
|
||||
return model.startsWith("gpt-5")
|
||||
? [...supportedReasoningEffort, "minimal"].includes(effort)
|
||||
: supportedReasoningEffort.includes(effort);
|
||||
}
|
||||
|
||||
export function isTemperatureSupported(model: ChatModel | string): boolean {
|
||||
return !model.startsWith("o3") && !model.startsWith("o4");
|
||||
}
|
||||
|
||||
@@ -283,4 +283,100 @@ describe("OpenAI streamChat", () => {
|
||||
expect(chunks[0].options).toEqual({});
|
||||
expect(chunks[0].delta).toBe("");
|
||||
});
|
||||
|
||||
it("should handle part with undefined choices", async () => {
|
||||
// Create a mock stream that yields a part without choices
|
||||
const mockStream = async function* () {
|
||||
yield {
|
||||
// No choices property defined
|
||||
usage: {
|
||||
prompt_tokens: 10,
|
||||
completion_tokens: 5,
|
||||
total_tokens: 15,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
// Mock the OpenAI session and chat completions
|
||||
const mockSession = {
|
||||
chat: {
|
||||
completions: {
|
||||
create: vi.fn().mockResolvedValue(mockStream()),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const openai = new OpenAI({
|
||||
model: "gpt-4o-mini",
|
||||
apiKey: "test-key",
|
||||
// @ts-expect-error: mockSession is a mock object for testing purposes
|
||||
session: mockSession,
|
||||
});
|
||||
|
||||
// @ts-expect-error accessing protected method
|
||||
const stream = openai.streamChat({
|
||||
messages: [{ role: "user" as const, content: "Hello" }],
|
||||
stream: true,
|
||||
});
|
||||
|
||||
const chunks: ChatResponseChunk[] = [];
|
||||
for await (const chunk of stream) {
|
||||
chunks.push(chunk);
|
||||
}
|
||||
|
||||
expect(chunks).toHaveLength(1);
|
||||
expect(chunks[0].delta).toBe("");
|
||||
expect(chunks[0].raw).toHaveProperty("usage");
|
||||
});
|
||||
|
||||
it("should handle part with invalid content", async () => {
|
||||
const mockStream = async function* () {
|
||||
yield {
|
||||
choices: [
|
||||
{
|
||||
delta: {
|
||||
role: "assistant",
|
||||
content: "",
|
||||
},
|
||||
},
|
||||
],
|
||||
usage: {
|
||||
prompt_tokens: 10,
|
||||
completion_tokens: 5,
|
||||
total_tokens: 15,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
// Mock the OpenAI session and chat completions
|
||||
const mockSession = {
|
||||
chat: {
|
||||
completions: {
|
||||
create: vi.fn().mockResolvedValue(mockStream()),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const openai = new OpenAI({
|
||||
model: "gpt-4o-mini",
|
||||
apiKey: "test-key",
|
||||
// @ts-expect-error: mockSession is a mock object for testing purposes
|
||||
session: mockSession,
|
||||
});
|
||||
|
||||
// @ts-expect-error accessing protected method
|
||||
const stream = openai.streamChat({
|
||||
messages: [{ role: "user" as const, content: "Hello" }],
|
||||
stream: true,
|
||||
});
|
||||
|
||||
const chunks: ChatResponseChunk[] = [];
|
||||
for await (const chunk of stream) {
|
||||
chunks.push(chunk);
|
||||
}
|
||||
|
||||
expect(chunks).toHaveLength(1);
|
||||
expect(chunks[0].delta).toBe("");
|
||||
expect(chunks[0].raw).toHaveProperty("usage");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
# @llamaindex/perplexity
|
||||
|
||||
## 0.0.31
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [001a515]
|
||||
- Updated dependencies [9d7d205]
|
||||
- @llamaindex/openai@0.4.18
|
||||
|
||||
## 0.0.30
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/perplexity",
|
||||
"description": "Perplexity Adapter for LlamaIndex",
|
||||
"version": "0.0.30",
|
||||
"version": "0.0.31",
|
||||
"type": "module",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
# @llamaindex/azure
|
||||
|
||||
## 0.1.35
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [001a515]
|
||||
- Updated dependencies [9d7d205]
|
||||
- @llamaindex/openai@0.4.18
|
||||
|
||||
## 0.1.34
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/azure",
|
||||
"description": "Azure Storage for LlamaIndex",
|
||||
"version": "0.1.34",
|
||||
"version": "0.1.35",
|
||||
"type": "module",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
# @llamaindex/together
|
||||
|
||||
## 0.0.34
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [001a515]
|
||||
- Updated dependencies [9d7d205]
|
||||
- @llamaindex/openai@0.4.18
|
||||
|
||||
## 0.0.33
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/together",
|
||||
"description": "Together Adapter for LlamaIndex",
|
||||
"version": "0.0.33",
|
||||
"version": "0.0.34",
|
||||
"type": "module",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
# @llamaindex/vllm
|
||||
|
||||
## 0.0.60
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [001a515]
|
||||
- Updated dependencies [9d7d205]
|
||||
- @llamaindex/openai@0.4.18
|
||||
|
||||
## 0.0.59
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/vllm",
|
||||
"description": "vLLM Adapter for LlamaIndex",
|
||||
"version": "0.0.59",
|
||||
"version": "0.0.60",
|
||||
"type": "module",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
# @llamaindex/xai
|
||||
|
||||
## 0.0.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [001a515]
|
||||
- Updated dependencies [9d7d205]
|
||||
- @llamaindex/openai@0.4.18
|
||||
|
||||
## 0.0.20
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/xai",
|
||||
"description": "XAI Adapter for LlamaIndex",
|
||||
"version": "0.0.20",
|
||||
"version": "0.0.21",
|
||||
"type": "module",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# @llamaindex/workflow
|
||||
|
||||
## 1.1.22
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 1995b38: bump @llamaindex/workflow-core in workflow package
|
||||
|
||||
## 1.1.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/workflow",
|
||||
"description": "Workflow API",
|
||||
"version": "1.1.21",
|
||||
"version": "1.1.22",
|
||||
"type": "module",
|
||||
"types": "dist/index.d.ts",
|
||||
"module": "dist/index.js",
|
||||
@@ -49,6 +49,6 @@
|
||||
"zod-to-json-schema": "^3.24.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"@llamaindex/workflow-core": "^1.0.0"
|
||||
"@llamaindex/workflow-core": "^1.3.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { getContext, type WorkflowEventData } from "@llamaindex/workflow-core";
|
||||
import {
|
||||
type WorkflowContext,
|
||||
type WorkflowEventData,
|
||||
} from "@llamaindex/workflow-core";
|
||||
import {
|
||||
AgentWorkflow,
|
||||
startAgentEvent,
|
||||
@@ -71,9 +74,10 @@ function createWorkflowForStepHandler(
|
||||
export const agentHandler = (
|
||||
params: Omit<StepHandlerParams, "workflowContext">,
|
||||
) => {
|
||||
return async (event: WorkflowEventData<unknown>) => {
|
||||
const context = getContext();
|
||||
|
||||
return async (
|
||||
context: WorkflowContext,
|
||||
event: WorkflowEventData<unknown>,
|
||||
) => {
|
||||
const workflow = createWorkflowForStepHandler({
|
||||
...params,
|
||||
workflowContext: context,
|
||||
|
||||
@@ -8,7 +8,6 @@ import { stringifyJSONToMessageContent } from "@llamaindex/core/utils";
|
||||
import { consoleLogger, emptyLogger, type Logger } from "@llamaindex/env";
|
||||
import {
|
||||
createWorkflow,
|
||||
getContext,
|
||||
workflowEvent,
|
||||
type Handler,
|
||||
type Workflow,
|
||||
@@ -16,7 +15,10 @@ import {
|
||||
type WorkflowEvent,
|
||||
type WorkflowEventData,
|
||||
} from "@llamaindex/workflow-core";
|
||||
import { createStatefulMiddleware } from "@llamaindex/workflow-core/middleware/state";
|
||||
import {
|
||||
createStatefulMiddleware,
|
||||
type StatefulContext,
|
||||
} from "@llamaindex/workflow-core/middleware/state";
|
||||
import { z } from "zod";
|
||||
import type { AgentWorkflowState, BaseWorkflowAgent } from "./base";
|
||||
import {
|
||||
@@ -339,9 +341,10 @@ export class AgentWorkflow implements Workflow {
|
||||
}
|
||||
|
||||
private handleInputStep = async (
|
||||
context: StatefulContext<AgentWorkflowState>,
|
||||
event: WorkflowEventData<AgentInputData>,
|
||||
) => {
|
||||
const { state } = this.stateful.getContext();
|
||||
const { state } = context;
|
||||
const { userInput, chatHistory } = event.data;
|
||||
const memory = state.memory;
|
||||
if (chatHistory) {
|
||||
@@ -375,7 +378,10 @@ export class AgentWorkflow implements Workflow {
|
||||
});
|
||||
};
|
||||
|
||||
private setupAgent = async (event: WorkflowEventData<AgentInput>) => {
|
||||
private setupAgent = async (
|
||||
context: StatefulContext<AgentWorkflowState>,
|
||||
event: WorkflowEventData<AgentInput>,
|
||||
) => {
|
||||
const currentAgentName = event.data.currentAgentName;
|
||||
const agent = this.agents.get(currentAgentName);
|
||||
if (!agent) {
|
||||
@@ -396,16 +402,19 @@ export class AgentWorkflow implements Workflow {
|
||||
});
|
||||
};
|
||||
|
||||
private runAgentStep = async (event: WorkflowEventData<AgentSetup>) => {
|
||||
const { sendEvent } = this.stateful.getContext();
|
||||
private runAgentStep = async (
|
||||
context: StatefulContext<AgentWorkflowState>,
|
||||
event: WorkflowEventData<AgentSetup>,
|
||||
) => {
|
||||
const { sendEvent } = context;
|
||||
const agent = this.agents.get(event.data.currentAgentName);
|
||||
if (!agent) {
|
||||
throw new Error("No valid agent found");
|
||||
}
|
||||
|
||||
const output = await agent.takeStep(
|
||||
this.stateful.getContext(),
|
||||
this.stateful.getContext().state,
|
||||
context,
|
||||
context.state,
|
||||
event.data.input,
|
||||
agent.tools,
|
||||
);
|
||||
@@ -421,7 +430,10 @@ export class AgentWorkflow implements Workflow {
|
||||
sendEvent(agentOutputEvent.with(output));
|
||||
};
|
||||
|
||||
private parseAgentOutput = async (event: WorkflowEventData<AgentStep>) => {
|
||||
private parseAgentOutput = async (
|
||||
context: StatefulContext<AgentWorkflowState>,
|
||||
event: WorkflowEventData<AgentStep>,
|
||||
) => {
|
||||
const { agentName, response, toolCalls } = event.data;
|
||||
const agent = this.agents.get(agentName);
|
||||
if (!agent) {
|
||||
@@ -442,15 +454,12 @@ export class AgentWorkflow implements Workflow {
|
||||
raw: response,
|
||||
currentAgentName: agentName,
|
||||
};
|
||||
const content = await agent.finalize(
|
||||
this.stateful.getContext().state,
|
||||
agentOutput,
|
||||
);
|
||||
const content = await agent.finalize(context.state, agentOutput);
|
||||
|
||||
return stopAgentEvent.with({
|
||||
message: content.response,
|
||||
result: content.response.content,
|
||||
state: this.stateful.getContext().state,
|
||||
state: context.state,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -460,8 +469,11 @@ export class AgentWorkflow implements Workflow {
|
||||
});
|
||||
};
|
||||
|
||||
private executeToolCalls = async (event: WorkflowEventData<ToolCalls>) => {
|
||||
const { sendEvent } = getContext();
|
||||
private executeToolCalls = async (
|
||||
context: StatefulContext<AgentWorkflowState>,
|
||||
event: WorkflowEventData<ToolCalls>,
|
||||
) => {
|
||||
const { sendEvent } = context;
|
||||
const { agentName, toolCalls } = event.data;
|
||||
const agent = this.agents.get(agentName);
|
||||
if (!agent) {
|
||||
@@ -507,6 +519,7 @@ export class AgentWorkflow implements Workflow {
|
||||
};
|
||||
|
||||
private processToolResults = async (
|
||||
context: StatefulContext<AgentWorkflowState>,
|
||||
event: WorkflowEventData<ToolResults>,
|
||||
) => {
|
||||
const { agentName, results } = event.data;
|
||||
@@ -517,10 +530,7 @@ export class AgentWorkflow implements Workflow {
|
||||
throw new Error(`Agent ${agentName} not found`);
|
||||
}
|
||||
|
||||
await agent.handleToolCallResults(
|
||||
this.stateful.getContext().state,
|
||||
results,
|
||||
);
|
||||
await agent.handleToolCallResults(context.state, results);
|
||||
|
||||
const directResult = results.find(
|
||||
(r: AgentToolCallResult) => r.returnDirect,
|
||||
@@ -542,22 +552,22 @@ export class AgentWorkflow implements Workflow {
|
||||
currentAgentName: agent.name,
|
||||
};
|
||||
|
||||
await agent.finalize(this.stateful.getContext().state, agentOutput);
|
||||
await agent.finalize(context.state, agentOutput);
|
||||
|
||||
if (isHandoff) {
|
||||
const nextAgentName = this.stateful.getContext().state.nextAgentName;
|
||||
const nextAgentName = context.state.nextAgentName;
|
||||
|
||||
this.logger.log(
|
||||
`[Agent ${agentName}]: Handoff to ${nextAgentName}: ${directResult.toolOutput.result}`,
|
||||
);
|
||||
|
||||
if (nextAgentName) {
|
||||
this.stateful.getContext().state.currentAgentName = nextAgentName;
|
||||
this.stateful.getContext().state.nextAgentName = null;
|
||||
context.state.currentAgentName = nextAgentName;
|
||||
context.state.nextAgentName = null;
|
||||
|
||||
const messages = await this.stateful
|
||||
.getContext()
|
||||
.state.memory.getLLM(this.agents.get(nextAgentName)?.llm);
|
||||
const messages = await context.state.memory.getLLM(
|
||||
this.agents.get(nextAgentName)?.llm,
|
||||
);
|
||||
|
||||
this.logger.log(`[Agent ${nextAgentName}]: Starting agent`);
|
||||
|
||||
@@ -571,14 +581,14 @@ export class AgentWorkflow implements Workflow {
|
||||
return stopAgentEvent.with({
|
||||
message: responseMessage,
|
||||
result: output,
|
||||
state: this.stateful.getContext().state,
|
||||
state: context.state,
|
||||
});
|
||||
}
|
||||
|
||||
// Continue with another agent step
|
||||
const messages = await this.stateful
|
||||
.getContext()
|
||||
.state.memory.getLLM(this.agents.get(agent.name)?.llm);
|
||||
const messages = await context.state.memory.getLLM(
|
||||
this.agents.get(agent.name)?.llm,
|
||||
);
|
||||
return agentInputEvent.with({
|
||||
input: messages,
|
||||
currentAgentName: agent.name,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
export * from "@llamaindex/workflow-core";
|
||||
export * from "@llamaindex/workflow-core/middleware/snapshot";
|
||||
export * from "@llamaindex/workflow-core/middleware/state";
|
||||
export * from "@llamaindex/workflow-core/stream/run";
|
||||
export { zodEvent } from "@llamaindex/workflow-core/util/zod";
|
||||
|
||||
Generated
+1626
-999
File diff suppressed because it is too large
Load Diff
@@ -223,6 +223,9 @@
|
||||
},
|
||||
{
|
||||
"path": "./packages/community/tsconfig.json"
|
||||
},
|
||||
{
|
||||
"path": "./examples/local-settings/tsconfig.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
# @llamaindex/unit-test
|
||||
|
||||
## 0.1.60
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1995b38]
|
||||
- Updated dependencies [001a515]
|
||||
- Updated dependencies [9d7d205]
|
||||
- @llamaindex/workflow@1.1.22
|
||||
- @llamaindex/openai@0.4.18
|
||||
- llamaindex@0.11.28
|
||||
|
||||
## 0.1.59
|
||||
|
||||
### Patch Changes
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/unit-test",
|
||||
"private": true,
|
||||
"version": "0.1.59",
|
||||
"version": "0.1.60",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "vitest run"
|
||||
|
||||
Reference in New Issue
Block a user