mirror of
https://github.com/run-llama/LlamaIndexTS.git
synced 2026-07-07 00:31:11 -04:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 456d3fb0b3 | |||
| efa326a871 | |||
| 5765b637ce | |||
| 72687b4f69 | |||
| 0c67e1f8f3 | |||
| 4a0619758a | |||
| bc7a11cdbe | |||
| 5596e31947 | |||
| 2fe2b813ba | |||
| be5df5b01b | |||
| e74fe88342 |
@@ -1,5 +1,23 @@
|
||||
# docs
|
||||
|
||||
## 0.0.14
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [efa326a]
|
||||
- llamaindex@0.3.6
|
||||
|
||||
## 0.0.13
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [bc7a11c]
|
||||
- Updated dependencies [2fe2b81]
|
||||
- Updated dependencies [5596e31]
|
||||
- Updated dependencies [e74fe88]
|
||||
- Updated dependencies [be5df5b]
|
||||
- llamaindex@0.3.5
|
||||
|
||||
## 0.0.12
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "docs",
|
||||
"version": "0.0.12",
|
||||
"version": "0.0.14",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"docusaurus": "docusaurus",
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
"release": "pnpm run check-minor-version && pnpm run build:release && changeset publish",
|
||||
"release-snapshot": "pnpm run check-minor-version && pnpm run build:release && changeset publish --tag snapshot",
|
||||
"check-minor-version": "node ./scripts/check-minor-version",
|
||||
"new-version": "changeset version && pnpm run check-minor-version && pnpm run build:release",
|
||||
"new-version": "changeset version && pnpm run check-minor-version && pnpm format:write && pnpm run build:release",
|
||||
"new-snapshot": "pnpm run build:release && changeset version --snapshot"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1,5 +1,26 @@
|
||||
# llamaindex
|
||||
|
||||
## 0.3.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- efa326a: chore: update package.json
|
||||
- Updated dependencies [efa326a]
|
||||
- Updated dependencies [efa326a]
|
||||
- @llamaindex/env@0.1.2
|
||||
|
||||
## 0.3.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- bc7a11c: fix: inline ollama build
|
||||
- 2fe2b81: fix: filter with multiple filters in ChromaDB
|
||||
- 5596e31: feat: improve `@llamaindex/env`
|
||||
- e74fe88: fix: change <-> to <=> in the SELECT query
|
||||
- be5df5b: fix: anthropic agent on multiple chat
|
||||
- Updated dependencies [5596e31]
|
||||
- @llamaindex/env@0.1.1
|
||||
|
||||
## 0.3.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# @llamaindex/core-e2e
|
||||
|
||||
## 0.0.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- be5df5b: fix: anthropic agent on multiple chat
|
||||
|
||||
## 0.0.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,5 +1,23 @@
|
||||
# @llamaindex/cloudflare-worker-agent-test
|
||||
|
||||
## 0.0.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [efa326a]
|
||||
- llamaindex@0.3.6
|
||||
|
||||
## 0.0.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [bc7a11c]
|
||||
- Updated dependencies [2fe2b81]
|
||||
- Updated dependencies [5596e31]
|
||||
- Updated dependencies [e74fe88]
|
||||
- Updated dependencies [be5df5b]
|
||||
- llamaindex@0.3.5
|
||||
|
||||
## 0.0.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/cloudflare-worker-agent-test",
|
||||
"version": "0.0.5",
|
||||
"version": "0.0.7",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
||||
@@ -1,5 +1,23 @@
|
||||
# @llamaindex/next-agent-test
|
||||
|
||||
## 0.1.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [efa326a]
|
||||
- llamaindex@0.3.6
|
||||
|
||||
## 0.1.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [bc7a11c]
|
||||
- Updated dependencies [2fe2b81]
|
||||
- Updated dependencies [5596e31]
|
||||
- Updated dependencies [e74fe88]
|
||||
- Updated dependencies [be5df5b]
|
||||
- llamaindex@0.3.5
|
||||
|
||||
## 0.1.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/next-agent-test",
|
||||
"version": "0.1.5",
|
||||
"version": "0.1.7",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
|
||||
@@ -1,5 +1,17 @@
|
||||
# test-edge-runtime
|
||||
|
||||
## 0.1.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/edge@0.3.6
|
||||
|
||||
## 0.1.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/edge@0.3.5
|
||||
|
||||
## 0.1.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/nextjs-edge-runtime-test",
|
||||
"version": "0.1.6",
|
||||
"version": "0.1.8",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
|
||||
@@ -1,5 +1,23 @@
|
||||
# @llamaindex/waku-query-engine-test
|
||||
|
||||
## 0.0.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [efa326a]
|
||||
- llamaindex@0.3.6
|
||||
|
||||
## 0.0.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [bc7a11c]
|
||||
- Updated dependencies [2fe2b81]
|
||||
- Updated dependencies [5596e31]
|
||||
- Updated dependencies [e74fe88]
|
||||
- Updated dependencies [be5df5b]
|
||||
- llamaindex@0.3.5
|
||||
|
||||
## 0.0.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/waku-query-engine-test",
|
||||
"version": "0.0.5",
|
||||
"version": "0.0.7",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { AnthropicAgent } from "llamaindex/agent/anthropic";
|
||||
import { extractText } from "llamaindex/llm/utils";
|
||||
import { ok, strictEqual } from "node:assert";
|
||||
import { beforeEach, test } from "node:test";
|
||||
import { sumNumbersTool } from "./fixtures/tools.js";
|
||||
import { getWeatherTool, sumNumbersTool } from "./fixtures/tools.js";
|
||||
import { mockLLMEvent } from "./utils.js";
|
||||
|
||||
let llm: LLM;
|
||||
@@ -118,14 +118,58 @@ await test("anthropic agent", async (t) => {
|
||||
});
|
||||
|
||||
await t.test("sum numbers", async () => {
|
||||
const openaiAgent = new AnthropicAgent({
|
||||
const anthropicAgent = new AnthropicAgent({
|
||||
tools: [sumNumbersTool],
|
||||
});
|
||||
|
||||
const { response } = await openaiAgent.chat({
|
||||
const { response } = await anthropicAgent.chat({
|
||||
message: "how much is 1 + 1?",
|
||||
});
|
||||
|
||||
ok(extractText(response.message.content).includes("2"));
|
||||
});
|
||||
});
|
||||
|
||||
await test("anthropic agent with multiple chat", async (t) => {
|
||||
await mockLLMEvent(t, "anthropic-agent-multiple-chat");
|
||||
await t.test("chat", async () => {
|
||||
const agent = new AnthropicAgent({
|
||||
tools: [getWeatherTool],
|
||||
});
|
||||
{
|
||||
const { response } = await agent.chat({
|
||||
message: 'Hello? Response to me "Yes"',
|
||||
});
|
||||
consola.debug("response:", response.message.content);
|
||||
ok(extractText(response.message.content).includes("Yes"));
|
||||
}
|
||||
{
|
||||
const { response } = await agent.chat({
|
||||
message: 'Hello? Response to me "No"',
|
||||
});
|
||||
consola.debug("response:", response.message.content);
|
||||
ok(extractText(response.message.content).includes("No"));
|
||||
}
|
||||
{
|
||||
const { response } = await agent.chat({
|
||||
message: 'Hello? Response to me "Maybe"',
|
||||
});
|
||||
consola.debug("response:", response.message.content);
|
||||
ok(extractText(response.message.content).includes("Maybe"));
|
||||
}
|
||||
{
|
||||
const { response } = await agent.chat({
|
||||
message: "What is the weather in San Francisco?",
|
||||
});
|
||||
consola.debug("response:", response.message.content);
|
||||
ok(extractText(response.message.content).includes("72"));
|
||||
}
|
||||
{
|
||||
const { response } = await agent.chat({
|
||||
message: "What is the weather in Shanghai?",
|
||||
});
|
||||
consola.debug("response:", response.message.content);
|
||||
ok(extractText(response.message.content).includes("72"));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,552 @@
|
||||
{
|
||||
"llmEventStart": [
|
||||
{
|
||||
"id": "PRESERVE_0",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello? Response to me \"Yes\""
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "PRESERVE_1",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello? Response to me \"Yes\""
|
||||
},
|
||||
{
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "<thinking>\nThe user has not asked a question that requires using any of the available tools. They have simply requested that I respond with the word \"Yes\".\n</thinking>\n\nYes"
|
||||
}
|
||||
],
|
||||
"role": "assistant",
|
||||
"options": {}
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello? Response to me \"No\""
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "PRESERVE_2",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello? Response to me \"Yes\""
|
||||
},
|
||||
{
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "<thinking>\nThe user has not asked a question that requires using any of the available tools. They have simply requested that I respond with the word \"Yes\".\n</thinking>\n\nYes"
|
||||
}
|
||||
],
|
||||
"role": "assistant",
|
||||
"options": {}
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello? Response to me \"No\""
|
||||
},
|
||||
{
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "<thinking>\nThe user has not asked a question that requires using any of the available tools. They have simply requested that I respond with the word \"No\".\n</thinking>\n\nNo"
|
||||
}
|
||||
],
|
||||
"role": "assistant",
|
||||
"options": {}
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello? Response to me \"Maybe\""
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "PRESERVE_3",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello? Response to me \"Yes\""
|
||||
},
|
||||
{
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "<thinking>\nThe user has not asked a question that requires using any of the available tools. They have simply requested that I respond with the word \"Yes\".\n</thinking>\n\nYes"
|
||||
}
|
||||
],
|
||||
"role": "assistant",
|
||||
"options": {}
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello? Response to me \"No\""
|
||||
},
|
||||
{
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "<thinking>\nThe user has not asked a question that requires using any of the available tools. They have simply requested that I respond with the word \"No\".\n</thinking>\n\nNo"
|
||||
}
|
||||
],
|
||||
"role": "assistant",
|
||||
"options": {}
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello? Response to me \"Maybe\""
|
||||
},
|
||||
{
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "<thinking>\nThe user has not asked a question that requires using any of the available tools. They have simply requested that I respond with the word \"Maybe\".\n</thinking>\n\nMaybe"
|
||||
}
|
||||
],
|
||||
"role": "assistant",
|
||||
"options": {}
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "What is the weather in San Francisco?"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "PRESERVE_4",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello? Response to me \"Yes\""
|
||||
},
|
||||
{
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "<thinking>\nThe user has not asked a question that requires using any of the available tools. They have simply requested that I respond with the word \"Yes\".\n</thinking>\n\nYes"
|
||||
}
|
||||
],
|
||||
"role": "assistant",
|
||||
"options": {}
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello? Response to me \"No\""
|
||||
},
|
||||
{
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "<thinking>\nThe user has not asked a question that requires using any of the available tools. They have simply requested that I respond with the word \"No\".\n</thinking>\n\nNo"
|
||||
}
|
||||
],
|
||||
"role": "assistant",
|
||||
"options": {}
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello? Response to me \"Maybe\""
|
||||
},
|
||||
{
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "<thinking>\nThe user has not asked a question that requires using any of the available tools. They have simply requested that I respond with the word \"Maybe\".\n</thinking>\n\nMaybe"
|
||||
}
|
||||
],
|
||||
"role": "assistant",
|
||||
"options": {}
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "What is the weather in San Francisco?"
|
||||
},
|
||||
{
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "<thinking>\nThe user has asked for the weather in a specific city, San Francisco. The relevant tool to answer this is the getWeather function.\n\nLooking at the required parameters for getWeather:\ncity (string): The user directly provided the city \"San Francisco\"\n\nSince the required \"city\" parameter has been provided, we can proceed with the getWeather function call.\n</thinking>"
|
||||
}
|
||||
],
|
||||
"role": "assistant",
|
||||
"options": {
|
||||
"toolCall": {
|
||||
"id": "toolu_01Gy7Gxbx7uGmjVncGH6pubL",
|
||||
"name": "getWeather",
|
||||
"input": {
|
||||
"city": "San Francisco"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"content": "The weather in San Francisco is 72 degrees",
|
||||
"role": "user",
|
||||
"options": {
|
||||
"toolResult": {
|
||||
"result": "The weather in San Francisco is 72 degrees",
|
||||
"isError": false,
|
||||
"id": "toolu_01Gy7Gxbx7uGmjVncGH6pubL"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "PRESERVE_5",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello? Response to me \"Yes\""
|
||||
},
|
||||
{
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "<thinking>\nThe user has not asked a question that requires using any of the available tools. They have simply requested that I respond with the word \"Yes\".\n</thinking>\n\nYes"
|
||||
}
|
||||
],
|
||||
"role": "assistant",
|
||||
"options": {}
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello? Response to me \"No\""
|
||||
},
|
||||
{
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "<thinking>\nThe user has not asked a question that requires using any of the available tools. They have simply requested that I respond with the word \"No\".\n</thinking>\n\nNo"
|
||||
}
|
||||
],
|
||||
"role": "assistant",
|
||||
"options": {}
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello? Response to me \"Maybe\""
|
||||
},
|
||||
{
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "<thinking>\nThe user has not asked a question that requires using any of the available tools. They have simply requested that I respond with the word \"Maybe\".\n</thinking>\n\nMaybe"
|
||||
}
|
||||
],
|
||||
"role": "assistant",
|
||||
"options": {}
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "What is the weather in San Francisco?"
|
||||
},
|
||||
{
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "<thinking>\nThe user has asked for the weather in a specific city, San Francisco. The relevant tool to answer this is the getWeather function.\n\nLooking at the required parameters for getWeather:\ncity (string): The user directly provided the city \"San Francisco\"\n\nSince the required \"city\" parameter has been provided, we can proceed with the getWeather function call.\n</thinking>"
|
||||
}
|
||||
],
|
||||
"role": "assistant",
|
||||
"options": {
|
||||
"toolCall": {
|
||||
"id": "toolu_01Gy7Gxbx7uGmjVncGH6pubL",
|
||||
"name": "getWeather",
|
||||
"input": {
|
||||
"city": "San Francisco"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"content": "The weather in San Francisco is 72 degrees",
|
||||
"role": "user",
|
||||
"options": {
|
||||
"toolResult": {
|
||||
"result": "The weather in San Francisco is 72 degrees",
|
||||
"isError": false,
|
||||
"id": "toolu_01Gy7Gxbx7uGmjVncGH6pubL"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "The current weather in San Francisco is 72 degrees."
|
||||
}
|
||||
],
|
||||
"role": "assistant",
|
||||
"options": {}
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "What is the weather in Shanghai?"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "PRESERVE_6",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello? Response to me \"Yes\""
|
||||
},
|
||||
{
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "<thinking>\nThe user has not asked a question that requires using any of the available tools. They have simply requested that I respond with the word \"Yes\".\n</thinking>\n\nYes"
|
||||
}
|
||||
],
|
||||
"role": "assistant",
|
||||
"options": {}
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello? Response to me \"No\""
|
||||
},
|
||||
{
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "<thinking>\nThe user has not asked a question that requires using any of the available tools. They have simply requested that I respond with the word \"No\".\n</thinking>\n\nNo"
|
||||
}
|
||||
],
|
||||
"role": "assistant",
|
||||
"options": {}
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello? Response to me \"Maybe\""
|
||||
},
|
||||
{
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "<thinking>\nThe user has not asked a question that requires using any of the available tools. They have simply requested that I respond with the word \"Maybe\".\n</thinking>\n\nMaybe"
|
||||
}
|
||||
],
|
||||
"role": "assistant",
|
||||
"options": {}
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "What is the weather in San Francisco?"
|
||||
},
|
||||
{
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "<thinking>\nThe user has asked for the weather in a specific city, San Francisco. The relevant tool to answer this is the getWeather function.\n\nLooking at the required parameters for getWeather:\ncity (string): The user directly provided the city \"San Francisco\"\n\nSince the required \"city\" parameter has been provided, we can proceed with the getWeather function call.\n</thinking>"
|
||||
}
|
||||
],
|
||||
"role": "assistant",
|
||||
"options": {
|
||||
"toolCall": {
|
||||
"id": "toolu_01Gy7Gxbx7uGmjVncGH6pubL",
|
||||
"name": "getWeather",
|
||||
"input": {
|
||||
"city": "San Francisco"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"content": "The weather in San Francisco is 72 degrees",
|
||||
"role": "user",
|
||||
"options": {
|
||||
"toolResult": {
|
||||
"result": "The weather in San Francisco is 72 degrees",
|
||||
"isError": false,
|
||||
"id": "toolu_01Gy7Gxbx7uGmjVncGH6pubL"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "The current weather in San Francisco is 72 degrees."
|
||||
}
|
||||
],
|
||||
"role": "assistant",
|
||||
"options": {}
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "What is the weather in Shanghai?"
|
||||
},
|
||||
{
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "<thinking>\nThe user has asked for the weather in a specific city, Shanghai. The relevant tool to answer this is the getWeather function.\n\nLooking at the required parameters for getWeather:\ncity (string): The user directly provided the city \"Shanghai\"\n\nSince the required \"city\" parameter has been provided, we can proceed with the getWeather function call.\n</thinking>"
|
||||
}
|
||||
],
|
||||
"role": "assistant",
|
||||
"options": {
|
||||
"toolCall": {
|
||||
"id": "toolu_01NHyahSUqrPjxQk9mvCvvGe",
|
||||
"name": "getWeather",
|
||||
"input": {
|
||||
"city": "Shanghai"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"content": "The weather in Shanghai is 72 degrees",
|
||||
"role": "user",
|
||||
"options": {
|
||||
"toolResult": {
|
||||
"result": "The weather in Shanghai is 72 degrees",
|
||||
"isError": false,
|
||||
"id": "toolu_01NHyahSUqrPjxQk9mvCvvGe"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"llmEventEnd": [
|
||||
{
|
||||
"id": "PRESERVE_0",
|
||||
"response": {
|
||||
"raw": null,
|
||||
"message": {
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "<thinking>\nThe user has not asked a question that requires using any of the available tools. They have simply requested that I respond with the word \"Yes\".\n</thinking>\n\nYes"
|
||||
}
|
||||
],
|
||||
"role": "assistant",
|
||||
"options": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "PRESERVE_1",
|
||||
"response": {
|
||||
"raw": null,
|
||||
"message": {
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "<thinking>\nThe user has not asked a question that requires using any of the available tools. They have simply requested that I respond with the word \"No\".\n</thinking>\n\nNo"
|
||||
}
|
||||
],
|
||||
"role": "assistant",
|
||||
"options": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "PRESERVE_2",
|
||||
"response": {
|
||||
"raw": null,
|
||||
"message": {
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "<thinking>\nThe user has not asked a question that requires using any of the available tools. They have simply requested that I respond with the word \"Maybe\".\n</thinking>\n\nMaybe"
|
||||
}
|
||||
],
|
||||
"role": "assistant",
|
||||
"options": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "PRESERVE_3",
|
||||
"response": {
|
||||
"raw": null,
|
||||
"message": {
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "<thinking>\nThe user has asked for the weather in a specific city, San Francisco. The relevant tool to answer this is the getWeather function.\n\nLooking at the required parameters for getWeather:\ncity (string): The user directly provided the city \"San Francisco\"\n\nSince the required \"city\" parameter has been provided, we can proceed with the getWeather function call.\n</thinking>"
|
||||
}
|
||||
],
|
||||
"role": "assistant",
|
||||
"options": {
|
||||
"toolCall": {
|
||||
"id": "toolu_01Gy7Gxbx7uGmjVncGH6pubL",
|
||||
"name": "getWeather",
|
||||
"input": {
|
||||
"city": "San Francisco"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "PRESERVE_4",
|
||||
"response": {
|
||||
"raw": null,
|
||||
"message": {
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "The current weather in San Francisco is 72 degrees."
|
||||
}
|
||||
],
|
||||
"role": "assistant",
|
||||
"options": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "PRESERVE_5",
|
||||
"response": {
|
||||
"raw": null,
|
||||
"message": {
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "<thinking>\nThe user has asked for the weather in a specific city, Shanghai. The relevant tool to answer this is the getWeather function.\n\nLooking at the required parameters for getWeather:\ncity (string): The user directly provided the city \"Shanghai\"\n\nSince the required \"city\" parameter has been provided, we can proceed with the getWeather function call.\n</thinking>"
|
||||
}
|
||||
],
|
||||
"role": "assistant",
|
||||
"options": {
|
||||
"toolCall": {
|
||||
"id": "toolu_01NHyahSUqrPjxQk9mvCvvGe",
|
||||
"name": "getWeather",
|
||||
"input": {
|
||||
"city": "Shanghai"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "PRESERVE_6",
|
||||
"response": {
|
||||
"raw": null,
|
||||
"message": {
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "The current weather in Shanghai is 72 degrees."
|
||||
}
|
||||
],
|
||||
"role": "assistant",
|
||||
"options": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"llmEventStream": []
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/core-e2e",
|
||||
"private": true,
|
||||
"version": "0.0.3",
|
||||
"version": "0.0.4",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"e2e": "node --import tsx --import ./mock-register.js --test ./node/*.e2e.ts",
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
{
|
||||
"name": "@llamaindex/core",
|
||||
"version": "0.3.4",
|
||||
"version": "0.3.6",
|
||||
"exports": "./src/index.ts",
|
||||
"imports": {
|
||||
"@llamaindex/env": "jsr:@llamaindex/env@0.0.6"
|
||||
"@llamaindex/env": "jsr:@llamaindex/env@0.1.2"
|
||||
},
|
||||
"publish": {
|
||||
"include": ["LICENSE", "README.md", "src/**/*", "jsr.json"]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,25 @@
|
||||
{
|
||||
"name": "llamaindex",
|
||||
"version": "0.3.4",
|
||||
"version": "0.3.6",
|
||||
"expectedMinorVersion": "3",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"keywords": [
|
||||
"llm",
|
||||
"llama",
|
||||
"openai",
|
||||
"gpt",
|
||||
"data science",
|
||||
"prompt",
|
||||
"prompt engineering",
|
||||
"chatgpt",
|
||||
"machine learning",
|
||||
"ml",
|
||||
"embedding",
|
||||
"vectorstore",
|
||||
"data framework",
|
||||
"llamaindex"
|
||||
],
|
||||
"dependencies": {
|
||||
"@anthropic-ai/sdk": "^0.20.6",
|
||||
"@aws-crypto/sha256-js": "^5.2.0",
|
||||
@@ -32,7 +48,6 @@
|
||||
"md-utils-ts": "^2.0.0",
|
||||
"mongodb": "^6.5.0",
|
||||
"notion-md-crawler": "^1.0.0",
|
||||
"ollama": "^0.5.0",
|
||||
"openai": "^4.38.0",
|
||||
"papaparse": "^5.4.1",
|
||||
"pathe": "^1.1.2",
|
||||
|
||||
@@ -348,6 +348,8 @@ export abstract class AgentRunner<
|
||||
>,
|
||||
) => {
|
||||
for await (const stepOutput of iter) {
|
||||
// update chat history for each round
|
||||
this.#chatHistory = [...stepOutput.taskStep.context.store.messages];
|
||||
if (stepOutput.isLast) {
|
||||
return stepOutput;
|
||||
}
|
||||
@@ -356,7 +358,6 @@ export abstract class AgentRunner<
|
||||
},
|
||||
);
|
||||
const { output, taskStep } = stepOutput;
|
||||
this.#chatHistory = [...taskStep.context.store.messages];
|
||||
if (isAsyncIterable(output)) {
|
||||
return output.pipeThrough<
|
||||
AgentStreamChatResponse<AdditionalMessageOptions>
|
||||
|
||||
+264
@@ -0,0 +1,264 @@
|
||||
type Fetch = typeof fetch;
|
||||
interface Config {
|
||||
host: string;
|
||||
fetch?: Fetch;
|
||||
proxy?: boolean;
|
||||
}
|
||||
interface Options {
|
||||
numa: boolean;
|
||||
num_ctx: number;
|
||||
num_batch: number;
|
||||
main_gpu: number;
|
||||
low_vram: boolean;
|
||||
f16_kv: boolean;
|
||||
logits_all: boolean;
|
||||
vocab_only: boolean;
|
||||
use_mmap: boolean;
|
||||
use_mlock: boolean;
|
||||
embedding_only: boolean;
|
||||
num_thread: number;
|
||||
num_keep: number;
|
||||
seed: number;
|
||||
num_predict: number;
|
||||
top_k: number;
|
||||
top_p: number;
|
||||
tfs_z: number;
|
||||
typical_p: number;
|
||||
repeat_last_n: number;
|
||||
temperature: number;
|
||||
repeat_penalty: number;
|
||||
presence_penalty: number;
|
||||
frequency_penalty: number;
|
||||
mirostat: number;
|
||||
mirostat_tau: number;
|
||||
mirostat_eta: number;
|
||||
penalize_newline: boolean;
|
||||
stop: string[];
|
||||
}
|
||||
interface GenerateRequest {
|
||||
model: string;
|
||||
prompt: string;
|
||||
system?: string;
|
||||
template?: string;
|
||||
context?: number[];
|
||||
stream?: boolean;
|
||||
raw?: boolean;
|
||||
format?: string;
|
||||
images?: Uint8Array[] | string[];
|
||||
keep_alive?: string | number;
|
||||
options?: Partial<Options>;
|
||||
}
|
||||
interface Message {
|
||||
role: string;
|
||||
content: string;
|
||||
images?: Uint8Array[] | string[];
|
||||
}
|
||||
interface ChatRequest {
|
||||
model: string;
|
||||
messages?: Message[];
|
||||
stream?: boolean;
|
||||
format?: string;
|
||||
keep_alive?: string | number;
|
||||
options?: Partial<Options>;
|
||||
}
|
||||
interface PullRequest {
|
||||
model: string;
|
||||
insecure?: boolean;
|
||||
stream?: boolean;
|
||||
}
|
||||
interface PushRequest {
|
||||
model: string;
|
||||
insecure?: boolean;
|
||||
stream?: boolean;
|
||||
}
|
||||
interface CreateRequest {
|
||||
model: string;
|
||||
path?: string;
|
||||
modelfile?: string;
|
||||
stream?: boolean;
|
||||
}
|
||||
interface DeleteRequest {
|
||||
model: string;
|
||||
}
|
||||
interface CopyRequest {
|
||||
source: string;
|
||||
destination: string;
|
||||
}
|
||||
interface ShowRequest {
|
||||
model: string;
|
||||
system?: string;
|
||||
template?: string;
|
||||
options?: Partial<Options>;
|
||||
}
|
||||
interface EmbeddingsRequest {
|
||||
model: string;
|
||||
prompt: string;
|
||||
keep_alive?: string | number;
|
||||
options?: Partial<Options>;
|
||||
}
|
||||
interface GenerateResponse {
|
||||
model: string;
|
||||
created_at: Date;
|
||||
response: string;
|
||||
done: boolean;
|
||||
context: number[];
|
||||
total_duration: number;
|
||||
load_duration: number;
|
||||
prompt_eval_count: number;
|
||||
prompt_eval_duration: number;
|
||||
eval_count: number;
|
||||
eval_duration: number;
|
||||
}
|
||||
interface ChatResponse {
|
||||
model: string;
|
||||
created_at: Date;
|
||||
message: Message;
|
||||
done: boolean;
|
||||
total_duration: number;
|
||||
load_duration: number;
|
||||
prompt_eval_count: number;
|
||||
prompt_eval_duration: number;
|
||||
eval_count: number;
|
||||
eval_duration: number;
|
||||
}
|
||||
interface EmbeddingsResponse {
|
||||
embedding: number[];
|
||||
}
|
||||
interface ProgressResponse {
|
||||
status: string;
|
||||
digest: string;
|
||||
total: number;
|
||||
completed: number;
|
||||
}
|
||||
interface ModelResponse {
|
||||
name: string;
|
||||
modified_at: Date;
|
||||
size: number;
|
||||
digest: string;
|
||||
details: ModelDetails;
|
||||
}
|
||||
interface ModelDetails {
|
||||
parent_model: string;
|
||||
format: string;
|
||||
family: string;
|
||||
families: string[];
|
||||
parameter_size: string;
|
||||
quantization_level: string;
|
||||
}
|
||||
interface ShowResponse {
|
||||
license: string;
|
||||
modelfile: string;
|
||||
parameters: string;
|
||||
template: string;
|
||||
system: string;
|
||||
details: ModelDetails;
|
||||
messages: Message[];
|
||||
}
|
||||
interface ListResponse {
|
||||
models: ModelResponse[];
|
||||
}
|
||||
interface ErrorResponse {
|
||||
error: string;
|
||||
}
|
||||
interface StatusResponse {
|
||||
status: string;
|
||||
}
|
||||
|
||||
declare class Ollama {
|
||||
protected readonly config: Config;
|
||||
protected readonly fetch: Fetch;
|
||||
private abortController;
|
||||
constructor(config?: Partial<Config>);
|
||||
abort(): void;
|
||||
protected processStreamableRequest<T extends object>(
|
||||
endpoint: string,
|
||||
request: {
|
||||
stream?: boolean;
|
||||
} & Record<string, any>,
|
||||
): Promise<T | AsyncGenerator<T>>;
|
||||
encodeImage(image: Uint8Array | string): Promise<string>;
|
||||
generate(
|
||||
request: GenerateRequest & {
|
||||
stream: true;
|
||||
},
|
||||
): Promise<AsyncGenerator<GenerateResponse>>;
|
||||
generate(
|
||||
request: GenerateRequest & {
|
||||
stream?: false;
|
||||
},
|
||||
): Promise<GenerateResponse>;
|
||||
chat(
|
||||
request: ChatRequest & {
|
||||
stream: true;
|
||||
},
|
||||
): Promise<AsyncGenerator<ChatResponse>>;
|
||||
chat(
|
||||
request: ChatRequest & {
|
||||
stream?: false;
|
||||
},
|
||||
): Promise<ChatResponse>;
|
||||
create(
|
||||
request: CreateRequest & {
|
||||
stream: true;
|
||||
},
|
||||
): Promise<AsyncGenerator<ProgressResponse>>;
|
||||
create(
|
||||
request: CreateRequest & {
|
||||
stream?: false;
|
||||
},
|
||||
): Promise<ProgressResponse>;
|
||||
pull(
|
||||
request: PullRequest & {
|
||||
stream: true;
|
||||
},
|
||||
): Promise<AsyncGenerator<ProgressResponse>>;
|
||||
pull(
|
||||
request: PullRequest & {
|
||||
stream?: false;
|
||||
},
|
||||
): Promise<ProgressResponse>;
|
||||
push(
|
||||
request: PushRequest & {
|
||||
stream: true;
|
||||
},
|
||||
): Promise<AsyncGenerator<ProgressResponse>>;
|
||||
push(
|
||||
request: PushRequest & {
|
||||
stream?: false;
|
||||
},
|
||||
): Promise<ProgressResponse>;
|
||||
delete(request: DeleteRequest): Promise<StatusResponse>;
|
||||
copy(request: CopyRequest): Promise<StatusResponse>;
|
||||
list(): Promise<ListResponse>;
|
||||
show(request: ShowRequest): Promise<ShowResponse>;
|
||||
embeddings(request: EmbeddingsRequest): Promise<EmbeddingsResponse>;
|
||||
}
|
||||
declare const _default: Ollama;
|
||||
|
||||
export {
|
||||
Ollama,
|
||||
_default as default,
|
||||
type ChatRequest,
|
||||
type ChatResponse,
|
||||
type Config,
|
||||
type CopyRequest,
|
||||
type CreateRequest,
|
||||
type DeleteRequest,
|
||||
type EmbeddingsRequest,
|
||||
type EmbeddingsResponse,
|
||||
type ErrorResponse,
|
||||
type Fetch,
|
||||
type GenerateRequest,
|
||||
type GenerateResponse,
|
||||
type ListResponse,
|
||||
type Message,
|
||||
type ModelDetails,
|
||||
type ModelResponse,
|
||||
type Options,
|
||||
type ProgressResponse,
|
||||
type PullRequest,
|
||||
type PushRequest,
|
||||
type ShowRequest,
|
||||
type ShowResponse,
|
||||
type StatusResponse,
|
||||
};
|
||||
@@ -0,0 +1,462 @@
|
||||
// generate from "tsup ./src/browser.js --format esm --dts"
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
||||
var __knownSymbol = (name, symbol) => {
|
||||
return (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
||||
};
|
||||
var __defNormalProp = (obj, key, value) =>
|
||||
key in obj
|
||||
? __defProp(obj, key, {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value,
|
||||
})
|
||||
: (obj[key] = value);
|
||||
var __spreadValues = (a, b) => {
|
||||
for (var prop in b || (b = {}))
|
||||
if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
||||
if (__getOwnPropSymbols)
|
||||
for (var prop of __getOwnPropSymbols(b)) {
|
||||
if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
||||
}
|
||||
return a;
|
||||
};
|
||||
var __async = (__this, __arguments, generator) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
var fulfilled = (value) => {
|
||||
try {
|
||||
step(generator.next(value));
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
};
|
||||
var rejected = (value) => {
|
||||
try {
|
||||
step(generator.throw(value));
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
};
|
||||
var step = (x) =>
|
||||
x.done
|
||||
? resolve(x.value)
|
||||
: Promise.resolve(x.value).then(fulfilled, rejected);
|
||||
step((generator = generator.apply(__this, __arguments)).next());
|
||||
});
|
||||
};
|
||||
var __await = function (promise, isYieldStar) {
|
||||
this[0] = promise;
|
||||
this[1] = isYieldStar;
|
||||
};
|
||||
var __asyncGenerator = (__this, __arguments, generator) => {
|
||||
var resume = (k, v, yes, no) => {
|
||||
try {
|
||||
var x = generator[k](v),
|
||||
isAwait = (v = x.value) instanceof __await,
|
||||
done = x.done;
|
||||
Promise.resolve(isAwait ? v[0] : v)
|
||||
.then((y) =>
|
||||
isAwait
|
||||
? resume(
|
||||
k === "return" ? k : "next",
|
||||
v[1] ? { done: y.done, value: y.value } : y,
|
||||
yes,
|
||||
no,
|
||||
)
|
||||
: yes({ value: y, done }),
|
||||
)
|
||||
.catch((e) => resume("throw", e, yes, no));
|
||||
} catch (e) {
|
||||
no(e);
|
||||
}
|
||||
};
|
||||
var method = (k) =>
|
||||
(it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no)));
|
||||
var it = {};
|
||||
return (
|
||||
(generator = generator.apply(__this, __arguments)),
|
||||
(it[__knownSymbol("asyncIterator")] = () => it),
|
||||
method("next"),
|
||||
method("throw"),
|
||||
method("return"),
|
||||
it
|
||||
);
|
||||
};
|
||||
var __forAwait = (obj, it, method) =>
|
||||
(it = obj[__knownSymbol("asyncIterator")])
|
||||
? it.call(obj)
|
||||
: ((obj = obj[__knownSymbol("iterator")]()),
|
||||
(it = {}),
|
||||
(method = (key, fn) =>
|
||||
(fn = obj[key]) &&
|
||||
(it[key] = (arg) =>
|
||||
new Promise(
|
||||
(yes, no, done) => (
|
||||
(arg = fn.call(obj, arg)),
|
||||
(done = arg.done),
|
||||
Promise.resolve(arg.value).then(
|
||||
(value) => yes({ value, done }),
|
||||
no,
|
||||
)
|
||||
),
|
||||
))),
|
||||
method("next"),
|
||||
method("return"),
|
||||
it);
|
||||
|
||||
// src/version.ts
|
||||
var version = "0.0.0";
|
||||
|
||||
// src/utils.ts
|
||||
var ResponseError = class _ResponseError extends Error {
|
||||
constructor(error, status_code) {
|
||||
super(error);
|
||||
this.error = error;
|
||||
this.status_code = status_code;
|
||||
this.name = "ResponseError";
|
||||
if (Error.captureStackTrace) {
|
||||
Error.captureStackTrace(this, _ResponseError);
|
||||
}
|
||||
}
|
||||
};
|
||||
var checkOk = (response) =>
|
||||
__async(void 0, null, function* () {
|
||||
var _a;
|
||||
if (!response.ok) {
|
||||
let message = `Error ${response.status}: ${response.statusText}`;
|
||||
let errorData = null;
|
||||
if (
|
||||
(_a = response.headers.get("content-type")) == null
|
||||
? void 0
|
||||
: _a.includes("application/json")
|
||||
) {
|
||||
try {
|
||||
errorData = yield response.json();
|
||||
message = errorData.error || message;
|
||||
} catch (error) {
|
||||
console.log("Failed to parse error response as JSON");
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
console.log("Getting text from response");
|
||||
const textResponse = yield response.text();
|
||||
message = textResponse || message;
|
||||
} catch (error) {
|
||||
console.log("Failed to get text from error response");
|
||||
}
|
||||
}
|
||||
throw new ResponseError(message, response.status);
|
||||
}
|
||||
});
|
||||
function getPlatform() {
|
||||
if (typeof window !== "undefined" && window.navigator) {
|
||||
return `${window.navigator.platform.toLowerCase()} Browser/${navigator.userAgent};`;
|
||||
} else if (typeof process !== "undefined") {
|
||||
return `${process.arch} ${process.platform} Node.js/${process.version}`;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
var fetchWithHeaders = (_0, _1, ..._2) =>
|
||||
__async(void 0, [_0, _1, ..._2], function* (fetch2, url, options = {}) {
|
||||
const defaultHeaders = {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"User-Agent": `ollama-js/${version} (${getPlatform()})`,
|
||||
};
|
||||
if (!options.headers) {
|
||||
options.headers = {};
|
||||
}
|
||||
options.headers = __spreadValues(
|
||||
__spreadValues({}, defaultHeaders),
|
||||
options.headers,
|
||||
);
|
||||
return fetch2(url, options);
|
||||
});
|
||||
var get = (fetch2, host) =>
|
||||
__async(void 0, null, function* () {
|
||||
const response = yield fetchWithHeaders(fetch2, host);
|
||||
yield checkOk(response);
|
||||
return response;
|
||||
});
|
||||
var post = (fetch2, host, data, options) =>
|
||||
__async(void 0, null, function* () {
|
||||
const isRecord = (input) => {
|
||||
return (
|
||||
input !== null && typeof input === "object" && !Array.isArray(input)
|
||||
);
|
||||
};
|
||||
const formattedData = isRecord(data) ? JSON.stringify(data) : data;
|
||||
const response = yield fetchWithHeaders(fetch2, host, {
|
||||
method: "POST",
|
||||
body: formattedData,
|
||||
signal: options == null ? void 0 : options.signal,
|
||||
});
|
||||
yield checkOk(response);
|
||||
return response;
|
||||
});
|
||||
var del = (fetch2, host, data) =>
|
||||
__async(void 0, null, function* () {
|
||||
const response = yield fetchWithHeaders(fetch2, host, {
|
||||
method: "DELETE",
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
yield checkOk(response);
|
||||
return response;
|
||||
});
|
||||
var parseJSON = function (itr) {
|
||||
return __asyncGenerator(this, null, function* () {
|
||||
var _a;
|
||||
const decoder = new TextDecoder("utf-8");
|
||||
let buffer = "";
|
||||
const reader = itr.getReader();
|
||||
while (true) {
|
||||
const { done, value: chunk } = yield new __await(reader.read());
|
||||
if (done) {
|
||||
break;
|
||||
}
|
||||
buffer += decoder.decode(chunk);
|
||||
const parts = buffer.split("\n");
|
||||
buffer = (_a = parts.pop()) != null ? _a : "";
|
||||
for (const part of parts) {
|
||||
try {
|
||||
yield JSON.parse(part);
|
||||
} catch (error) {
|
||||
console.warn("invalid json: ", part);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const part of buffer.split("\n").filter((p) => p !== "")) {
|
||||
try {
|
||||
yield JSON.parse(part);
|
||||
} catch (error) {
|
||||
console.warn("invalid json: ", part);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
var formatHost = (host) => {
|
||||
if (!host) {
|
||||
return "http://127.0.0.1:11434";
|
||||
}
|
||||
let isExplicitProtocol = host.includes("://");
|
||||
if (host.startsWith(":")) {
|
||||
host = `http://127.0.0.1${host}`;
|
||||
isExplicitProtocol = false;
|
||||
}
|
||||
if (!isExplicitProtocol) {
|
||||
host = `http://${host}`;
|
||||
}
|
||||
const url = new URL(host);
|
||||
let port = url.port;
|
||||
if (!port) {
|
||||
if (!isExplicitProtocol) {
|
||||
port = "11434";
|
||||
} else {
|
||||
port = url.protocol === "https:" ? "443" : "80";
|
||||
}
|
||||
}
|
||||
let formattedHost = `${url.protocol}//${url.hostname}:${port}${url.pathname}`;
|
||||
if (formattedHost.endsWith("/")) {
|
||||
formattedHost = formattedHost.slice(0, -1);
|
||||
}
|
||||
return formattedHost;
|
||||
};
|
||||
|
||||
// src/browser.ts
|
||||
// import "whatwg-fetch";
|
||||
var Ollama = class {
|
||||
constructor(config) {
|
||||
var _a;
|
||||
this.config = {
|
||||
host: "",
|
||||
};
|
||||
if (!(config == null ? void 0 : config.proxy)) {
|
||||
this.config.host = formatHost(
|
||||
(_a = config == null ? void 0 : config.host) != null
|
||||
? _a
|
||||
: "http://127.0.0.1:11434",
|
||||
);
|
||||
}
|
||||
this.fetch = fetch;
|
||||
if ((config == null ? void 0 : config.fetch) != null) {
|
||||
this.fetch = config.fetch;
|
||||
}
|
||||
this.abortController = new AbortController();
|
||||
}
|
||||
// Abort any ongoing requests to Ollama
|
||||
abort() {
|
||||
this.abortController.abort();
|
||||
this.abortController = new AbortController();
|
||||
}
|
||||
processStreamableRequest(endpoint, request) {
|
||||
return __async(this, null, function* () {
|
||||
var _a;
|
||||
request.stream = (_a = request.stream) != null ? _a : false;
|
||||
const response = yield post(
|
||||
this.fetch,
|
||||
`${this.config.host}/api/${endpoint}`,
|
||||
__spreadValues({}, request),
|
||||
{ signal: this.abortController.signal },
|
||||
);
|
||||
if (!response.body) {
|
||||
throw new Error("Missing body");
|
||||
}
|
||||
const itr = parseJSON(response.body);
|
||||
if (request.stream) {
|
||||
return (function () {
|
||||
return __asyncGenerator(this, null, function* () {
|
||||
try {
|
||||
for (
|
||||
var iter = __forAwait(itr), more, temp, error;
|
||||
(more = !(temp = yield new __await(iter.next())).done);
|
||||
more = false
|
||||
) {
|
||||
const message = temp.value;
|
||||
if ("error" in message) {
|
||||
throw new Error(message.error);
|
||||
}
|
||||
yield message;
|
||||
if (message.done || message.status === "success") {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (temp) {
|
||||
error = [temp];
|
||||
} finally {
|
||||
try {
|
||||
more &&
|
||||
(temp = iter.return) &&
|
||||
(yield new __await(temp.call(iter)));
|
||||
} finally {
|
||||
if (error) throw error[0];
|
||||
}
|
||||
}
|
||||
throw new Error(
|
||||
"Did not receive done or success response in stream.",
|
||||
);
|
||||
});
|
||||
})();
|
||||
} else {
|
||||
const message = yield itr.next();
|
||||
if (!message.value.done && message.value.status !== "success") {
|
||||
throw new Error("Expected a completed response.");
|
||||
}
|
||||
return message.value;
|
||||
}
|
||||
});
|
||||
}
|
||||
encodeImage(image) {
|
||||
return __async(this, null, function* () {
|
||||
if (typeof image !== "string") {
|
||||
const uint8Array = new Uint8Array(image);
|
||||
const numberArray = Array.from(uint8Array);
|
||||
const base64String = btoa(String.fromCharCode.apply(null, numberArray));
|
||||
return base64String;
|
||||
}
|
||||
return image;
|
||||
});
|
||||
}
|
||||
generate(request) {
|
||||
return __async(this, null, function* () {
|
||||
if (request.images) {
|
||||
request.images = yield Promise.all(
|
||||
request.images.map(this.encodeImage.bind(this)),
|
||||
);
|
||||
}
|
||||
return this.processStreamableRequest("generate", request);
|
||||
});
|
||||
}
|
||||
chat(request) {
|
||||
return __async(this, null, function* () {
|
||||
if (request.messages) {
|
||||
for (const message of request.messages) {
|
||||
if (message.images) {
|
||||
message.images = yield Promise.all(
|
||||
message.images.map(this.encodeImage.bind(this)),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.processStreamableRequest("chat", request);
|
||||
});
|
||||
}
|
||||
create(request) {
|
||||
return __async(this, null, function* () {
|
||||
return this.processStreamableRequest("create", {
|
||||
name: request.model,
|
||||
stream: request.stream,
|
||||
modelfile: request.modelfile,
|
||||
});
|
||||
});
|
||||
}
|
||||
pull(request) {
|
||||
return __async(this, null, function* () {
|
||||
return this.processStreamableRequest("pull", {
|
||||
name: request.model,
|
||||
stream: request.stream,
|
||||
insecure: request.insecure,
|
||||
});
|
||||
});
|
||||
}
|
||||
push(request) {
|
||||
return __async(this, null, function* () {
|
||||
return this.processStreamableRequest("push", {
|
||||
name: request.model,
|
||||
stream: request.stream,
|
||||
insecure: request.insecure,
|
||||
});
|
||||
});
|
||||
}
|
||||
delete(request) {
|
||||
return __async(this, null, function* () {
|
||||
yield del(this.fetch, `${this.config.host}/api/delete`, {
|
||||
name: request.model,
|
||||
});
|
||||
return { status: "success" };
|
||||
});
|
||||
}
|
||||
copy(request) {
|
||||
return __async(this, null, function* () {
|
||||
yield post(
|
||||
this.fetch,
|
||||
`${this.config.host}/api/copy`,
|
||||
__spreadValues({}, request),
|
||||
);
|
||||
return { status: "success" };
|
||||
});
|
||||
}
|
||||
list() {
|
||||
return __async(this, null, function* () {
|
||||
const response = yield get(this.fetch, `${this.config.host}/api/tags`);
|
||||
const listResponse = yield response.json();
|
||||
return listResponse;
|
||||
});
|
||||
}
|
||||
show(request) {
|
||||
return __async(this, null, function* () {
|
||||
const response = yield post(
|
||||
this.fetch,
|
||||
`${this.config.host}/api/show`,
|
||||
__spreadValues({}, request),
|
||||
);
|
||||
const showResponse = yield response.json();
|
||||
return showResponse;
|
||||
});
|
||||
}
|
||||
embeddings(request) {
|
||||
return __async(this, null, function* () {
|
||||
const response = yield post(
|
||||
this.fetch,
|
||||
`${this.config.host}/api/embeddings`,
|
||||
__spreadValues({}, request),
|
||||
);
|
||||
const embeddingsResponse = yield response.json();
|
||||
return embeddingsResponse;
|
||||
});
|
||||
}
|
||||
};
|
||||
var browser_default = new Ollama();
|
||||
export { Ollama, browser_default as default };
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 Saul
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -156,58 +156,104 @@ export class Anthropic extends ToolCallLLM<AnthropicAdditionalChatOptions> {
|
||||
formatMessages<Beta = false>(
|
||||
messages: ChatMessage<ToolCallLLMMessageOptions>[],
|
||||
): Beta extends true ? ToolsBetaMessageParam[] : MessageParam[] {
|
||||
return messages.map<any>((message) => {
|
||||
if (message.role !== "user" && message.role !== "assistant") {
|
||||
throw new Error("Unsupported Anthropic role");
|
||||
}
|
||||
const options = message.options ?? {};
|
||||
if ("toolResult" in options) {
|
||||
const { id, isError } = options.toolResult;
|
||||
return {
|
||||
role: "user",
|
||||
content: [
|
||||
{
|
||||
type: "tool_result",
|
||||
is_error: isError,
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: extractText(message.content),
|
||||
},
|
||||
],
|
||||
tool_use_id: id,
|
||||
},
|
||||
] satisfies ToolResultBlockParam[],
|
||||
} satisfies ToolsBetaMessageParam;
|
||||
} else if ("toolCall" in options) {
|
||||
const aiThinkingText = extractText(message.content);
|
||||
return {
|
||||
role: "assistant",
|
||||
content: [
|
||||
// this could be empty when you call two tools in one query
|
||||
...(aiThinkingText.trim()
|
||||
? [
|
||||
const result: ToolsBetaMessageParam[] = messages
|
||||
.filter(
|
||||
(message) => message.role === "user" || message.role === "assistant",
|
||||
)
|
||||
.map((message) => {
|
||||
const options = message.options ?? {};
|
||||
if ("toolResult" in options) {
|
||||
const { id, isError } = options.toolResult;
|
||||
return {
|
||||
role: "user",
|
||||
content: [
|
||||
{
|
||||
type: "tool_result",
|
||||
is_error: isError,
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: aiThinkingText,
|
||||
} satisfies TextBlockParam,
|
||||
]
|
||||
: []),
|
||||
{
|
||||
type: "tool_use",
|
||||
id: options.toolCall.id,
|
||||
name: options.toolCall.name,
|
||||
input: options.toolCall.input,
|
||||
} satisfies ToolUseBlockParam,
|
||||
] satisfies ToolsBetaContentBlock[],
|
||||
} satisfies ToolsBetaMessageParam;
|
||||
}
|
||||
text: extractText(message.content),
|
||||
},
|
||||
],
|
||||
tool_use_id: id,
|
||||
},
|
||||
] satisfies ToolResultBlockParam[],
|
||||
} satisfies ToolsBetaMessageParam;
|
||||
} else if ("toolCall" in options) {
|
||||
const aiThinkingText = extractText(message.content);
|
||||
return {
|
||||
role: "assistant",
|
||||
content: [
|
||||
// this could be empty when you call two tools in one query
|
||||
...(aiThinkingText.trim()
|
||||
? [
|
||||
{
|
||||
type: "text",
|
||||
text: aiThinkingText,
|
||||
} satisfies TextBlockParam,
|
||||
]
|
||||
: []),
|
||||
{
|
||||
type: "tool_use",
|
||||
id: options.toolCall.id,
|
||||
name: options.toolCall.name,
|
||||
input: options.toolCall.input,
|
||||
} satisfies ToolUseBlockParam,
|
||||
] satisfies ToolsBetaContentBlock[],
|
||||
} satisfies ToolsBetaMessageParam;
|
||||
}
|
||||
|
||||
return {
|
||||
content: extractText(message.content),
|
||||
role: message.role,
|
||||
} satisfies MessageParam;
|
||||
});
|
||||
return {
|
||||
content: extractText(message.content),
|
||||
role: message.role as "user" | "assistant",
|
||||
} satisfies MessageParam;
|
||||
});
|
||||
// merge messages with the same role
|
||||
// in case of 'messages: roles must alternate between "user" and "assistant", but found multiple "user" roles in a row'
|
||||
const realResult: ToolsBetaMessageParam[] = [];
|
||||
for (let i = 0; i < result.length; i++) {
|
||||
if (i === 0) {
|
||||
realResult.push(result[i]);
|
||||
continue;
|
||||
}
|
||||
const current = result[i];
|
||||
const previous = result[i - 1];
|
||||
if (current.role === previous.role) {
|
||||
// merge two messages with the same role
|
||||
if (Array.isArray(previous.content)) {
|
||||
if (Array.isArray(current.content)) {
|
||||
previous.content.push(...current.content);
|
||||
} else {
|
||||
previous.content.push({
|
||||
type: "text",
|
||||
text: current.content,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
if (Array.isArray(current.content)) {
|
||||
previous.content = [
|
||||
{
|
||||
type: "text",
|
||||
text: previous.content,
|
||||
},
|
||||
...current.content,
|
||||
];
|
||||
} else {
|
||||
previous.content += `\n${current.content}`;
|
||||
}
|
||||
}
|
||||
// no need to push the message
|
||||
}
|
||||
// if the roles are different, just push the message
|
||||
else {
|
||||
realResult.push(current);
|
||||
}
|
||||
}
|
||||
|
||||
return realResult as Beta extends true
|
||||
? ToolsBetaMessageParam[]
|
||||
: MessageParam[];
|
||||
}
|
||||
|
||||
chat(
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { BaseEmbedding } from "../embeddings/types.js";
|
||||
import ollama, {
|
||||
type CreateRequest,
|
||||
type ChatResponse as OllamaChatResponse,
|
||||
@@ -5,8 +6,7 @@ import ollama, {
|
||||
type Options,
|
||||
type ProgressResponse,
|
||||
type ShowRequest,
|
||||
} from "ollama/browser";
|
||||
import { BaseEmbedding } from "../embeddings/types.js";
|
||||
} from "../internal/deps/ollama.js";
|
||||
import type {
|
||||
ChatResponse,
|
||||
ChatResponseChunk,
|
||||
|
||||
@@ -106,12 +106,32 @@ export class ChromaVectorStore implements VectorStore {
|
||||
throw new Error("ChromaDB does not support querying by mode");
|
||||
}
|
||||
|
||||
const chromaWhere: { [x: string]: string | number | boolean } = {};
|
||||
// fixme: type is broken
|
||||
let chromaWhere: any = {};
|
||||
if (query.filters?.filters) {
|
||||
query.filters.filters.map((filter) => {
|
||||
const filterKey = filter.key;
|
||||
const filterValue = filter.value;
|
||||
chromaWhere[filterKey] = filterValue;
|
||||
if (filterKey in chromaWhere || "$or" in chromaWhere) {
|
||||
if (!chromaWhere["$or"]) {
|
||||
chromaWhere = {
|
||||
$or: [
|
||||
{
|
||||
...chromaWhere,
|
||||
},
|
||||
{
|
||||
[filterKey]: filterValue,
|
||||
},
|
||||
],
|
||||
};
|
||||
} else {
|
||||
chromaWhere["$or"].push({
|
||||
[filterKey]: filterValue,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
chromaWhere[filterKey] = filterValue;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -130,6 +150,7 @@ export class ChromaVectorStore implements VectorStore {
|
||||
IncludeEnum.Embeddings,
|
||||
],
|
||||
});
|
||||
|
||||
const vectorStoreQueryResult: VectorStoreQueryResult = {
|
||||
nodes: queryResponse.ids[0].map((id, index) => {
|
||||
const text = (queryResponse.documents as string[][])[0][index];
|
||||
|
||||
@@ -250,7 +250,7 @@ export class PGVectorStore implements VectorStore {
|
||||
options?: any,
|
||||
): Promise<VectorStoreQueryResult> {
|
||||
// TODO QUERY TYPES:
|
||||
// Distance: SELECT embedding <-> $1 AS distance FROM items;
|
||||
// Distance: SELECT embedding <=> $1 AS distance FROM items;
|
||||
// Inner Product: SELECT (embedding <#> $1) * -1 AS inner_product FROM items;
|
||||
// Cosine Sim: SELECT 1 - (embedding <=> $1) AS cosine_similarity FROM items;
|
||||
|
||||
@@ -273,7 +273,7 @@ export class PGVectorStore implements VectorStore {
|
||||
|
||||
const sql = `SELECT
|
||||
v.*,
|
||||
embeddings <-> $1 s
|
||||
embeddings <=> $1 s
|
||||
FROM ${this.schemaName}.${this.tableName} v
|
||||
${where}
|
||||
ORDER BY s
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# @llamaindex/core-test
|
||||
|
||||
## 0.0.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- be5df5b: fix: anthropic agent on multiple chat
|
||||
|
||||
## 0.0.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
import { setEnvs } from "@llamaindex/env";
|
||||
import { Anthropic } from "llamaindex";
|
||||
import { beforeAll, describe, expect, test } from "vitest";
|
||||
|
||||
beforeAll(() => {
|
||||
setEnvs({
|
||||
ANTHROPIC_API_KEY: "valid",
|
||||
});
|
||||
});
|
||||
|
||||
describe("Anthropic llm", () => {
|
||||
test("format messages", () => {
|
||||
const anthropic = new Anthropic();
|
||||
expect(
|
||||
anthropic.formatMessages([
|
||||
{
|
||||
content: "You are a helpful assistant.",
|
||||
role: "assistant",
|
||||
},
|
||||
{
|
||||
content: "Hello?",
|
||||
role: "user",
|
||||
},
|
||||
]),
|
||||
).toEqual([
|
||||
{
|
||||
content: "You are a helpful assistant.",
|
||||
role: "assistant",
|
||||
},
|
||||
{
|
||||
content: "Hello?",
|
||||
role: "user",
|
||||
},
|
||||
]);
|
||||
|
||||
expect(
|
||||
anthropic.formatMessages([
|
||||
{
|
||||
content: "You are a helpful assistant.",
|
||||
role: "assistant",
|
||||
},
|
||||
{
|
||||
content: "Hello?",
|
||||
role: "user",
|
||||
},
|
||||
{
|
||||
content: "I am a system message.",
|
||||
role: "system",
|
||||
},
|
||||
{
|
||||
content: "What is your name?",
|
||||
role: "user",
|
||||
},
|
||||
]),
|
||||
).toEqual([
|
||||
{
|
||||
content: "You are a helpful assistant.",
|
||||
role: "assistant",
|
||||
},
|
||||
{
|
||||
content: "Hello?\nWhat is your name?",
|
||||
role: "user",
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/core-test",
|
||||
"private": true,
|
||||
"version": "0.0.2",
|
||||
"version": "0.0.3",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "vitest run"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/edge",
|
||||
"version": "0.3.4",
|
||||
"version": "0.3.6",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
@@ -31,7 +31,6 @@
|
||||
"md-utils-ts": "^2.0.0",
|
||||
"mongodb": "^6.5.0",
|
||||
"notion-md-crawler": "^1.0.0",
|
||||
"ollama": "^0.5.0",
|
||||
"openai": "^4.38.0",
|
||||
"papaparse": "^5.4.1",
|
||||
"pathe": "^1.1.2",
|
||||
|
||||
Vendored
+13
@@ -1,5 +1,18 @@
|
||||
# @llamaindex/env
|
||||
|
||||
## 0.1.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- efa326a: chore: update package.json
|
||||
- efa326a: refactor: remove usage of lodash
|
||||
|
||||
## 0.1.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 5596e31: feat: improve `@llamaindex/env`
|
||||
|
||||
## 0.1.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
# @llamaindex/env
|
||||
|
||||
> Environment wrapper, supports all JS environment including node, deno, bun, edge runtime, and cloudflare worker.
|
||||
|
||||
## LICENSE
|
||||
|
||||
MIT
|
||||
Vendored
+4
-1
@@ -1,8 +1,11 @@
|
||||
{
|
||||
"name": "@llamaindex/env",
|
||||
"version": "0.1.0",
|
||||
"version": "0.1.2",
|
||||
"exports": {
|
||||
".": "./src/index.ts",
|
||||
"./type": "./src/type.ts"
|
||||
},
|
||||
"publish": {
|
||||
"include": ["LICENSE", "README.md", "src/**/*.ts", "jsr.json"]
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+30
-4
@@ -1,10 +1,26 @@
|
||||
{
|
||||
"name": "@llamaindex/env",
|
||||
"description": "environment wrapper",
|
||||
"version": "0.1.0",
|
||||
"description": "environment wrapper, supports all JS environment including node, deno, bun, edge runtime, and cloudflare worker",
|
||||
"version": "0.1.2",
|
||||
"type": "module",
|
||||
"types": "dist/type/index.d.ts",
|
||||
"main": "dist/cjs/index.js",
|
||||
"keywords": [
|
||||
"llm",
|
||||
"llama",
|
||||
"openai",
|
||||
"gpt",
|
||||
"data science",
|
||||
"prompt",
|
||||
"prompt engineering",
|
||||
"chatgpt",
|
||||
"machine learning",
|
||||
"ml",
|
||||
"embedding",
|
||||
"vectorstore",
|
||||
"data framework",
|
||||
"llamaindex"
|
||||
],
|
||||
"exports": {
|
||||
".": {
|
||||
"node": {
|
||||
@@ -67,12 +83,22 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/lodash": "^4.14.202",
|
||||
"@types/node": "^20.12.7",
|
||||
"lodash": "^4.17.21"
|
||||
"@types/node": "^20.12.7"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@aws-crypto/sha256-js": "^5.2.0",
|
||||
"pathe": "^1.1.2",
|
||||
"readable-stream": "^4.5.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@aws-crypto/sha256-js": {
|
||||
"optional": true
|
||||
},
|
||||
"pathe": {
|
||||
"optional": true
|
||||
},
|
||||
"readable-stream": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+7
@@ -1,3 +1,10 @@
|
||||
/**
|
||||
* Polyfill implementation some node.js APIs.
|
||||
*
|
||||
* The code should be compatible with any JS runtime.
|
||||
*
|
||||
* @module
|
||||
*/
|
||||
import { Sha256 } from "@aws-crypto/sha256-js";
|
||||
import pathe from "pathe";
|
||||
import { InMemoryFileSystem, type CompleteFileSystem } from "./type.js";
|
||||
|
||||
Vendored
+13
@@ -1,3 +1,16 @@
|
||||
/**
|
||||
* This module is under Node.js environment.
|
||||
* It provides a set of APIs to interact with the file system, streams, and other Node.js built-in modules.
|
||||
*
|
||||
* Use this under "node" condition,
|
||||
*
|
||||
* For example:
|
||||
* ```shell
|
||||
* node -e "const env = require('@llamaindex/env');"
|
||||
* ```
|
||||
*
|
||||
* @module
|
||||
*/
|
||||
import { ok } from "node:assert";
|
||||
import { createHash, randomUUID } from "node:crypto";
|
||||
import fs from "node:fs/promises";
|
||||
|
||||
Vendored
+7
@@ -1,3 +1,10 @@
|
||||
/**
|
||||
* This module is under Cloudflare Workers environment.
|
||||
*
|
||||
* Most of Node.js APIs are not available in Cloudflare Workers environment.
|
||||
*
|
||||
* @module
|
||||
*/
|
||||
import { INTERNAL_ENV } from "./utils.js";
|
||||
|
||||
export * from "./index.polyfill.js";
|
||||
|
||||
Vendored
+3
-5
@@ -1,5 +1,3 @@
|
||||
import _ from "lodash";
|
||||
|
||||
/**
|
||||
* A filesystem interface that is meant to be compatible with
|
||||
* the 'fs' module from Node.js.
|
||||
@@ -41,14 +39,14 @@ export class InMemoryFileSystem implements CompleteFileSystem {
|
||||
content: string,
|
||||
options?: unknown,
|
||||
): Promise<void> {
|
||||
this.files[path] = _.cloneDeep(content);
|
||||
this.files[path] = structuredClone(content);
|
||||
}
|
||||
|
||||
async readFile(path: string): Promise<string> {
|
||||
if (!(path in this.files)) {
|
||||
throw new Error(`File ${path} does not exist`);
|
||||
}
|
||||
return _.cloneDeep(this.files[path]);
|
||||
return structuredClone(this.files[path]);
|
||||
}
|
||||
|
||||
async access(path: string): Promise<void> {
|
||||
@@ -58,7 +56,7 @@ export class InMemoryFileSystem implements CompleteFileSystem {
|
||||
}
|
||||
|
||||
async mkdir(path: string): Promise<undefined> {
|
||||
this.files[path] = _.get(this.files, path, null);
|
||||
this.files[path] = this.files[path] ?? null;
|
||||
}
|
||||
|
||||
async readdir(path: string): Promise<string[]> {
|
||||
|
||||
Vendored
+24
@@ -1,6 +1,30 @@
|
||||
// DO NOT EXPOSE THIS VARIABLE TO PUBLIC, IT IS USED INTERNALLY FOR CLOUDFLARE WORKER
|
||||
export const INTERNAL_ENV: Record<string, string> = {};
|
||||
|
||||
/**
|
||||
* Set environment variables before using llamaindex, because some LLM need to access API key before running.
|
||||
*
|
||||
* You have to set the environment variables in Cloudflare Worker environment,
|
||||
* because it doesn't have any global environment variables.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* export default {
|
||||
* async fetch(
|
||||
* request: Request,
|
||||
* env: Env,
|
||||
* ctx: ExecutionContext,
|
||||
* ): Promise<Response> {
|
||||
* const { setEnvs } = await import("@llamaindex/env");
|
||||
* setEnvs(env);
|
||||
* // ...
|
||||
* return new Response("Hello, World!");
|
||||
* },
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* @param envs Environment variables
|
||||
*/
|
||||
export function setEnvs(envs: object): void {
|
||||
Object.assign(INTERNAL_ENV, envs);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,23 @@
|
||||
# @llamaindex/experimental
|
||||
|
||||
## 0.0.23
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [efa326a]
|
||||
- llamaindex@0.3.6
|
||||
|
||||
## 0.0.22
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [bc7a11c]
|
||||
- Updated dependencies [2fe2b81]
|
||||
- Updated dependencies [5596e31]
|
||||
- Updated dependencies [e74fe88]
|
||||
- Updated dependencies [be5df5b]
|
||||
- llamaindex@0.3.5
|
||||
|
||||
## 0.0.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/experimental",
|
||||
"description": "Experimental package for LlamaIndexTS",
|
||||
"version": "0.0.21",
|
||||
"version": "0.0.23",
|
||||
"type": "module",
|
||||
"types": "dist/type/index.d.ts",
|
||||
"main": "dist/cjs/index.js",
|
||||
|
||||
Generated
-16
@@ -271,9 +271,6 @@ importers:
|
||||
notion-md-crawler:
|
||||
specifier: ^1.0.0
|
||||
version: 1.0.0(encoding@0.1.13)
|
||||
ollama:
|
||||
specifier: ^0.5.0
|
||||
version: 0.5.0
|
||||
openai:
|
||||
specifier: ^4.38.0
|
||||
version: 4.38.1(encoding@0.1.13)
|
||||
@@ -567,9 +564,6 @@ importers:
|
||||
notion-md-crawler:
|
||||
specifier: ^1.0.0
|
||||
version: 1.0.0(encoding@0.1.13)
|
||||
ollama:
|
||||
specifier: ^0.5.0
|
||||
version: 0.5.0
|
||||
openai:
|
||||
specifier: ^4.38.0
|
||||
version: 4.38.1(encoding@0.1.13)
|
||||
@@ -634,9 +628,6 @@ importers:
|
||||
'@types/node':
|
||||
specifier: ^20.12.7
|
||||
version: 20.12.7
|
||||
lodash:
|
||||
specifier: ^4.17.21
|
||||
version: 4.17.21
|
||||
devDependencies:
|
||||
'@aws-crypto/sha256-js':
|
||||
specifier: ^5.2.0
|
||||
@@ -7118,9 +7109,6 @@ packages:
|
||||
obuf@1.1.2:
|
||||
resolution: {integrity: sha512-PX1wu0AmAdPqOL1mWhqmlOd8kOIZQwGZw6rh7uby9fTc5lhaOWFLX3I6R1hrF9k3zUY40e6igsLGkDXK92LJNg==}
|
||||
|
||||
ollama@0.5.0:
|
||||
resolution: {integrity: sha512-CRtRzsho210EGdK52GrUMohA2pU+7NbgEaBG3DcYeRmvQthDO7E2LHOkLlUUeaYUlNmEd8icbjC02ug9meSYnw==}
|
||||
|
||||
on-finished@2.4.1:
|
||||
resolution: {integrity: sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==}
|
||||
engines: {node: '>= 0.8'}
|
||||
@@ -17688,10 +17676,6 @@ snapshots:
|
||||
|
||||
obuf@1.1.2: {}
|
||||
|
||||
ollama@0.5.0:
|
||||
dependencies:
|
||||
whatwg-fetch: 3.6.20
|
||||
|
||||
on-finished@2.4.1:
|
||||
dependencies:
|
||||
ee-first: 1.1.1
|
||||
|
||||
@@ -26,7 +26,10 @@ if (minorVersion !== expectedMinorVersion) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const packages = ["core", "env"];
|
||||
const packages = ["env", "core"];
|
||||
const envPackageJson = JSON.parse(
|
||||
fs.readFileSync("./packages/env/package.json", "utf8"),
|
||||
);
|
||||
for (const pkg of packages) {
|
||||
const packageJson = JSON.parse(
|
||||
fs.readFileSync(`./packages/${pkg}/package.json`, "utf8"),
|
||||
@@ -36,6 +39,10 @@ for (const pkg of packages) {
|
||||
);
|
||||
|
||||
jsrJson.version = packageJson.version;
|
||||
if (pkg === "core") {
|
||||
jsrJson.imports["@llamaindex/env"] =
|
||||
`jsr:@llamaindex/env@${envPackageJson.version}`;
|
||||
}
|
||||
|
||||
fs.writeFileSync(
|
||||
`./packages/${pkg}/jsr.json`,
|
||||
|
||||
@@ -35,6 +35,9 @@
|
||||
{
|
||||
"path": "./packages/core/e2e/examples/nextjs-edge-runtime/tsconfig.json"
|
||||
},
|
||||
{
|
||||
"path": "./packages/core/e2e/examples/waku-query-engine/tsconfig.json"
|
||||
},
|
||||
{
|
||||
"path": "./packages/core/tests/tsconfig.json"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user