Compare commits

...

38 Commits

Author SHA1 Message Date
github-actions[bot] 456d3fb0b3 Release 0.3.6 (#810)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-05-05 18:40:58 -05:00
Alex Yang efa326a871 chore: update package.json and usage of lodash (#809) 2024-05-05 18:30:46 -05:00
Alex Yang 5765b637ce build: fix jsr release 2024-05-03 18:21:08 -05:00
github-actions[bot] 72687b4f69 Release 0.3.5 (#805)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-05-03 18:16:39 -05:00
Alex Yang 0c67e1f8f3 build: fix new version script 2024-05-03 18:13:24 -05:00
Alex Yang 4a0619758a chore: fix jsr.json 2024-05-03 18:09:05 -05:00
Alex Yang bc7a11cdbe fix: inline ollama build (#807) 2024-05-03 18:03:23 -05:00
Alex Yang 5596e31947 feat: improve @llamaindex/env (#787) 2024-05-03 18:03:14 -05:00
Alex Yang 2fe2b813ba fix: filter with multiple filters in ChromaDB (#784) 2024-05-03 17:07:45 -05:00
Alex Yang be5df5b01b fix(core): multple chat on anthropic agent (#799) 2024-05-03 16:18:46 -05:00
JT-Dev-215 e74fe88342 fix: change <-> to <=> in the SELECT query (#804)
Co-authored-by: Alex Yang <himself65@outlook.com>
2024-05-03 12:10:36 -05:00
github-actions[bot] f1862ccab1 Release 0.3.4 (#797)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-05-02 20:02:06 -05:00
Yi Ding 9e74a4327f feat: add top k to asQueryEngine (#801)
Co-authored-by: Alex Yang <himself65@outlook.com>
2024-05-02 19:59:36 -05:00
Alex Yang 5e61934d5a fix: remove clone object in CallbackManager.dispatchEvent (#802) 2024-05-02 19:55:41 -05:00
Alex Yang 2008efe0ee feat: add verbose mode to Agent (#800) 2024-05-02 19:54:05 -05:00
Alex Yang ee719a1fda fix: streaming for ReAct Agent (#798) 2024-05-02 18:52:18 -05:00
Alex Yang 1dce275a7c fix: export StorageContext on edge runtime (#793) 2024-05-02 14:52:16 -05:00
Thuc Pham d10533ef77 feat: add hugging face llm (#796) 2024-05-02 18:43:05 +08:00
github-actions[bot] 8aeb8ae690 Release 0.3.3 (#792)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-05-01 21:47:16 -05:00
Thuc Pham e8c41c5c27 fix: wrong gemini streaming chat response (#791) 2024-05-02 08:39:57 +07:00
github-actions[bot] 051b4ddfa2 Release 0.3.2 (#790)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-05-01 19:30:09 -05:00
Alex Yang 61103b677b fix: streaming for Agent.createTask (#788) 2024-05-01 19:26:06 -05:00
Alex Yang e69cac672a docs: update blog post 2024-05-01 13:01:55 -05:00
Alex Yang 94246a3ca8 chore: bump jsr.json 2024-05-01 12:59:03 -05:00
github-actions[bot] b440a008e5 Release 0.3.1 (#786)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-05-01 12:39:37 -05:00
Alex Yang 46227f2a70 fix: build error on next.js nodejs runtime (#785) 2024-05-01 12:37:43 -05:00
Alex Yang 77f0298f6f chore: update jsr.json 2024-04-30 22:47:09 -05:00
github-actions[bot] c14e112236 Release 0.3.0 (#783)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-04-30 22:46:10 -05:00
Alex Yang 62b035fdc1 build: fix test package naming 2024-04-30 22:42:06 -05:00
Alex Yang aa0be1469b build: update expectedMinorVersion 2024-04-30 22:37:14 -05:00
Alex Yang 5016f21d52 feat(core): better next.js/cloudflare/vite support 2024-04-30 22:34:54 -05:00
Marcus Schiesser 130b7992a1 refactor: clean gemini embedding (#781) 2024-04-30 10:51:22 +07:00
Yi Ding 0d50b22dbf fix(core): add more exports on llm/index (#780) 2024-04-28 20:43:14 -05:00
Alex Yang db1d1f57c9 build(wasm-tools): fix type check 2024-04-28 20:29:01 -05:00
Alex Yang dccb8163d8 fix(core): polyfill Web Stream APIs (#777) 2024-04-28 18:35:33 -05:00
Fabian Wimmer 1ab3ba407e feat: add Language and parsingInstruction to LlamaParseReader (#779)
Co-authored-by: Alex Yang <himself65@outlook.com>
2024-04-28 17:00:58 -05:00
Alex Yang b03f765733 chore: update husky script (#776) 2024-04-27 01:10:34 -05:00
Alex Yang 7488d3c235 fix: agent callback with step infomation (#774) 2024-04-26 18:13:05 -05:00
159 changed files with 9591 additions and 2637 deletions
+14 -6
View File
@@ -84,9 +84,16 @@ jobs:
name: typecheck-build-dist
path: ./packages/core/dist
if-no-files-found: error
core-edge-runtime:
e2e-core-examples:
strategy:
matrix:
packages:
- cloudflare-worker-agent
- nextjs-agent
- nextjs-edge-runtime
- waku-query-engine
runs-on: ubuntu-latest
name: Build Core Example (${{ matrix.packages }})
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
@@ -97,11 +104,12 @@ jobs:
cache: "pnpm"
- name: Install dependencies
run: pnpm install
- name: Build
run: pnpm run build --filter @llamaindex/edge
- name: Build Edge Runtime
- name: Build llamaindex
run: pnpm run build --filter llamaindex
- name: Build ${{ matrix.packages }}
run: pnpm run build
working-directory: ./packages/edge/e2e/test-edge-runtime
working-directory: packages/core/e2e/examples/${{ matrix.packages }}
typecheck-examples:
runs-on: ubuntu-latest
+1 -1
View File
@@ -1,3 +1,3 @@
pnpm format
pnpm format:write
pnpm lint
npx lint-staged
-1
View File
@@ -1 +0,0 @@
pnpm test
+1 -1
View File
@@ -1 +1 @@
18
20
+129 -79
View File
@@ -19,25 +19,29 @@ Try examples online:
LlamaIndex.TS aims to be a lightweight, easy to use set of libraries to help you integrate large language models into your applications with your own data.
## Getting started with an example:
## Multiple JS Environment Support
LlamaIndex.TS requires Node v18 or higher. You can download it from https://nodejs.org or use https://nvm.sh (our preferred option).
LlamaIndex.TS supports multiple JS environments, including:
In a new folder:
- Node.js (18, 20, 22) ✅
- Deno ✅
- Bun ✅
- React Server Components (Next.js) ✅
```bash
export OPENAI_API_KEY="sk-......" # Replace with your key from https://platform.openai.com/account/api-keys
pnpm init
pnpm install typescript
pnpm exec tsc --init # if needed
For now, browser support is limited due to the lack of support for [AsyncLocalStorage-like APIs](https://github.com/tc39/proposal-async-context)
## Getting started
```shell
npm install llamaindex
pnpm install llamaindex
pnpm install @types/node
yarn add llamaindex
jsr install @llamaindex/core
```
Create the file example.ts
### Node.js
```ts
// example.ts
import fs from "fs/promises";
import { Document, VectorStoreIndex } from "llamaindex";
@@ -67,10 +71,110 @@ async function main() {
main();
```
Then you can run it using
```bash
pnpm dlx ts-node example.ts
# `pnpm install tsx` before running the script
node --import tsx ./main.ts
```
### Next.js
You can combine `ai` with `llamaindex` in Next.js with RSC (React Server Components).
```tsx
// src/apps/page.tsx
"use client";
import { chatWithAgent } from "@/actions";
import type { JSX } from "react";
import { useFormState } from "react-dom";
// You can use the Edge runtime in Next.js by adding this line:
// export const runtime = "edge";
export default function Home() {
const [ui, action] = useFormState<JSX.Element | null>(async () => {
return chatWithAgent("hello!", []);
}, null);
return (
<main>
{ui}
<form action={action}>
<button>Chat</button>
</form>
</main>
);
}
```
```tsx
// src/actions/index.ts
"use server";
import { createStreamableUI } from "ai/rsc";
import { OpenAIAgent } from "llamaindex";
import type { ChatMessage } from "llamaindex/llm/types";
export async function chatWithAgent(
question: string,
prevMessages: ChatMessage[] = [],
) {
const agent = new OpenAIAgent({
tools: [
// ... adding your tools here
],
});
const responseStream = await agent.chat({
stream: true,
message: question,
chatHistory: prevMessages,
});
const uiStream = createStreamableUI(<div>loading...</div>);
responseStream
.pipeTo(
new WritableStream({
start: () => {
uiStream.update("response:");
},
write: async (message) => {
uiStream.append(message.response.delta);
},
}),
)
.catch(console.error);
return uiStream.value;
}
```
### Cloudflare Workers
```ts
// src/index.ts
export default {
async fetch(
request: Request,
env: Env,
ctx: ExecutionContext,
): Promise<Response> {
const { setEnvs } = await import("@llamaindex/env");
// set environment variables so that the OpenAIAgent can use them
setEnvs(env);
const { OpenAIAgent } = await import("llamaindex");
const agent = new OpenAIAgent({
tools: [],
});
const responseStream = await agent.chat({
stream: true,
message: "Hello? What is the weather today?",
});
const textEncoder = new TextEncoder();
const response = responseStream.pipeThrough(
new TransformStream({
transform: (chunk, controller) => {
controller.enqueue(textEncoder.encode(chunk.response.delta));
},
}),
);
return new Response(response);
},
};
```
## Playground
@@ -93,79 +197,25 @@ Check out our NextJS playground at https://llama-playground.vercel.app/. The sou
- [SimplePrompt](/packages/core/src/Prompt.ts): A simple standardized function call definition that takes in inputs and formats them in a template literal. SimplePrompts can be specialized using currying and combined using other SimplePrompt functions.
## Using NextJS
## Tips when using in non-Node.js environments
If you're using the NextJS App Router, you can choose between the Node.js and the [Edge runtime](https://nextjs.org/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes#edge-runtime).
When you are importing `llamaindex` in a non-Node.js environment(such as React Server Components, Cloudflare Workers, etc.)
Some classes are not exported from top-level entry file.
With NextJS 13 and 14, using the Node.js runtime is the default. You can explicitly set the Edge runtime in your [router handler](https://nextjs.org/docs/app/building-your-application/routing/route-handlers) by adding this line:
The reason is that some classes are only compatible with Node.js runtime,(e.g. `PDFReader`) which uses Node.js specific APIs(like `fs`, `child_process`, `crypto`).
If you need any of those classes, you have to import them instead directly though their file path in the package.
Here's an example for importing the `PineconeVectorStore` class:
```typescript
export const runtime = "edge";
```
The following sections explain further differences in using the Node.js or Edge runtime.
### Using the Node.js runtime
Add the following config to your `next.config.js` to ignore specific packages in the server-side bundling:
```js
// next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
serverComponentsExternalPackages: [
"pdf2json",
"@zilliz/milvus2-sdk-node",
"sharp",
"onnxruntime-node",
],
},
webpack: (config) => {
config.externals.push({
pdf2json: "commonjs pdf2json",
"@zilliz/milvus2-sdk-node": "commonjs @zilliz/milvus2-sdk-node",
sharp: "commonjs sharp",
"onnxruntime-node": "commonjs onnxruntime-node",
});
return config;
},
};
module.exports = nextConfig;
```
### Using the Edge runtime
We publish a dedicated package (`@llamaindex/edge` instead of `llamaindex`) for using the Edge runtime. To use it, first install the package:
```shell
pnpm install @llamaindex/edge
```
> _Note_: Ensure that your `package.json` doesn't include the `llamaindex` package if you're using `@llamaindex/edge`.
Then make sure to use the correct import statement in your code:
```typescript
// replace 'llamaindex' with '@llamaindex/edge'
import {} from "@llamaindex/edge";
```
A further difference is that the `@llamaindex/edge` package doesn't export classes from the `readers` or `storage` folders. The reason is that most of these classes are not compatible with the Edge runtime.
If you need any of those classes, you have to import them instead directly. Here's an example for importing the `PineconeVectorStore` class:
```typescript
import { PineconeVectorStore } from "@llamaindex/edge/storage/vectorStore/PineconeVectorStore";
import { PineconeVectorStore } from "llamaindex/storage/vectorStore/PineconeVectorStore";
```
As the `PDFReader` is not working with the Edge runtime, here's how to use the `SimpleDirectoryReader` with the `LlamaParseReader` to load PDFs:
```typescript
import { SimpleDirectoryReader } from "@llamaindex/edge/readers/SimpleDirectoryReader";
import { LlamaParseReader } from "@llamaindex/edge/readers/LlamaParseReader";
import { SimpleDirectoryReader } from "llamaindex/readers/SimpleDirectoryReader";
import { LlamaParseReader } from "llamaindex/readers/LlamaParseReader";
export const DATA_DIR = "./data";
@@ -183,7 +233,7 @@ export async function getDocuments() {
> _Note_: Reader classes have to be added explictly to the `fileExtToReader` map in the Edge version of the `SimpleDirectoryReader`.
You'll find a complete example of using the Edge runtime with LlamaIndexTS here: https://github.com/run-llama/create_llama_projects/tree/main/nextjs-edge-llamaparse
You'll find a complete example with LlamaIndexTS here: https://github.com/run-llama/create_llama_projects/tree/main/nextjs-edge-llamaparse
## Supported LLMs:
+58
View File
@@ -1,5 +1,63 @@
# 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
- Updated dependencies [1dce275]
- Updated dependencies [d10533e]
- Updated dependencies [2008efe]
- Updated dependencies [5e61934]
- Updated dependencies [9e74a43]
- Updated dependencies [ee719a1]
- llamaindex@0.3.4
## 0.0.11
### Patch Changes
- Updated dependencies [e8c41c5]
- llamaindex@0.3.3
## 0.0.10
### Patch Changes
- Updated dependencies [61103b6]
- llamaindex@0.3.2
## 0.0.9
### Patch Changes
- Updated dependencies [46227f2]
- llamaindex@0.3.1
## 0.0.8
### Patch Changes
- Updated dependencies [5016f21]
- llamaindex@0.3.0
## 0.0.7
### Patch Changes
+493
View File
@@ -0,0 +1,493 @@
---
title: LlamaIndexTS v0.3.0
description: This is my first post on Docusaurus.
slug: welcome-llamaindexts-v0.3
authors:
- name: Alex Yang
title: LlamaIndexTS maintainer, Node.js Member
url: https://github.com/himself65
image_url: https://github.com/himself65.png
tags: [llamaindex, agent]
hide_table_of_contents: false
---
- [What's new in LlamaIndexTS v0.3.0](#whats-new-in-llamaindexts-v030)
- [Improvement in LlamaIndexTS v0.3.0](#improvement-in-llamaindexts-v030)
- [What's the next?](#whats-the-next)
## What's new in LlamaIndexTS v0.3.0
## Agents
In this release, we've not only ported the Agent module from the LlamaIndex Python version but have significantly
enhanced it to be more powerful and user-friendly for JavaScript/TypeScript applications.
Starting from v0.3.0, we are introducing multiple agents specifically designed for RAG applications, including:
- `OpenAIAgent`
- `AnthropicAgent`
- `ReActAgent`:
```ts
import { OpenAIAgent } from "llamaindex";
import { tools } from "./tools";
const agent = new OpenAIAgent({
tools: [...tools],
});
const { response } = await agent.chat({
message: "What is weather today?",
stream: false,
});
console.log(response.message.content);
```
We are also introducing the abstract AgentRunner class, which allows you to create your own agent by simply implementing
the task handler.
```ts
import { AgentRunner, OpenAI } from "llamaindex";
class MyLLM extends OpenAI {}
export class MyAgentWorker extends AgentWorker<MyLLM> {
taskHandler = MyAgent.taskHandler;
}
export class MyAgent extends AgentRunner<MyLLM> {
constructor(params: Params) {
super({
llm: params.llm,
chatHistory: params.chatHistory ?? [],
systemPrompt: params.systemPrompt ?? null,
runner: new MyAgentWorker(),
tools:
"tools" in params
? params.tools
: params.toolRetriever.retrieve.bind(params.toolRetriever),
});
}
// create store is a function to create a store for each task, by default it only includes `messages` and `toolOutputs`
createStore = AgentRunner.defaultCreateStore;
static taskHandler: TaskHandler<Anthropic> = async (step, enqueueOutput) => {
const { llm, stream } = step.context;
// initialize the input
const response = await llm.chat({
stream,
messages: step.context.store.messages,
});
// store the response for next task step
step.context.store.messages = [
...step.context.store.messages,
response.message,
];
// your logic here to decide whether to continue the task
const shouldContinue = Math.random(); /* <-- replace with your logic here */
enqueueOutput({
taskStep: step,
output: response,
isLast: !shouldContinue,
});
if (shouldContinue) {
const content = await someHeavyFunctionCall();
// if you want to continue the task, you can insert your new context for the next task step
step.context.store.messages = [
...step.context.store.messages,
{
content,
role: "user",
},
];
}
};
}
```
### Web Stream API for Streaming response
Web Stream is a web standard utilized in many modern web frameworks and libraries (like React 19, Deno, Node 22). We
have migrated streaming responses to Web Stream to ensure broader compatibility.
For instance, you can use the streaming response in a simple HTTP Server:
```ts
import { createServer } from "http";
import { OpenAIAgent } from "llamaindex";
import { OpenAIStream, streamToResponse } from "ai";
import { tools } from "./tools";
const agent = new OpenAIAgent({
tools: [...tools],
});
const server = createServer(async (req, res) => {
const response = await agent.chat({
message: "What is weather today?",
stream: true,
});
// Transform the response into a string readable stream
const stream: ReadableStream<string> = response.pipeThrough(
new TransformStream({
transform: (chunk, controller) => {
controller.enqueue(chunk.response.delta);
},
}),
);
// Pipe the stream to the response
streamToResponse(stream, res);
});
server.listen(3000);
```
Or it can be integrated into React Server Components (RSC) in Next.js:
```tsx
// app/actions/index.tsx
"use server";
import { createStreamableUI } from "ai/rsc";
import { OpenAIAgent } from "llamaindex";
import type { ChatMessage } from "llamaindex/llm/types";
export async function chatWithAgent(
question: string,
prevMessages: ChatMessage[] = [],
) {
const agent = new OpenAIAgent({
tools: [],
});
const responseStream = await agent.chat({
stream: true,
message: question,
chatHistory: prevMessages,
});
const uiStream = createStreamableUI(<div>loading...</div>);
responseStream
.pipeTo(
new WritableStream({
start: () => {
uiStream.update("response:");
},
write: async (message) => {
uiStream.append(message.response.delta);
},
}),
)
.catch(uiStream.error);
return uiStream.value;
}
```
```tsx
// app/src/page.tsx
"use client";
import { chatWithAgent } from "@/actions";
import type { JSX } from "react";
import { useFormState } from "react-dom";
export const runtime = "edge";
export default function Home() {
const [state, action] = useFormState<JSX.Element | null>(async () => {
return chatWithAgent("hello!", []);
}, null);
return (
<main>
{state}
<form action={action}>
<button>Chat</button>
</form>
</main>
);
}
```
## Improvement in LlamaIndexTS v0.3.0
### Better TypeScript support
We have made significant improvements to the type system to ensure that all code is thoroughly checked before it is
published. This ongoing enhancement has already resulted in better module reliability and developer experience.
For example, we have improved `FunctionTool` type with generic support:
```ts
type Input = {
a: number;
b: number;
};
const sumNumbers = FunctionTool.from<Input>(
({ a, b }) => `${a + b}`, // a and b will be checked as number
// JSON schema will be an error if you type wrong.
{
name: "sumNumbers",
description: "Use this function to sum two numbers",
parameters: {
type: "object",
properties: {
a: {
type: "number",
description: "The first number",
},
b: {
type: "number",
description: "The second number",
},
},
required: ["a", "b"],
},
},
);
```
![type checking](./img/function_tool_example.png)
### Better Next.js, Deno, Cloudflare Worker, and Waku(Vite) support
In addition to Node.js, LlamaIndexTS now offers enhanced support for Next.js, Deno, and Cloudflare Workers, making it
more versatile across different platforms.
For now, you can install llamaindex and directly import it into your existing Next.js, Deno or Cloudflare Worker project
**without any extra configuration**.
#### [Deno](https://deno.com/)
You can use LlamaIndexTS in Deno by installation through JSR:
```sh
jsr add @llamaindex/core
```
#### [Cloudflare Worker](https://developers.cloudflare.com/workers/)
For Cloudflare Workers, here is a starter template:
```typescript
export default {
async fetch(
request: Request,
env: Env,
ctx: ExecutionContext,
): Promise<Response> {
const { setEnvs } = await import("@llamaindex/env");
setEnvs(env);
const { OpenAIAgent } = await import("llamaindex");
const agent = new OpenAIAgent({
tools: [],
});
const responseStream = await agent.chat({
stream: true,
message: "Hello? What is the weather today?",
});
const textEncoder = new TextEncoder();
const response = responseStream.pipeThrough(
new TransformStream({
transform: (chunk, controller) => {
controller.enqueue(textEncoder.encode(chunk.response.delta));
},
}),
);
return new Response(response);
},
};
```
### [Waku (Vite)](https://waku.gg/)
Waku powered by Vite is a minimal React framework that supports multiple JS environments, including Deno, Cloudflare, and
Node.js.
You can use LlamaIndexTS with Node.js output to enable full Node.js support with React.
```sh
npm install llamaindex
```
```ts
// file: src/actions.ts
"use server";
import { Document, VectorStoreIndex } from "llamaindex";
import { readFile } from "node:fs/promises";
const path = "node_modules/llamaindex/examples/abramov.txt";
const essay = await 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]);
const queryEngine = index.asQueryEngine();
export async function chatWithAI(question: string): Promise<string> {
const { response } = await queryEngine.query({ query: question });
return response;
}
```
```tsx
// file: src/pages/index.tsx
import { chatWithAI } from "./actions";
export default async function HomePage() {
return (
<div>
<Chat askQuestion={chatWithAI} />
</div>
);
}
```
```tsx
// file: src/components/Chat.tsx
"use client";
export type ChatProps = {
askQuestion: (question: string) => Promise<string>;
};
export const Chat = (props: ChatProps) => {
const [response, setResponse] = useState<string | null>(null);
return (
<section className="border-blue-400 -mx-4 mt-4 rounded border border-dashed p-4">
<h2 className="text-lg font-bold">Chat with AI</h2>
{response ? (
<p className="text-sm text-gray-600 max-w-sm">{response}</p>
) : null}
<form
action={async (formData) => {
const question = formData.get("question") as string | null;
if (question) {
setResponse(await props.askQuestion(question));
}
}}
>
<input
type="text"
name="question"
className="border border-gray-400 rounded-sm px-2 py-0.5 text-sm"
/>
<button className="rounded-sm bg-black px-2 py-0.5 text-sm text-white">
Ask
</button>
</form>
</section>
);
};
```
```shell
waku dev # development mode
waku build # build for production
waku start # start the production server
```
Note that not all the modules are supported in all JS environments because of
lack of the file system, network API,
and incompatibility with the Node.js API by upstream dependencies.
But we are trying to make it more compatible with all the environments.
## What's the next?
As we continue to develop LlamaIndexTS, our focus remains on providing more comprehensive and powerful tools for
creating custom agents.
### Align with the Python `llama-index`
We aim to align LlamaIndexTS with the Python version to ensure API consistency and ease of use for developers familiar
with the Python ecosystem.
### Align with the Web Standard and JS development
Not all python APIs are compatible and easy to use in JavaScript/TypeScript.
We are trying to make the API more compatible with the Web Standard and JavaScript modern development.
### More Agents
Future releases will introduce more agents from the Python Llama-Index and explore APIs tailored to real-world use
cases.
### 🧪 `@llamaindex/tool`
We are exploring innovative ways to create tools for agents. The `@llamaindex/tool` library allows you to transform any
function into a tool for an agent, simplifying the development process and reducing runtime costs.
```ts
export function getWeather(city: string) {
return `The weather in ${city} is sunny.`;
}
// you don't need to worry about the shcema with different llm tools
export function getTemperature(city: string) {
return `The temperature in ${city} is 25°C.`;
}
export function getCurrentCity() {
return "New York";
}
```
These functions can be easily integrated into your applications, such as Next.js:
```ts
"use server";
import { OpenAI } from "openai";
import { getTools } from "@llamaindex/tool";
export async function chat(message: string) {
const openai = new OpenAI();
openai.chat.completions.create({
messages: [
{
role: "user",
content: "What is the weather in the current city?",
},
],
tools: getTools("openai"),
});
}
```
```ts
// next.config.js
const withTool = require("@llamaindex/tool/next");
const config = {
// Your original Next.js config
};
module.exports = withTool(config);
```
The functions are automatically transformed into tools for the agent at compile time, which eliminates any extra runtime
costs. This feature is particularly beneficial when you need to debug or deploy your assistant.
For deploying your local functions into OpenAI, you can use a simple command:
```sh
npm install -g @llamaindex/tool
mkai --tools ./src/index.llama.ts
# Successfully created assistant: asst_XXX
# chat with your assistant by `chatai --assistant asst_XXX`
chatai --assistant asst_XXX
# Open your browser and chat with your assistant
# Running at http://localhost:3000
```
This deployment process simplifies the testing and implementation of your custom tools in a live environment.
As this project is still in its early stages, we continue to explore the best ways to create and integrate tools for
agents. For more information and updates, visit the @llamaindex/tool repository.
This release of LlamaIndexTS v0.3.0 marks a significant step forward in our journey to provide developers with robust,
flexible tools for building advanced agents. We are excited to see how our community utilizes these new capabilities to
create innovative solutions and look forward to continuing to support and enhance LlamaIndexTS in future updates.
Binary file not shown.

After

Width:  |  Height:  |  Size: 178 KiB

+6 -1
View File
@@ -66,7 +66,11 @@ const config = {
[require("@docusaurus/remark-plugin-npm2yarn"), { sync: true }],
],
},
blog: false,
blog: {
blogTitle: "LlamaIndexTS blog",
blogDescription: "The official blog of LlamaIndexTS",
postsPerPage: "ALL",
},
gtag: {
trackingID: "G-NB9B8LW9W5",
anonymizeIP: true,
@@ -97,6 +101,7 @@ const config = {
type: "localeDropdown",
position: "left",
},
{ to: "blog", label: "Blog", position: "right" },
{
href: "https://github.com/run-llama/LlamaIndexTS",
label: "GitHub",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "docs",
"version": "0.0.7",
"version": "0.0.14",
"private": true,
"scripts": {
"docusaurus": "docusaurus",
+1
View File
@@ -0,0 +1 @@
DEBUG=llamaindex
+39
View File
@@ -0,0 +1,39 @@
import { ChatResponseChunk, OpenAIAgent } from "llamaindex";
import { ReadableStream } from "node:stream/web";
import {
getCurrentIDTool,
getUserInfoTool,
getWeatherTool,
} from "./utils/tools";
async function main() {
// Create an OpenAIAgent with the function tools
const agent = new OpenAIAgent({
tools: [getCurrentIDTool, getUserInfoTool, getWeatherTool],
});
const task = await agent.createTask(
"What is my current address weather based on my profile?",
true,
);
for await (const stepOutput of task) {
const stream = stepOutput.output as ReadableStream<ChatResponseChunk>;
if (stepOutput.isLast) {
for await (const chunk of stream) {
process.stdout.write(chunk.delta);
}
process.stdout.write("\n");
} else {
// handing function call
console.log("handling function call...");
for await (const chunk of stream) {
console.log("debug:", JSON.stringify(chunk.raw));
}
}
}
}
void main().then(() => {
console.log("Done");
});
+1 -1
View File
@@ -53,7 +53,7 @@ async function main() {
message: "How much is 5 + 5? then divide by 2",
});
console.log(String(response));
console.log(response.response.message);
}
void main().then(() => {
+40
View File
@@ -0,0 +1,40 @@
import { ChatResponseChunk, ReActAgent } from "llamaindex";
import { ReadableStream } from "node:stream/web";
import {
getCurrentIDTool,
getUserInfoTool,
getWeatherTool,
} from "./utils/tools";
async function main() {
// Create an OpenAIAgent with the function tools
const agent = new ReActAgent({
tools: [getCurrentIDTool, getUserInfoTool, getWeatherTool],
});
const task = await agent.createTask(
"What is my current address weather based on my profile?",
true,
);
for await (const stepOutput of task) {
const stream = stepOutput.output as ReadableStream<ChatResponseChunk>;
if (stepOutput.isLast) {
for await (const chunk of stream) {
process.stdout.write(chunk.delta);
}
process.stdout.write("\n");
} else {
// handing function call
console.log("handling function call...");
for await (const chunk of stream) {
console.log("debug:", JSON.stringify(chunk.raw));
}
}
console.log("---");
}
}
void main().then(() => {
console.log("Done");
});
-83
View File
@@ -1,83 +0,0 @@
import { FunctionTool, OpenAIAgent } from "llamaindex";
// Define a function to sum two numbers
function sumNumbers({ a, b }: { a: number; b: number }) {
return `${a + b}`;
}
// Define a function to divide two numbers
function divideNumbers({ a, b }: { a: number; b: number }) {
return `${a / b}`;
}
// Define the parameters of the sum function as a JSON schema
const sumJSON = {
type: "object",
properties: {
a: {
type: "number",
description: "The first number",
},
b: {
type: "number",
description: "The second number",
},
},
required: ["a", "b"],
} as const;
const divideJSON = {
type: "object",
properties: {
a: {
type: "number",
description: "The dividend",
},
b: {
type: "number",
description: "The divisor",
},
},
required: ["a", "b"],
} as const;
async function main() {
// Create a function tool from the sum function
const functionTool = new FunctionTool(sumNumbers, {
name: "sumNumbers",
description: "Use this function to sum two numbers",
parameters: sumJSON,
});
// Create a function tool from the divide function
const functionTool2 = new FunctionTool(divideNumbers, {
name: "divideNumbers",
description: "Use this function to divide two numbers",
parameters: divideJSON,
});
// Create an OpenAIAgent with the function tools
const agent = new OpenAIAgent({
tools: [functionTool, functionTool2],
});
// Create a task to sum and divide numbers
const task = await agent.createTask("How much is 5 + 5? then divide by 2");
let count = 0;
for await (const stepOutput of task) {
console.log(`Runnning step ${count++}`);
console.log(`======== OUTPUT ==========`);
console.log(stepOutput.output.message.content);
console.log(`==========================`);
if (stepOutput.isLast) {
console.log(stepOutput.output.message.content);
}
}
}
void main().then(() => {
console.log("Done");
});
+6 -2
View File
@@ -66,8 +66,12 @@ async function main() {
stream: true,
});
for await (const chunk of stream.response) {
process.stdout.write(chunk.response);
console.log("Response:");
for await (const {
response: { delta },
} of stream) {
process.stdout.write(delta);
}
}
+54
View File
@@ -0,0 +1,54 @@
import { FunctionTool } from "llamaindex";
export const getCurrentIDTool = FunctionTool.from(
() => {
console.log("Getting user id...");
return crypto.randomUUID();
},
{
name: "get_user_id",
description: "Get a random user id",
},
);
export const getUserInfoTool = FunctionTool.from(
({ userId }: { userId: string }) => {
console.log("Getting user info...", userId);
return `Name: Alex; Address: 1234 Main St, CA; User ID: ${userId}`;
},
{
name: "get_user_info",
description: "Get user info",
parameters: {
type: "object",
properties: {
userId: {
type: "string",
description: "The user id",
},
},
required: ["userId"],
},
},
);
export const getWeatherTool = FunctionTool.from(
({ address }: { address: string }) => {
console.log("Getting weather...", address);
return `${address} is in a sunny location!`;
},
{
name: "get_weather",
description: "Get the current weather for a location",
parameters: {
type: "object",
properties: {
address: {
type: "string",
description: "The address",
},
},
required: ["address"],
},
},
);
+4 -2
View File
@@ -16,8 +16,10 @@ async function main() {
stream: true,
});
for await (const chunk of response.response) {
process.stdout.write(chunk.response);
for await (const {
response: { delta },
} of response) {
process.stdout.write(delta);
}
}
Binary file not shown.
@@ -1,11 +1,11 @@
import { GEMINI_MODEL, GeminiEmbedding } from "llamaindex";
import { GEMINI_EMBEDDING_MODEL, GeminiEmbedding } from "llamaindex";
async function main() {
if (!process.env.GOOGLE_API_KEY) {
throw new Error("Please set the GOOGLE_API_KEY environment variable.");
}
const embedModel = new GeminiEmbedding({
model: GEMINI_MODEL.GEMINI_PRO,
model: GEMINI_EMBEDDING_MODEL.EMBEDDING_001,
});
const texts = ["hello", "world"];
const embeddings = await embedModel.getTextEmbeddingsBatch(texts);
+22
View File
@@ -0,0 +1,22 @@
import { HuggingFaceInferenceAPI } from "llamaindex";
(async () => {
if (!process.env.HUGGING_FACE_TOKEN) {
throw new Error("Please set the HUGGING_FACE_TOKEN environment variable.");
}
const hf = new HuggingFaceInferenceAPI({
accessToken: process.env.HUGGING_FACE_TOKEN,
model: "mistralai/Mixtral-8x7B-Instruct-v0.1",
});
const result = await hf.chat({
messages: [
{ content: "You want to talk in rhymes.", role: "system" },
{
content:
"How much wood would a woodchuck chuck if a woodchuck could chuck wood?",
role: "user",
},
],
});
console.log(result);
})();
+2 -1
View File
@@ -10,7 +10,8 @@
"start:markdown": "node --import tsx ./src/markdown.ts",
"start:pdf": "node --import tsx ./src/pdf.ts",
"start:llamaparse": "node --import tsx ./src/llamaparse.ts",
"start:notion": "node --import tsx ./src/notion.ts"
"start:notion": "node --import tsx ./src/notion.ts",
"start:llamaparse2": "node --import tsx ./src/llamaparse_2.ts"
},
"dependencies": {
"llamaindex": "*"
+26
View File
@@ -0,0 +1,26 @@
import fs from "fs/promises";
import { LlamaParseReader } from "llamaindex";
async function main() {
// Load PDF using LlamaParse. set apiKey here or in environment variable LLAMA_CLOUD_API_KEY
const reader = new LlamaParseReader({
resultType: "markdown",
language: "en",
parsingInstruction:
"The provided document is a manga comic book. Most pages do NOT have title. It does not contain tables. Try to reconstruct the dialogue happening in a cohesive way. Output any math equation in LATEX markdown (between $$)",
});
const documents = await reader.loadData("../data/manga.pdf"); // The manga.pdf in the data folder is just a copy of the TOS, due to copyright laws. You have to place your own. I used "The Manga Guide to Calculus" by Hiroyuki Kojima
// Assuming documents contain an array of pages or sections
const parsedManga = documents.map((page) => page.text).join("\n---\n");
// Output the parsed manga to .md file. Will be placed in ../example/readers/
try {
await fs.writeFile("./parsedManga.md", parsedManga);
console.log("Output successfully written to parsedManga.md");
} catch (err) {
console.error("Error writing to file:", err);
}
}
main().catch(console.error);
+1
View File
@@ -8,6 +8,7 @@
"strict": true,
"skipLibCheck": true,
"lib": ["ES2022"],
"types": ["node"],
"outDir": "./lib",
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"incremental": true,
+2 -2
View File
@@ -3,7 +3,7 @@
"private": true,
"scripts": {
"build": "turbo run build",
"build:release": "turbo run build lint test --filter=\"!docs\"",
"build:release": "turbo run build lint test --filter=\"!docs\" --filter=\"!*-test\"",
"dev": "turbo run dev",
"format": "prettier --ignore-unknown --cache --check .",
"format:write": "prettier --ignore-unknown --write .",
@@ -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": {
+61
View File
@@ -1,5 +1,66 @@
# 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
- 1dce275: fix: export `StorageContext` on edge runtime
- d10533e: feat: add hugging face llm
- 2008efe: feat: add verbose mode to Agent
- 5e61934: fix: remove clone object in `CallbackManager.dispatchEvent`
- 9e74a43: feat: add top k to `asQueryEngine`
- ee719a1: fix: streaming for ReAct Agent
## 0.3.3
### Patch Changes
- e8c41c5: fix: wrong gemini streaming chat response
## 0.3.2
### Patch Changes
- 61103b6: fix: streaming for `Agent.createTask` API
## 0.3.1
### Patch Changes
- 46227f2: fix: build error on next.js nodejs runtime
## 0.3.0
### Minor Changes
- 5016f21: feat: improve next.js/cloudflare/vite support
### Patch Changes
- Updated dependencies [5016f21]
- @llamaindex/env@0.1.0
## 0.2.13
### Patch Changes
+13
View File
@@ -0,0 +1,13 @@
# @llamaindex/core-e2e
## 0.0.4
### Patch Changes
- be5df5b: fix: anthropic agent on multiple chat
## 0.0.3
### Patch Changes
- 61103b6: fix: streaming for `Agent.createTask` API
+4
View File
@@ -0,0 +1,4 @@
# Examples
This directory contains examples of how to use the core package.
Each example is not for production use, but rather to show how to use the core package at minimum.
@@ -0,0 +1,172 @@
# Logs
logs
_.log
npm-debug.log_
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
# Runtime data
pids
_.pid
_.seed
\*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
\*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
\*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional stylelint cache
.stylelintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
\*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# vuepress v2.x temp and cache directory
.temp
.cache
# Docusaurus cache and generated files
.docusaurus
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.\*
# wrangler project
.dev.vars
.wrangler/
@@ -0,0 +1,59 @@
# @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
- Updated dependencies [1dce275]
- Updated dependencies [d10533e]
- Updated dependencies [2008efe]
- Updated dependencies [5e61934]
- Updated dependencies [9e74a43]
- Updated dependencies [ee719a1]
- llamaindex@0.3.4
## 0.0.4
### Patch Changes
- Updated dependencies [e8c41c5]
- llamaindex@0.3.3
## 0.0.3
### Patch Changes
- Updated dependencies [61103b6]
- llamaindex@0.3.2
## 0.0.2
### Patch Changes
- Updated dependencies [46227f2]
- llamaindex@0.3.1
## 0.0.1
### Patch Changes
- Updated dependencies [5016f21]
- llamaindex@0.3.0
@@ -0,0 +1,24 @@
{
"name": "@llamaindex/cloudflare-worker-agent-test",
"version": "0.0.7",
"type": "module",
"private": true,
"scripts": {
"deploy": "wrangler deploy",
"dev": "wrangler dev",
"build": "wrangler deploy --dry-run --outdir dist",
"start": "wrangler dev",
"test": "vitest",
"cf-typegen": "wrangler types"
},
"devDependencies": {
"@cloudflare/vitest-pool-workers": "^0.2.3",
"@cloudflare/workers-types": "^4.20240423.0",
"typescript": "^5.4.5",
"vitest": "1.3.0",
"wrangler": "^3.52.0"
},
"dependencies": {
"llamaindex": "workspace:*"
}
}
@@ -0,0 +1,29 @@
export default {
async fetch(
request: Request,
env: Env,
ctx: ExecutionContext,
): Promise<Response> {
const { setEnvs } = await import("@llamaindex/env");
setEnvs(env);
const { OpenAIAgent } = await import("llamaindex");
const agent = new OpenAIAgent({
tools: [],
});
const responseStream = await agent.chat({
stream: true,
message: "Hello? What is the weather today?",
});
const textEncoder = new TextEncoder();
const response = responseStream.pipeThrough<Uint8Array>(
// @ts-expect-error: see https://github.com/cloudflare/workerd/issues/2067
new TransformStream({
transform: (chunk, controller) => {
controller.enqueue(textEncoder.encode(chunk.response.delta));
},
}),
);
// @ts-expect-error: see https://github.com/cloudflare/workerd/issues/2067
return new Response(response);
},
};
@@ -0,0 +1,23 @@
import {
createExecutionContext,
env,
waitOnExecutionContext,
} from "cloudflare:test";
import { describe, expect, it } from "vitest";
import worker from "../src/index";
const IncomingRequest = Request<unknown, IncomingRequestCfProperties>;
describe("Hello World worker", () => {
// FIXME: https://github.com/cloudflare/workers-sdk/issues/5646
it.fails("responds with Hello World! (unit style)", async () => {
const request = new IncomingRequest("http://example.com");
// Create an empty context to pass to `worker.fetch()`.
const ctx = createExecutionContext();
const response = await worker.fetch(request, env, ctx);
// Wait for all `Promise`s passed to `ctx.waitUntil()` to settle before running test assertions
await waitOnExecutionContext(ctx);
// fixme: should be not "Hello World!"
expect(await response.text()).toMatchInlineSnapshot(`"Hello World!"`);
});
});
@@ -0,0 +1,11 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"types": [
"@cloudflare/workers-types/experimental",
"@cloudflare/vitest-pool-workers"
]
},
"include": ["./**/*.ts", "../src/env.d.ts"],
"exclude": []
}
@@ -0,0 +1,106 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Projects */
// "incremental": true, /* Enable incremental compilation */
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
// "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
/* Language and Environment */
"target": "es2021" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
"lib": [
"es2021"
] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
"jsx": "react" /* Specify what JSX code is generated. */,
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */
// "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
/* Modules */
"module": "es2022" /* Specify what module code is generated. */,
// "rootDir": "./", /* Specify the root folder within your source files. */
"moduleResolution": "Bundler" /* Specify how TypeScript looks up a file from a given module specifier. */,
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
// "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */
"types": [
"@cloudflare/workers-types/2023-07-01"
] /* Specify type package names to be included without being referenced in a source file. */,
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
"resolveJsonModule": true /* Enable importing .json files */,
// "noResolve": true, /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. */
/* JavaScript Support */
"allowJs": true /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */,
"checkJs": false /* Enable error reporting in type-checked JavaScript files. */,
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */
/* Emit */
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
// "outDir": "./", /* Specify an output folder for all emitted files. */
// "removeComments": true, /* Disable emitting comments. */
"noEmit": true /* Disable emitting files from a compilation. */,
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
// "newLine": "crlf", /* Set the newline character for emitting files. */
// "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */
// "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
// "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
/* Interop Constraints */
"isolatedModules": true /* Ensure that each file can be safely transpiled without relying on other imports. */,
"allowSyntheticDefaultImports": true /* Allow 'import x from y' when a module doesn't have a default export. */,
// "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */,
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
/* Type Checking */
"strict": true /* Enable all strict type-checking options. */,
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */
// "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
// "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
// "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */
// "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
// "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
/* Completeness */
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
},
"exclude": ["test"]
}
@@ -0,0 +1,11 @@
import { defineWorkersConfig } from "@cloudflare/vitest-pool-workers/config";
export default defineWorkersConfig({
test: {
poolOptions: {
workers: {
wrangler: { configPath: "./wrangler.toml" },
},
},
},
});
@@ -0,0 +1,3 @@
// Generated by Wrangler
// After adding bindings to `wrangler.toml`, regenerate this interface via `npm run cf-typegen`
interface Env {}
@@ -0,0 +1,108 @@
#:schema node_modules/wrangler/config-schema.json
name = "agent"
main = "src/index.ts"
compatibility_date = "2024-04-23"
compatibility_flags = ["nodejs_compat"]
# Automatically place your workloads in an optimal location to minimize latency.
# If you are running back-end logic in a Worker, running it closer to your back-end infrastructure
# rather than the end user may result in better performance.
# Docs: https://developers.cloudflare.com/workers/configuration/smart-placement/#smart-placement
# [placement]
# mode = "smart"
# Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
# Docs:
# - https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
# Note: Use secrets to store sensitive data.
# - https://developers.cloudflare.com/workers/configuration/secrets/
# [vars]
# MY_VARIABLE = "production_value"
# Bind the Workers AI model catalog. Run machine learning models, powered by serverless GPUs, on Cloudflares global network
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#workers-ai
# [ai]
# binding = "AI"
# Bind an Analytics Engine dataset. Use Analytics Engine to write analytics within your Pages Function.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#analytics-engine-datasets
# [[analytics_engine_datasets]]
# binding = "MY_DATASET"
# Bind a headless browser instance running on Cloudflare's global network.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#browser-rendering
# [browser]
# binding = "MY_BROWSER"
# Bind a D1 database. D1 is Cloudflares native serverless SQL database.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#d1-databases
# [[d1_databases]]
# binding = "MY_DB"
# database_name = "my-database"
# database_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
# Bind a dispatch namespace. Use Workers for Platforms to deploy serverless functions programmatically on behalf of your customers.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#dispatch-namespace-bindings-workers-for-platforms
# [[dispatch_namespaces]]
# binding = "MY_DISPATCHER"
# namespace = "my-namespace"
# Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model.
# Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects
# [[durable_objects.bindings]]
# name = "MY_DURABLE_OBJECT"
# class_name = "MyDurableObject"
# Durable Object migrations.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#migrations
# [[migrations]]
# tag = "v1"
# new_classes = ["MyDurableObject"]
# Bind a Hyperdrive configuration. Use to accelerate access to your existing databases from Cloudflare Workers.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#hyperdrive
# [[hyperdrive]]
# binding = "MY_HYPERDRIVE"
# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# Bind a KV Namespace. Use KV as persistent storage for small key-value pairs.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#kv-namespaces
# [[kv_namespaces]]
# binding = "MY_KV_NAMESPACE"
# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# Bind an mTLS certificate. Use to present a client certificate when communicating with another service.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#mtls-certificates
# [[mtls_certificates]]
# binding = "MY_CERTIFICATE"
# certificate_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
# Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#queues
# [[queues.producers]]
# binding = "MY_QUEUE"
# queue = "my-queue"
# Bind a Queue consumer. Queue Consumers can retrieve tasks scheduled by Producers to act on them.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#queues
# [[queues.consumers]]
# queue = "my-queue"
# Bind an R2 Bucket. Use R2 to store arbitrarily large blobs of data, such as files.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#r2-buckets
# [[r2_buckets]]
# binding = "MY_BUCKET"
# bucket_name = "my-bucket"
# Bind another Worker service. Use this binding to call another Worker without network overhead.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#service-bindings
# [[services]]
# binding = "MY_SERVICE"
# service = "my-service"
# Bind a Vectorize index. Use to store and query vector embeddings for semantic search, classification and other vector search use-cases.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#vectorize-indexes
# [[vectorize]]
# binding = "MY_INDEX"
# index_name = "my-index"
@@ -0,0 +1,4 @@
{
"root": false,
"extends": "next/core-web-vitals"
}
@@ -0,0 +1,59 @@
# @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
- Updated dependencies [1dce275]
- Updated dependencies [d10533e]
- Updated dependencies [2008efe]
- Updated dependencies [5e61934]
- Updated dependencies [9e74a43]
- Updated dependencies [ee719a1]
- llamaindex@0.3.4
## 0.1.4
### Patch Changes
- Updated dependencies [e8c41c5]
- llamaindex@0.3.3
## 0.1.3
### Patch Changes
- Updated dependencies [61103b6]
- llamaindex@0.3.2
## 0.1.2
### Patch Changes
- Updated dependencies [46227f2]
- llamaindex@0.3.1
## 0.1.1
### Patch Changes
- Updated dependencies [5016f21]
- llamaindex@0.3.0
@@ -0,0 +1,36 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
## Getting Started
First, run the development server:
```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
## Learn More
To learn more about Next.js, take a look at the following resources:
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
## Deploy on Vercel
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
@@ -0,0 +1,28 @@
{
"name": "@llamaindex/next-agent-test",
"version": "0.1.7",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"ai": "^3.0.34",
"llamaindex": "workspace:*",
"next": "14.2.3",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"@types/node": "^20",
"@types/react": "^18.2.79",
"@types/react-dom": "^18.2.25",
"eslint": "^8",
"eslint-config-next": "14.2.3",
"postcss": "^8",
"tailwindcss": "^3.4.1",
"typescript": "^5"
}
}
@@ -0,0 +1,8 @@
/** @type {import('postcss-load-config').Config} */
const config = {
plugins: {
tailwindcss: {},
},
};
export default config;

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Before

Width:  |  Height:  |  Size: 629 B

After

Width:  |  Height:  |  Size: 629 B

@@ -0,0 +1,32 @@
"use server";
import { createStreamableUI } from "ai/rsc";
import { OpenAIAgent } from "llamaindex";
import type { ChatMessage } from "llamaindex/llm/types";
export async function chatWithAgent(
question: string,
prevMessages: ChatMessage[] = [],
) {
const agent = new OpenAIAgent({
tools: [],
});
const responseStream = await agent.chat({
stream: true,
message: question,
chatHistory: prevMessages,
});
const uiStream = createStreamableUI(<div>loading...</div>);
responseStream
.pipeTo(
new WritableStream({
start: () => {
uiStream.update("response:");
},
write: async (message) => {
uiStream.append(message.response.delta);
},
}),
)
.catch(uiStream.error);
return uiStream.value;
}

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
@@ -0,0 +1,22 @@
import type { Metadata } from "next";
import { Inter } from "next/font/google";
import "./globals.css";
const inter = Inter({ subsets: ["latin"] });
export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
};
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body className={inter.className}>{children}</body>
</html>
);
}
@@ -0,0 +1,20 @@
"use client";
import { chatWithAgent } from "@/actions";
import type { JSX } from "react";
import { useFormState } from "react-dom";
export const runtime = "edge";
export default function Home() {
const [state, action] = useFormState<JSX.Element | null>(async () => {
return chatWithAgent("hello!", []);
}, null);
return (
<main>
{state}
<form action={action}>
<button>Chat</button>
</form>
</main>
);
}
@@ -0,0 +1,5 @@
import "llamaindex";
export default function Page() {
return "hello world!";
}
@@ -0,0 +1,20 @@
import type { Config } from "tailwindcss";
const config: Config = {
content: [
"./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
"./src/components/**/*.{js,ts,jsx,tsx,mdx}",
"./src/app/**/*.{js,ts,jsx,tsx,mdx}",
],
theme: {
extend: {
backgroundImage: {
"gradient-radial": "radial-gradient(var(--tw-gradient-stops))",
"gradient-conic":
"conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))",
},
},
},
plugins: [],
};
export default config;
@@ -0,0 +1,27 @@
{
"extends": "../../../../../tsconfig.json",
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
@@ -0,0 +1,36 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# local env files
.env*.local
# vercel
.vercel
# typescript
*.tsbuildinfo
next-env.d.ts
@@ -1,5 +1,31 @@
# 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
- Updated dependencies [46227f2]
- @llamaindex/edge@0.3.1
## 0.1.5
### Patch Changes
- Updated dependencies [5016f21]
- @llamaindex/edge@0.3.0
## 0.1.4
### Patch Changes
@@ -0,0 +1,4 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};
export default nextConfig;
@@ -1,6 +1,6 @@
{
"name": "test-edge-runtime",
"version": "0.1.4",
"name": "@llamaindex/nextjs-edge-runtime-test",
"version": "0.1.8",
"private": true,
"scripts": {
"dev": "next dev",
@@ -15,8 +15,8 @@
},
"devDependencies": {
"@types/node": "^20.12.7",
"@types/react": "^18",
"@types/react-dom": "^18",
"@types/react": "^18.2.79",
"@types/react-dom": "^18.2.25",
"typescript": "^5"
}
}
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 394 80"><path fill="#000" d="M262 0h68.5v12.7h-27.2v66.6h-13.6V12.7H262V0ZM149 0v12.7H94v20.4h44.3v12.6H94v21h55v12.6H80.5V0h68.7zm34.3 0h-17.8l63.8 79.4h17.9l-32-39.7 32-39.6h-17.9l-23 28.6-23-28.6zm18.3 56.7-9-11-27.1 33.7h17.8l18.3-22.7z"/><path fill="#000" d="M81 79.3 17 0H0v79.3h13.6V17l50.2 62.3H81Zm252.6-.4c-1 0-1.8-.4-2.5-1s-1.1-1.6-1.1-2.6.3-1.8 1-2.5 1.6-1 2.6-1 1.8.3 2.5 1a3.4 3.4 0 0 1 .6 4.3 3.7 3.7 0 0 1-3 1.8zm23.2-33.5h6v23.3c0 2.1-.4 4-1.3 5.5a9.1 9.1 0 0 1-3.8 3.5c-1.6.8-3.5 1.3-5.7 1.3-2 0-3.7-.4-5.3-1s-2.8-1.8-3.7-3.2c-.9-1.3-1.4-3-1.4-5h6c.1.8.3 1.6.7 2.2s1 1.2 1.6 1.5c.7.4 1.5.5 2.4.5 1 0 1.8-.2 2.4-.6a4 4 0 0 0 1.6-1.8c.3-.8.5-1.8.5-3V45.5zm30.9 9.1a4.4 4.4 0 0 0-2-3.3 7.5 7.5 0 0 0-4.3-1.1c-1.3 0-2.4.2-3.3.5-.9.4-1.6 1-2 1.6a3.5 3.5 0 0 0-.3 4c.3.5.7.9 1.3 1.2l1.8 1 2 .5 3.2.8c1.3.3 2.5.7 3.7 1.2a13 13 0 0 1 3.2 1.8 8.1 8.1 0 0 1 3 6.5c0 2-.5 3.7-1.5 5.1a10 10 0 0 1-4.4 3.5c-1.8.8-4.1 1.2-6.8 1.2-2.6 0-4.9-.4-6.8-1.2-2-.8-3.4-2-4.5-3.5a10 10 0 0 1-1.7-5.6h6a5 5 0 0 0 3.5 4.6c1 .4 2.2.6 3.4.6 1.3 0 2.5-.2 3.5-.6 1-.4 1.8-1 2.4-1.7a4 4 0 0 0 .8-2.4c0-.9-.2-1.6-.7-2.2a11 11 0 0 0-2.1-1.4l-3.2-1-3.8-1c-2.8-.7-5-1.7-6.6-3.2a7.2 7.2 0 0 1-2.4-5.7 8 8 0 0 1 1.7-5 10 10 0 0 1 4.3-3.5c2-.8 4-1.2 6.4-1.2 2.3 0 4.4.4 6.2 1.2 1.8.8 3.2 2 4.3 3.4 1 1.4 1.5 3 1.5 5h-5.8z"/></svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 283 64"><path fill="black" d="M141 16c-11 0-19 7-19 18s9 18 20 18c7 0 13-3 16-7l-7-5c-2 3-6 4-9 4-5 0-9-3-10-7h28v-3c0-11-8-18-19-18zm-9 15c1-4 4-7 9-7s8 3 9 7h-18zm117-15c-11 0-19 7-19 18s9 18 20 18c6 0 12-3 16-7l-8-5c-2 3-5 4-8 4-5 0-9-3-11-7h28l1-3c0-11-8-18-19-18zm-10 15c2-4 5-7 10-7s8 3 9 7h-19zm-39 3c0 6 4 10 10 10 4 0 7-2 9-5l8 5c-3 5-9 8-17 8-11 0-19-7-19-18s8-18 19-18c8 0 14 3 17 8l-8 5c-2-3-5-5-9-5-6 0-10 4-10 10zm83-29v46h-9V5h9zM37 0l37 64H0L37 0zm92 5-27 48L74 5h10l18 30 17-30h10zm59 12v10l-3-1c-6 0-10 4-10 10v15h-9V17h9v9c0-5 6-9 13-9z"/></svg>

After

Width:  |  Height:  |  Size: 629 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

@@ -1,6 +1,7 @@
"use server";
// test runtime
import "@llamaindex/edge";
import "llamaindex";
import "llamaindex/readers/SimpleDirectoryReader";
// @ts-expect-error
if (typeof EdgeRuntime !== "string") {
@@ -0,0 +1,7 @@
node_modules
dist
.env*
*.tsbuildinfo
.cache
.DS_Store
*.pem
@@ -0,0 +1,59 @@
# @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
- Updated dependencies [1dce275]
- Updated dependencies [d10533e]
- Updated dependencies [2008efe]
- Updated dependencies [5e61934]
- Updated dependencies [9e74a43]
- Updated dependencies [ee719a1]
- llamaindex@0.3.4
## 0.0.4
### Patch Changes
- Updated dependencies [e8c41c5]
- llamaindex@0.3.3
## 0.0.3
### Patch Changes
- Updated dependencies [61103b6]
- llamaindex@0.3.2
## 0.0.2
### Patch Changes
- Updated dependencies [46227f2]
- llamaindex@0.3.1
## 0.0.1
### Patch Changes
- Updated dependencies [5016f21]
- llamaindex@0.3.0
@@ -0,0 +1,25 @@
{
"name": "@llamaindex/waku-query-engine-test",
"version": "0.0.7",
"type": "module",
"private": true,
"scripts": {
"dev": "waku dev",
"build": "waku build",
"start": "waku start"
},
"dependencies": {
"llamaindex": "workspace:*",
"react": "19.0.0-canary-e3ebcd54b-20240405",
"react-dom": "19.0.0-canary-e3ebcd54b-20240405",
"react-server-dom-webpack": "19.0.0-canary-e3ebcd54b-20240405",
"waku": "0.20.1"
},
"devDependencies": {
"@types/react": "18.2.74",
"@types/react-dom": "18.2.24",
"autoprefixer": "10.4.19",
"tailwindcss": "3.4.3",
"typescript": "5.4.4"
}
}
@@ -0,0 +1,7 @@
/** @type {import('postcss-load-config').Config} */
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};
Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

@@ -0,0 +1,27 @@
"use server";
import { Document, VectorStoreIndex, type QueryEngine } from "llamaindex";
import { readFile } from "node:fs/promises";
let _queryEngine: QueryEngine;
async function lazyLoadQueryEngine() {
if (!_queryEngine) {
const path = "node_modules/llamaindex/examples/abramov.txt";
const essay = await 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]);
_queryEngine = index.asQueryEngine();
}
return _queryEngine;
}
export async function chatWithAI(question: string): Promise<string> {
const queryEngine = await lazyLoadQueryEngine();
const { response } = await queryEngine.query({ query: question });
return response;
}
@@ -0,0 +1,37 @@
"use client";
import { useState } from "react";
export type ChatProps = {
askQuestion: (question: string) => Promise<string>;
};
export const Chat = (props: ChatProps) => {
const [response, setResponse] = useState<string | null>(null);
return (
<section className="border-blue-400 -mx-4 mt-4 rounded border border-dashed p-4">
<h2 className="text-lg font-bold">Chat with AI</h2>
{response ? (
<p className="text-sm text-gray-600 max-w-sm">{response}</p>
) : null}
<form
action={async (formData) => {
const question = formData.get("question") as string | null;
if (question) {
setResponse(await props.askQuestion(question));
}
}}
>
<input
type="text"
name="question"
className="border border-gray-400 rounded-sm px-2 py-0.5 text-sm"
/>
<button className="rounded-sm bg-black px-2 py-0.5 text-sm text-white">
Ask
</button>
</form>
</section>
);
};
@@ -0,0 +1,18 @@
export const Footer = () => {
return (
<footer className="p-6 lg:fixed lg:bottom-0 lg:left-0">
<div>
visit{" "}
<a
href="https://waku.gg/"
target="_blank"
rel="noreferrer"
className="mt-4 inline-block underline"
>
waku.gg
</a>{" "}
to learn more
</div>
</footer>
);
};
@@ -0,0 +1,11 @@
import { Link } from "waku";
export const Header = () => {
return (
<header className="flex items-center gap-4 p-6 lg:fixed lg:left-0 lg:top-0">
<h2 className="text-lg font-bold tracking-tight">
<Link to="/">Waku starter</Link>
</h2>
</header>
);
};
@@ -0,0 +1,39 @@
import "../styles.css";
import type { ReactNode } from "react";
import { Footer } from "../components/footer";
import { Header } from "../components/header";
type RootLayoutProps = { children: ReactNode };
export default async function RootLayout({ children }: RootLayoutProps) {
const data = await getData();
return (
<div className="font-['Nunito']">
<meta property="description" content={data.description} />
<link rel="icon" type="image/png" href={data.icon} />
<Header />
<main className="m-6 flex items-center *:min-h-64 *:min-w-64 lg:m-0 lg:min-h-svh lg:justify-center">
{children}
</main>
<Footer />
</div>
);
}
const getData = async () => {
const data = {
description: "An internet website!",
icon: "/images/favicon.png",
};
return data;
};
export const getConfig = async () => {
return {
render: "static",
};
};
@@ -0,0 +1,36 @@
import { Link } from "waku";
import { chatWithAI } from "../actions";
import { Chat } from "../components/chat";
export default async function HomePage() {
const data = await getData();
return (
<div>
<title>{data.title}</title>
<h1 className="text-4xl font-bold tracking-tight">{data.headline}</h1>
<p>{data.body}</p>
<Chat askQuestion={chatWithAI} />
<Link to="/about" className="mt-4 inline-block underline">
About page
</Link>
</div>
);
}
const getData = async () => {
const data = {
title: "Waku",
headline: "Waku",
body: "Hello world!",
};
return data;
};
export const getConfig = async () => {
return {
render: "static",
};
};
@@ -0,0 +1,4 @@
@import url("https://fonts.googleapis.com/css2?family=Nunito:ital,wght@0,400;0,700;1,400;1,700&display=swap");
@tailwind base;
@tailwind components;
@tailwind utilities;
@@ -0,0 +1,4 @@
/** @type {import('tailwindcss').Config} */
export default {
content: ["./src/**/*.{js,jsx,ts,tsx}"],
};
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"strict": true,
"target": "esnext",
"downlevelIteration": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"skipLibCheck": true,
"noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": true,
"types": ["react/experimental"],
"jsx": "react-jsx"
}
}
@@ -1,3 +1,6 @@
import { OpenAI } from "./openai.js";
export class Anthropic extends OpenAI {}
export const ALL_AVAILABLE_ANTHROPIC_LEGACY_MODELS = {};
export const ALL_AVAILABLE_ANTHROPIC_MODELS = {};
export const ALL_AVAILABLE_V3_MODELS = {};
+47 -3
View File
@@ -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"));
}
});
});
+20
View File
@@ -27,3 +27,23 @@ await test("react agent", async (t) => {
ok(extractText(response.message.content).includes("72"));
});
});
await test("react agent stream", async (t) => {
await mockLLMEvent(t, "react-agent-stream");
await t.test("get weather", async () => {
const agent = new ReActAgent({
tools: [getWeatherTool],
});
const stream = await agent.chat({
stream: true,
message: "What is the weather like in San Francisco?",
});
let content = "";
for await (const { response } of stream) {
content += response.delta;
}
ok(content.includes("72"));
});
});
+34 -193
View File
@@ -4,8 +4,8 @@
"id": "PRESERVE_0",
"messages": [
{
"content": "What is the weather in San Francisco?",
"role": "user"
"role": "user",
"content": "What is the weather in San Francisco?"
}
]
},
@@ -13,15 +13,15 @@
"id": "PRESERVE_1",
"messages": [
{
"content": "What is the weather in San Francisco?",
"role": "user"
"role": "user",
"content": "What is the weather in San Francisco?"
},
{
"content": "",
"role": "assistant",
"options": {
"toolCall": {
"id": "HIDDEN",
"id": "call_Enrc7RhNts0qxGaEATOEhV6F",
"name": "Weather",
"input": "{\"location\":\"San Francisco\"}"
}
@@ -32,8 +32,9 @@
"role": "user",
"options": {
"toolResult": {
"id": "HIDDEN",
"isError": false
"result": "35 degrees and sunny in San Francisco",
"isError": false,
"id": "call_Enrc7RhNts0qxGaEATOEhV6F"
}
}
}
@@ -43,8 +44,8 @@
"id": "PRESERVE_2",
"messages": [
{
"content": "My name is Alex Yang. What is my unique id?",
"role": "user"
"role": "user",
"content": "My name is Alex Yang. What is my unique id?"
}
]
},
@@ -52,15 +53,15 @@
"id": "PRESERVE_3",
"messages": [
{
"content": "My name is Alex Yang. What is my unique id?",
"role": "user"
"role": "user",
"content": "My name is Alex Yang. What is my unique id?"
},
{
"content": "",
"role": "assistant",
"options": {
"toolCall": {
"id": "HIDDEN",
"id": "call_OYo81prrpK2RLOS9d0Y6kiXB",
"name": "unique_id",
"input": "{\"firstName\":\"Alex\",\"lastName\":\"Yang\"}"
}
@@ -71,8 +72,9 @@
"role": "user",
"options": {
"toolResult": {
"id": "HIDDEN",
"isError": false
"result": "123456789",
"isError": false,
"id": "call_OYo81prrpK2RLOS9d0Y6kiXB"
}
}
}
@@ -82,8 +84,8 @@
"id": "PRESERVE_4",
"messages": [
{
"content": "how much is 1 + 1?",
"role": "user"
"role": "user",
"content": "how much is 1 + 1?"
}
]
},
@@ -91,15 +93,15 @@
"id": "PRESERVE_5",
"messages": [
{
"content": "how much is 1 + 1?",
"role": "user"
"role": "user",
"content": "how much is 1 + 1?"
},
{
"content": "",
"role": "assistant",
"options": {
"toolCall": {
"id": "HIDDEN",
"id": "call_YUXowHKwOJ6GIWV4EA59x8iF",
"name": "sumNumbers",
"input": "{\"a\":1,\"b\":1}"
}
@@ -110,8 +112,9 @@
"role": "user",
"options": {
"toolResult": {
"id": "HIDDEN",
"isError": false
"result": "2",
"isError": false,
"id": "call_YUXowHKwOJ6GIWV4EA59x8iF"
}
}
}
@@ -122,45 +125,13 @@
{
"id": "PRESERVE_0",
"response": {
"raw": {
"id": "HIDDEN",
"object": "chat.completion",
"created": 114514,
"model": "gpt-3.5-turbo-0125",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "HIDDEN",
"type": "function",
"function": {
"name": "Weather",
"arguments": "{\"location\":\"San Francisco\"}"
}
}
]
},
"logprobs": null,
"finish_reason": "tool_calls"
}
],
"usage": {
"prompt_tokens": 49,
"completion_tokens": 15,
"total_tokens": 64
},
"system_fingerprint": "HIDDEN"
},
"raw": null,
"message": {
"content": "",
"role": "assistant",
"options": {
"toolCall": {
"id": "HIDDEN",
"id": "call_Enrc7RhNts0qxGaEATOEhV6F",
"name": "Weather",
"input": "{\"location\":\"San Francisco\"}"
}
@@ -171,29 +142,7 @@
{
"id": "PRESERVE_1",
"response": {
"raw": {
"id": "HIDDEN",
"object": "chat.completion",
"created": 114514,
"model": "gpt-3.5-turbo-0125",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "The weather in San Francisco is currently 35 degrees and sunny."
},
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 78,
"completion_tokens": 14,
"total_tokens": 92
},
"system_fingerprint": "HIDDEN"
},
"raw": null,
"message": {
"content": "The weather in San Francisco is currently 35 degrees and sunny.",
"role": "assistant",
@@ -204,45 +153,13 @@
{
"id": "PRESERVE_2",
"response": {
"raw": {
"id": "HIDDEN",
"object": "chat.completion",
"created": 114514,
"model": "gpt-3.5-turbo-0125",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "HIDDEN",
"type": "function",
"function": {
"name": "unique_id",
"arguments": "{\"firstName\":\"Alex\",\"lastName\":\"Yang\"}"
}
}
]
},
"logprobs": null,
"finish_reason": "tool_calls"
}
],
"usage": {
"prompt_tokens": 59,
"completion_tokens": 18,
"total_tokens": 77
},
"system_fingerprint": "HIDDEN"
},
"raw": null,
"message": {
"content": "",
"role": "assistant",
"options": {
"toolCall": {
"id": "HIDDEN",
"id": "call_OYo81prrpK2RLOS9d0Y6kiXB",
"name": "unique_id",
"input": "{\"firstName\":\"Alex\",\"lastName\":\"Yang\"}"
}
@@ -253,29 +170,7 @@
{
"id": "PRESERVE_3",
"response": {
"raw": {
"id": "HIDDEN",
"object": "chat.completion",
"created": 114514,
"model": "gpt-3.5-turbo-0125",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Your unique id is 123456789."
},
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 88,
"completion_tokens": 10,
"total_tokens": 98
},
"system_fingerprint": "HIDDEN"
},
"raw": null,
"message": {
"content": "Your unique id is 123456789.",
"role": "assistant",
@@ -286,45 +181,13 @@
{
"id": "PRESERVE_4",
"response": {
"raw": {
"id": "HIDDEN",
"object": "chat.completion",
"created": 114514,
"model": "gpt-3.5-turbo-0125",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "HIDDEN",
"type": "function",
"function": {
"name": "sumNumbers",
"arguments": "{\"a\":1,\"b\":1}"
}
}
]
},
"logprobs": null,
"finish_reason": "tool_calls"
}
],
"usage": {
"prompt_tokens": 70,
"completion_tokens": 18,
"total_tokens": 88
},
"system_fingerprint": "HIDDEN"
},
"raw": null,
"message": {
"content": "",
"role": "assistant",
"options": {
"toolCall": {
"id": "HIDDEN",
"id": "call_YUXowHKwOJ6GIWV4EA59x8iF",
"name": "sumNumbers",
"input": "{\"a\":1,\"b\":1}"
}
@@ -335,31 +198,9 @@
{
"id": "PRESERVE_5",
"response": {
"raw": {
"id": "HIDDEN",
"object": "chat.completion",
"created": 114514,
"model": "gpt-3.5-turbo-0125",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "1 + 1 is equal to 2."
},
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 97,
"completion_tokens": 11,
"total_tokens": 108
},
"system_fingerprint": "HIDDEN"
},
"raw": null,
"message": {
"content": "1 + 1 is equal to 2.",
"content": "The sum of 1 + 1 is 2.",
"role": "assistant",
"options": {}
}
@@ -22,8 +22,11 @@
"options": {
"toolCall": {
"name": "divideNumbers",
"id": "call_t0vy4M815ncAQnfRqoflW5hn",
"input": "{\"a\": 16, \"b\": 2}"
"id": "call_QQh8uKzGHbgBlrhqxZNoWiQT",
"input": {
"a": 16,
"b": 2
}
}
}
},
@@ -34,7 +37,7 @@
"toolResult": {
"result": "8",
"isError": false,
"id": "call_t0vy4M815ncAQnfRqoflW5hn"
"id": "call_QQh8uKzGHbgBlrhqxZNoWiQT"
}
}
},
@@ -44,7 +47,7 @@
"options": {
"toolCall": {
"name": "sumNumbers",
"id": "call_08QNOtWYlDoqPPXHMtbvr7A2",
"id": "call_C03ASSDxIFTrYmzSuTxCrItd",
"input": "{\"a\": 8, \"b\": 20}"
}
}
@@ -56,7 +59,7 @@
"toolResult": {
"result": "28",
"isError": false,
"id": "call_08QNOtWYlDoqPPXHMtbvr7A2"
"id": "call_C03ASSDxIFTrYmzSuTxCrItd"
}
}
}
@@ -74,7 +77,7 @@
"options": {
"toolCall": {
"name": "sumNumbers",
"id": "call_08QNOtWYlDoqPPXHMtbvr7A2",
"id": "call_C03ASSDxIFTrYmzSuTxCrItd",
"input": "{\"a\": 8, \"b\": 20}"
}
}
@@ -101,7 +104,63 @@
"options": {
"toolCall": {
"name": "divideNumbers",
"id": "call_t0vy4M815ncAQnfRqoflW5hn",
"id": "call_QQh8uKzGHbgBlrhqxZNoWiQT",
"input": ""
}
},
"delta": ""
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {
"toolCall": {
"name": "divideNumbers",
"id": "call_QQh8uKzGHbgBlrhqxZNoWiQT",
"input": "{\"a\""
}
},
"delta": ""
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {
"toolCall": {
"name": "divideNumbers",
"id": "call_QQh8uKzGHbgBlrhqxZNoWiQT",
"input": "{\"a\": 16,"
}
},
"delta": ""
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {
"toolCall": {
"name": "divideNumbers",
"id": "call_QQh8uKzGHbgBlrhqxZNoWiQT",
"input": "{\"a\": 16, \"b\": "
}
},
"delta": ""
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {
"toolCall": {
"name": "divideNumbers",
"id": "call_QQh8uKzGHbgBlrhqxZNoWiQT",
"input": "{\"a\": 16, \"b\": 2}"
}
},
@@ -115,50 +174,11 @@
"options": {
"toolCall": {
"name": "divideNumbers",
"id": "call_t0vy4M815ncAQnfRqoflW5hn",
"input": "{\"a\": 16, \"b\": 2}"
}
},
"delta": ""
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {
"toolCall": {
"name": "divideNumbers",
"id": "call_t0vy4M815ncAQnfRqoflW5hn",
"input": "{\"a\": 16, \"b\": 2}"
}
},
"delta": ""
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {
"toolCall": {
"name": "divideNumbers",
"id": "call_t0vy4M815ncAQnfRqoflW5hn",
"input": "{\"a\": 16, \"b\": 2}"
}
},
"delta": ""
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {
"toolCall": {
"name": "divideNumbers",
"id": "call_t0vy4M815ncAQnfRqoflW5hn",
"input": "{\"a\": 16, \"b\": 2}"
"id": "call_QQh8uKzGHbgBlrhqxZNoWiQT",
"input": {
"a": 16,
"b": 2
}
}
},
"delta": ""
@@ -171,8 +191,8 @@
"options": {
"toolCall": {
"name": "sumNumbers",
"id": "call_08QNOtWYlDoqPPXHMtbvr7A2",
"input": "{\"a\": 8, \"b\": 20}"
"id": "call_C03ASSDxIFTrYmzSuTxCrItd",
"input": "{\"a\""
}
},
"delta": ""
@@ -185,8 +205,8 @@
"options": {
"toolCall": {
"name": "sumNumbers",
"id": "call_08QNOtWYlDoqPPXHMtbvr7A2",
"input": "{\"a\": 8, \"b\": 20}"
"id": "call_C03ASSDxIFTrYmzSuTxCrItd",
"input": "{\"a\": 8, "
}
},
"delta": ""
@@ -199,8 +219,8 @@
"options": {
"toolCall": {
"name": "sumNumbers",
"id": "call_08QNOtWYlDoqPPXHMtbvr7A2",
"input": "{\"a\": 8, \"b\": 20}"
"id": "call_C03ASSDxIFTrYmzSuTxCrItd",
"input": "{\"a\": 8, \"b\": 2"
}
},
"delta": ""
@@ -213,21 +233,7 @@
"options": {
"toolCall": {
"name": "sumNumbers",
"id": "call_08QNOtWYlDoqPPXHMtbvr7A2",
"input": "{\"a\": 8, \"b\": 20}"
}
},
"delta": ""
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {
"toolCall": {
"name": "sumNumbers",
"id": "call_08QNOtWYlDoqPPXHMtbvr7A2",
"id": "call_C03ASSDxIFTrYmzSuTxCrItd",
"input": "{\"a\": 8, \"b\": 20}"
}
},
@@ -21,7 +21,7 @@
"role": "assistant",
"options": {
"toolCall": {
"id": "call_lR2r0rpfqNX11jukJvEUdByv",
"id": "call_iY0VO4HvXDT2PtR3CvRSY1uK",
"name": "get_weather",
"input": "{\"location\":\"San Francisco\"}"
}
@@ -39,7 +39,7 @@
"rain_prediction": 0.89
},
"isError": false,
"id": "call_lR2r0rpfqNX11jukJvEUdByv"
"id": "call_iY0VO4HvXDT2PtR3CvRSY1uK"
}
}
}
@@ -56,7 +56,7 @@
"role": "assistant",
"options": {
"toolCall": {
"id": "call_lR2r0rpfqNX11jukJvEUdByv",
"id": "call_iY0VO4HvXDT2PtR3CvRSY1uK",
"name": "get_weather",
"input": "{\"location\":\"San Francisco\"}"
}
@@ -38,7 +38,7 @@
"role": "assistant",
"options": {
"toolCall": {
"id": "call_EVThrsiOylO0p6ZmGdsA31x9",
"id": "call_VfgZS1NPKpbtzqhM3o1Buzx8",
"name": "summary_tool",
"input": "{\"query\": \"Alex\"}"
}
@@ -51,7 +51,7 @@
"toolResult": {
"result": "Alex is not in Brazil.",
"isError": false,
"id": "call_EVThrsiOylO0p6ZmGdsA31x9"
"id": "call_VfgZS1NPKpbtzqhM3o1Buzx8"
}
}
}
@@ -68,7 +68,7 @@
"role": "assistant",
"options": {
"toolCall": {
"id": "call_EVThrsiOylO0p6ZmGdsA31x9",
"id": "call_VfgZS1NPKpbtzqhM3o1Buzx8",
"name": "summary_tool",
"input": "{\"query\": \"Alex\"}"
}
@@ -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": []
}
@@ -4,8 +4,8 @@
"id": "PRESERVE_0",
"messages": [
{
"content": "What is the weather in San Jose?",
"role": "user"
"role": "user",
"content": "What is the weather in San Jose?"
}
]
},
@@ -13,15 +13,15 @@
"id": "PRESERVE_1",
"messages": [
{
"content": "What is the weather in San Jose?",
"role": "user"
"role": "user",
"content": "What is the weather in San Jose?"
},
{
"content": "",
"role": "assistant",
"options": {
"toolCall": {
"id": "HIDDEN",
"id": "call_TRC5kpzyVaV5n2R91sJsBAF1",
"name": "Weather",
"input": "{\"location\":\"San Jose\"}"
}
@@ -32,8 +32,9 @@
"role": "user",
"options": {
"toolResult": {
"id": "HIDDEN",
"isError": false
"result": "45 degrees and sunny in San Jose",
"isError": false,
"id": "call_TRC5kpzyVaV5n2R91sJsBAF1"
}
}
}
@@ -44,45 +45,13 @@
{
"id": "PRESERVE_0",
"response": {
"raw": {
"id": "HIDDEN",
"object": "chat.completion",
"created": 114514,
"model": "gpt-3.5-turbo-0125",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "HIDDEN",
"type": "function",
"function": {
"name": "Weather",
"arguments": "{\"location\":\"San Jose\"}"
}
}
]
},
"logprobs": null,
"finish_reason": "tool_calls"
}
],
"usage": {
"prompt_tokens": 49,
"completion_tokens": 15,
"total_tokens": 64
},
"system_fingerprint": "HIDDEN"
},
"raw": null,
"message": {
"content": "",
"role": "assistant",
"options": {
"toolCall": {
"id": "HIDDEN",
"id": "call_TRC5kpzyVaV5n2R91sJsBAF1",
"name": "Weather",
"input": "{\"location\":\"San Jose\"}"
}
@@ -93,29 +62,7 @@
{
"id": "PRESERVE_1",
"response": {
"raw": {
"id": "HIDDEN",
"object": "chat.completion",
"created": 114514,
"model": "gpt-3.5-turbo-0125",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "The weather in San Jose is currently 45 degrees and sunny."
},
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 78,
"completion_tokens": 14,
"total_tokens": 92
},
"system_fingerprint": "HIDDEN"
},
"raw": null,
"message": {
"content": "The weather in San Jose is currently 45 degrees and sunny.",
"role": "assistant",
+11 -367
View File
@@ -23,29 +23,7 @@
{
"id": "PRESERVE_0",
"response": {
"raw": {
"id": "HIDDEN",
"object": "chat.completion",
"created": 114514,
"model": "gpt-3.5-turbo-0125",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I assist you today?"
},
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 8,
"completion_tokens": 9,
"total_tokens": 17
},
"system_fingerprint": "HIDDEN"
},
"raw": null,
"message": {
"content": "Hello! How can I assist you today?",
"role": "assistant",
@@ -56,197 +34,7 @@
{
"id": "PRESERVE_1",
"response": {
"raw": [
{
"raw": {
"id": "HIDDEN",
"object": "chat.completion.chunk",
"created": 114514,
"model": "gpt-3.5-turbo-0125",
"system_fingerprint": "HIDDEN",
"choices": [
{
"index": 0,
"delta": {
"content": "Hello"
},
"logprobs": null,
"finish_reason": null
}
]
},
"options": {},
"delta": "Hello"
},
{
"raw": {
"id": "HIDDEN",
"object": "chat.completion.chunk",
"created": 114514,
"model": "gpt-3.5-turbo-0125",
"system_fingerprint": "HIDDEN",
"choices": [
{
"index": 0,
"delta": {
"content": "!"
},
"logprobs": null,
"finish_reason": null
}
]
},
"options": {},
"delta": "!"
},
{
"raw": {
"id": "HIDDEN",
"object": "chat.completion.chunk",
"created": 114514,
"model": "gpt-3.5-turbo-0125",
"system_fingerprint": "HIDDEN",
"choices": [
{
"index": 0,
"delta": {
"content": " How"
},
"logprobs": null,
"finish_reason": null
}
]
},
"options": {},
"delta": " How"
},
{
"raw": {
"id": "HIDDEN",
"object": "chat.completion.chunk",
"created": 114514,
"model": "gpt-3.5-turbo-0125",
"system_fingerprint": "HIDDEN",
"choices": [
{
"index": 0,
"delta": {
"content": " can"
},
"logprobs": null,
"finish_reason": null
}
]
},
"options": {},
"delta": " can"
},
{
"raw": {
"id": "HIDDEN",
"object": "chat.completion.chunk",
"created": 114514,
"model": "gpt-3.5-turbo-0125",
"system_fingerprint": "HIDDEN",
"choices": [
{
"index": 0,
"delta": {
"content": " I"
},
"logprobs": null,
"finish_reason": null
}
]
},
"options": {},
"delta": " I"
},
{
"raw": {
"id": "HIDDEN",
"object": "chat.completion.chunk",
"created": 114514,
"model": "gpt-3.5-turbo-0125",
"system_fingerprint": "HIDDEN",
"choices": [
{
"index": 0,
"delta": {
"content": " assist"
},
"logprobs": null,
"finish_reason": null
}
]
},
"options": {},
"delta": " assist"
},
{
"raw": {
"id": "HIDDEN",
"object": "chat.completion.chunk",
"created": 114514,
"model": "gpt-3.5-turbo-0125",
"system_fingerprint": "HIDDEN",
"choices": [
{
"index": 0,
"delta": {
"content": " you"
},
"logprobs": null,
"finish_reason": null
}
]
},
"options": {},
"delta": " you"
},
{
"raw": {
"id": "HIDDEN",
"object": "chat.completion.chunk",
"created": 114514,
"model": "gpt-3.5-turbo-0125",
"system_fingerprint": "HIDDEN",
"choices": [
{
"index": 0,
"delta": {
"content": " today"
},
"logprobs": null,
"finish_reason": null
}
]
},
"options": {},
"delta": " today"
},
{
"raw": {
"id": "HIDDEN",
"object": "chat.completion.chunk",
"created": 114514,
"model": "gpt-3.5-turbo-0125",
"system_fingerprint": "HIDDEN",
"choices": [
{
"index": 0,
"delta": {
"content": "?"
},
"logprobs": null,
"finish_reason": null
}
]
},
"options": {},
"delta": "?"
}
],
"raw": null,
"message": {
"content": "Hello! How can I assist you today?",
"role": "assistant",
@@ -259,23 +47,7 @@
{
"id": "PRESERVE_1",
"chunk": {
"raw": {
"id": "HIDDEN",
"object": "chat.completion.chunk",
"created": 114514,
"model": "gpt-3.5-turbo-0125",
"system_fingerprint": "HIDDEN",
"choices": [
{
"index": 0,
"delta": {
"content": "Hello"
},
"logprobs": null,
"finish_reason": null
}
]
},
"raw": null,
"options": {},
"delta": "Hello"
}
@@ -283,23 +55,7 @@
{
"id": "PRESERVE_1",
"chunk": {
"raw": {
"id": "HIDDEN",
"object": "chat.completion.chunk",
"created": 114514,
"model": "gpt-3.5-turbo-0125",
"system_fingerprint": "HIDDEN",
"choices": [
{
"index": 0,
"delta": {
"content": "!"
},
"logprobs": null,
"finish_reason": null
}
]
},
"raw": null,
"options": {},
"delta": "!"
}
@@ -307,23 +63,7 @@
{
"id": "PRESERVE_1",
"chunk": {
"raw": {
"id": "HIDDEN",
"object": "chat.completion.chunk",
"created": 114514,
"model": "gpt-3.5-turbo-0125",
"system_fingerprint": "HIDDEN",
"choices": [
{
"index": 0,
"delta": {
"content": " How"
},
"logprobs": null,
"finish_reason": null
}
]
},
"raw": null,
"options": {},
"delta": " How"
}
@@ -331,23 +71,7 @@
{
"id": "PRESERVE_1",
"chunk": {
"raw": {
"id": "HIDDEN",
"object": "chat.completion.chunk",
"created": 114514,
"model": "gpt-3.5-turbo-0125",
"system_fingerprint": "HIDDEN",
"choices": [
{
"index": 0,
"delta": {
"content": " can"
},
"logprobs": null,
"finish_reason": null
}
]
},
"raw": null,
"options": {},
"delta": " can"
}
@@ -355,23 +79,7 @@
{
"id": "PRESERVE_1",
"chunk": {
"raw": {
"id": "HIDDEN",
"object": "chat.completion.chunk",
"created": 114514,
"model": "gpt-3.5-turbo-0125",
"system_fingerprint": "HIDDEN",
"choices": [
{
"index": 0,
"delta": {
"content": " I"
},
"logprobs": null,
"finish_reason": null
}
]
},
"raw": null,
"options": {},
"delta": " I"
}
@@ -379,23 +87,7 @@
{
"id": "PRESERVE_1",
"chunk": {
"raw": {
"id": "HIDDEN",
"object": "chat.completion.chunk",
"created": 114514,
"model": "gpt-3.5-turbo-0125",
"system_fingerprint": "HIDDEN",
"choices": [
{
"index": 0,
"delta": {
"content": " assist"
},
"logprobs": null,
"finish_reason": null
}
]
},
"raw": null,
"options": {},
"delta": " assist"
}
@@ -403,23 +95,7 @@
{
"id": "PRESERVE_1",
"chunk": {
"raw": {
"id": "HIDDEN",
"object": "chat.completion.chunk",
"created": 114514,
"model": "gpt-3.5-turbo-0125",
"system_fingerprint": "HIDDEN",
"choices": [
{
"index": 0,
"delta": {
"content": " you"
},
"logprobs": null,
"finish_reason": null
}
]
},
"raw": null,
"options": {},
"delta": " you"
}
@@ -427,23 +103,7 @@
{
"id": "PRESERVE_1",
"chunk": {
"raw": {
"id": "HIDDEN",
"object": "chat.completion.chunk",
"created": 114514,
"model": "gpt-3.5-turbo-0125",
"system_fingerprint": "HIDDEN",
"choices": [
{
"index": 0,
"delta": {
"content": " today"
},
"logprobs": null,
"finish_reason": null
}
]
},
"raw": null,
"options": {},
"delta": " today"
}
@@ -451,23 +111,7 @@
{
"id": "PRESERVE_1",
"chunk": {
"raw": {
"id": "HIDDEN",
"object": "chat.completion.chunk",
"created": 114514,
"model": "gpt-3.5-turbo-0125",
"system_fingerprint": "HIDDEN",
"choices": [
{
"index": 0,
"delta": {
"content": "?"
},
"logprobs": null,
"finish_reason": null
}
]
},
"raw": null,
"options": {},
"delta": "?"
}
@@ -29,7 +29,7 @@
"role": "assistant",
"options": {
"toolCall": {
"id": "call_h4gSNrz7MhhkOod7W4WKZ1iZ",
"id": "call_loaXnCH3WRnbnROZzNbrRkHS",
"name": "getWeather",
"input": "{\"city\":\"San Francisco\"}"
}
@@ -42,7 +42,7 @@
"toolResult": {
"result": "The weather in San Francisco is 72 degrees",
"isError": false,
"id": "call_h4gSNrz7MhhkOod7W4WKZ1iZ"
"id": "call_loaXnCH3WRnbnROZzNbrRkHS"
}
}
}
@@ -59,7 +59,7 @@
"role": "assistant",
"options": {
"toolCall": {
"id": "call_h4gSNrz7MhhkOod7W4WKZ1iZ",
"id": "call_loaXnCH3WRnbnROZzNbrRkHS",
"name": "getWeather",
"input": "{\"city\":\"San Francisco\"}"
}
@@ -72,7 +72,7 @@
"response": {
"raw": null,
"message": {
"content": "Arhgs the weather in San Francisco be 72 degrees.",
"content": "Arhgs! The weather in San Francisco is 72 degrees.",
"role": "assistant",
"options": {}
}
@@ -32,29 +32,7 @@
{
"id": "PRESERVE_0",
"response": {
"raw": {
"id": "HIDDEN",
"object": "chat.completion",
"created": 114514,
"model": "gpt-3.5-turbo-0125",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "```json\n[\n {\n \"subQuestion\": \"What is Bill Gates' idea\",\n \"toolName\": \"bill_gates_idea\"\n }\n]\n```"
},
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 290,
"completion_tokens": 35,
"total_tokens": 325
},
"system_fingerprint": "HIDDEN"
},
"raw": null,
"message": {
"content": "```json\n[\n {\n \"subQuestion\": \"What is Bill Gates' idea\",\n \"toolName\": \"bill_gates_idea\"\n }\n]\n```",
"role": "assistant",
@@ -65,29 +43,7 @@
{
"id": "PRESERVE_1",
"response": {
"raw": {
"id": "HIDDEN",
"object": "chat.completion",
"created": 114514,
"model": "gpt-3.5-turbo-0125",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Bill Gates' idea was to steal from Apple."
},
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 53,
"completion_tokens": 10,
"total_tokens": 63
},
"system_fingerprint": "HIDDEN"
},
"raw": null,
"message": {
"content": "Bill Gates' idea was to steal from Apple.",
"role": "assistant",
@@ -98,29 +54,7 @@
{
"id": "PRESERVE_2",
"response": {
"raw": {
"id": "HIDDEN",
"object": "chat.completion",
"created": 114514,
"model": "gpt-3.5-turbo-0125",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Bill Gates stole from Apple."
},
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 62,
"completion_tokens": 6,
"total_tokens": 68
},
"system_fingerprint": "HIDDEN"
},
"raw": null,
"message": {
"content": "Bill Gates stole from Apple.",
"role": "assistant",
@@ -0,0 +1,488 @@
{
"llmEventStart": [
{
"id": "PRESERVE_0",
"messages": [
{
"role": "system",
"content": "You are designed to help with a variety of tasks, from answering questions to providing summaries to other types of analyses.\n\n## Tools\nYou have access to a wide variety of tools. You are responsible for using\nthe tools in any sequence you deem appropriate to complete the task at hand.\nThis may require breaking the task into subtasks and using different tools\nto complete each subtask.\n\nYou have access to the following tools:\n- getWeather: Get the weather for a city with schema: {\"type\":\"object\",\"properties\":{\"city\":{\"type\":\"string\",\"description\":\"The city to get the weather for\"}},\"required\":[\"city\"]}\n\n## Output Format\nTo answer the question, please use the following format.\n\n\"\"\"\nThought: I need to use a tool to help me answer the question.\nAction: tool name (one of getWeather) if using a tool.\nAction Input: the input to the tool, in a JSON format representing the kwargs (e.g. {{\"input\": \"hello world\", \"num_beams\": 5}})\n\"\"\"\n\nPlease ALWAYS start with a Thought.\n\nPlease use a valid JSON format for the Action Input. Do NOT do this {{'input': 'hello world', 'num_beams': 5}}.\n\nIf this format is used, the user will respond in the following format:\n\n\"\"\"\"\nObservation: tool response\n\"\"\"\"\n\nYou should keep repeating the above format until you have enough information\nto answer the question without using any more tools. At that point, you MUST respond\nin the one of the following two formats:\n\n\"\"\"\"\nThought: I can answer without using any more tools.\nAnswer: [your answer here]\n\"\"\"\"\n\n\"\"\"\"\nThought: I cannot answer the question with the provided tools.\nAnswer: Sorry, I cannot answer your query.\n\"\"\"\"\n\n## Current Conversation\nBelow is the current conversation consisting of interleaving human and assistant messages."
},
{
"role": "user",
"content": "What is the weather like in San Francisco?"
}
]
},
{
"id": "PRESERVE_1",
"messages": [
{
"role": "system",
"content": "You are designed to help with a variety of tasks, from answering questions to providing summaries to other types of analyses.\n\n## Tools\nYou have access to a wide variety of tools. You are responsible for using\nthe tools in any sequence you deem appropriate to complete the task at hand.\nThis may require breaking the task into subtasks and using different tools\nto complete each subtask.\n\nYou have access to the following tools:\n- getWeather: Get the weather for a city with schema: {\"type\":\"object\",\"properties\":{\"city\":{\"type\":\"string\",\"description\":\"The city to get the weather for\"}},\"required\":[\"city\"]}\n\n## Output Format\nTo answer the question, please use the following format.\n\n\"\"\"\nThought: I need to use a tool to help me answer the question.\nAction: tool name (one of getWeather) if using a tool.\nAction Input: the input to the tool, in a JSON format representing the kwargs (e.g. {{\"input\": \"hello world\", \"num_beams\": 5}})\n\"\"\"\n\nPlease ALWAYS start with a Thought.\n\nPlease use a valid JSON format for the Action Input. Do NOT do this {{'input': 'hello world', 'num_beams': 5}}.\n\nIf this format is used, the user will respond in the following format:\n\n\"\"\"\"\nObservation: tool response\n\"\"\"\"\n\nYou should keep repeating the above format until you have enough information\nto answer the question without using any more tools. At that point, you MUST respond\nin the one of the following two formats:\n\n\"\"\"\"\nThought: I can answer without using any more tools.\nAnswer: [your answer here]\n\"\"\"\"\n\n\"\"\"\"\nThought: I cannot answer the question with the provided tools.\nAnswer: Sorry, I cannot answer your query.\n\"\"\"\"\n\n## Current Conversation\nBelow is the current conversation consisting of interleaving human and assistant messages."
},
{
"role": "user",
"content": "What is the weather like in San Francisco?"
},
{
"role": "assistant",
"content": "Thought: I need to use a tool to help me answer the question.\nAction: getWeather\nInput: {\n city: San Francisco\n}"
},
{
"role": "user",
"content": "Observation: The weather in San Francisco is 72 degrees"
}
]
}
],
"llmEventEnd": [
{
"id": "PRESERVE_0",
"response": {
"raw": null,
"message": {
"content": "Thought: I need to use a tool to help me answer the question.\nAction: getWeather\nAction Input: {\"city\": \"San Francisco\"}",
"role": "assistant",
"options": {}
}
}
},
{
"id": "PRESERVE_1",
"response": {
"raw": null,
"message": {
"content": "Thought: I can answer without using any more tools.\nAnswer: The weather in San Francisco is 72 degrees.",
"role": "assistant",
"options": {}
}
}
}
],
"llmEventStream": [
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {},
"delta": "Thought"
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {},
"delta": ":"
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {},
"delta": " I"
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {},
"delta": " need"
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {},
"delta": " to"
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {},
"delta": " use"
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {},
"delta": " a"
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {},
"delta": " tool"
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {},
"delta": " to"
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {},
"delta": " help"
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {},
"delta": " me"
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {},
"delta": " answer"
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {},
"delta": " the"
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {},
"delta": " question"
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {},
"delta": ".\n"
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {},
"delta": "Action"
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {},
"delta": ":"
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {},
"delta": " get"
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {},
"delta": "Weather"
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {},
"delta": "\n"
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {},
"delta": "Action"
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {},
"delta": " Input"
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {},
"delta": ":"
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {},
"delta": " {\""
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {},
"delta": "city"
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {},
"delta": "\":"
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {},
"delta": " \""
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {},
"delta": "San"
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {},
"delta": " Francisco"
}
},
{
"id": "PRESERVE_0",
"chunk": {
"raw": null,
"options": {},
"delta": "\"}"
}
},
{
"id": "PRESERVE_1",
"chunk": {
"raw": null,
"options": {},
"delta": "Thought"
}
},
{
"id": "PRESERVE_1",
"chunk": {
"raw": null,
"options": {},
"delta": ":"
}
},
{
"id": "PRESERVE_1",
"chunk": {
"raw": null,
"options": {},
"delta": " I"
}
},
{
"id": "PRESERVE_1",
"chunk": {
"raw": null,
"options": {},
"delta": " can"
}
},
{
"id": "PRESERVE_1",
"chunk": {
"raw": null,
"options": {},
"delta": " answer"
}
},
{
"id": "PRESERVE_1",
"chunk": {
"raw": null,
"options": {},
"delta": " without"
}
},
{
"id": "PRESERVE_1",
"chunk": {
"raw": null,
"options": {},
"delta": " using"
}
},
{
"id": "PRESERVE_1",
"chunk": {
"raw": null,
"options": {},
"delta": " any"
}
},
{
"id": "PRESERVE_1",
"chunk": {
"raw": null,
"options": {},
"delta": " more"
}
},
{
"id": "PRESERVE_1",
"chunk": {
"raw": null,
"options": {},
"delta": " tools"
}
},
{
"id": "PRESERVE_1",
"chunk": {
"raw": null,
"options": {},
"delta": ".\n"
}
},
{
"id": "PRESERVE_1",
"chunk": {
"raw": null,
"options": {},
"delta": "Answer"
}
},
{
"id": "PRESERVE_1",
"chunk": {
"raw": null,
"options": {},
"delta": ":"
}
},
{
"id": "PRESERVE_1",
"chunk": {
"raw": null,
"options": {},
"delta": " The"
}
},
{
"id": "PRESERVE_1",
"chunk": {
"raw": null,
"options": {},
"delta": " weather"
}
},
{
"id": "PRESERVE_1",
"chunk": {
"raw": null,
"options": {},
"delta": " in"
}
},
{
"id": "PRESERVE_1",
"chunk": {
"raw": null,
"options": {},
"delta": " San"
}
},
{
"id": "PRESERVE_1",
"chunk": {
"raw": null,
"options": {},
"delta": " Francisco"
}
},
{
"id": "PRESERVE_1",
"chunk": {
"raw": null,
"options": {},
"delta": " is"
}
},
{
"id": "PRESERVE_1",
"chunk": {
"raw": null,
"options": {},
"delta": " "
}
},
{
"id": "PRESERVE_1",
"chunk": {
"raw": null,
"options": {},
"delta": "72"
}
},
{
"id": "PRESERVE_1",
"chunk": {
"raw": null,
"options": {},
"delta": " degrees"
}
},
{
"id": "PRESERVE_1",
"chunk": {
"raw": null,
"options": {},
"delta": "."
}
}
]
}
+2 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/core-e2e",
"private": true,
"version": "0.0.2",
"version": "0.0.4",
"type": "module",
"scripts": {
"e2e": "node --import tsx --import ./mock-register.js --test ./node/*.e2e.ts",
@@ -10,6 +10,7 @@
},
"devDependencies": {
"@faker-js/faker": "^8.4.1",
"@types/node": "^20.12.7",
"consola": "^3.2.3",
"llamaindex": "workspace:*",
"tsx": "^4.7.2"
+5 -2
View File
@@ -1,8 +1,11 @@
{
"name": "@llamaindex/core",
"version": "0.2.3",
"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"]
}
}
+49 -4
View File
@@ -1,22 +1,38 @@
{
"name": "llamaindex",
"version": "0.2.13",
"expectedMinorVersion": "2",
"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",
"@datastax/astra-db-ts": "^1.0.1",
"@google/generative-ai": "^0.8.0",
"@grpc/grpc-js": "^1.10.6",
"@huggingface/inference": "^2.6.7",
"@llamaindex/cloud": "0.0.5",
"@llamaindex/env": "workspace:*",
"@mistralai/mistralai": "^0.1.3",
"@pinecone-database/pinecone": "^2.2.0",
"@qdrant/js-client-rest": "^1.8.2",
"@types/lodash": "^4.17.0",
"@types/node": "^20.12.7",
"@types/papaparse": "^5.3.14",
"@types/pg": "^8.11.5",
"@xenova/transformers": "^2.17.1",
@@ -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",
@@ -64,6 +79,18 @@
"main": "./dist/cjs/index.js",
"exports": {
".": {
"react-server": {
"types": "./dist/type/index.react-server.d.ts",
"default": "./dist/index.react-server.js"
},
"workerd": {
"types": "./dist/type/index.workerd.d.ts",
"default": "./dist/index.workerd.js"
},
"edge-light": {
"types": "./dist/type/index.edge.d.ts",
"default": "./dist/index.edge.js"
},
"import": {
"types": "./dist/type/index.d.ts",
"default": "./dist/index.js"
@@ -77,6 +104,24 @@
"import": "./dist/not-allow.js",
"require": "./dist/cjs/not-allow.js"
},
"./readers/SimpleDirectoryReader": {
"workerd": {
"types": "./dist/type/readers/SimpleDirectoryReader.edge.d.ts",
"default": "./dist/readers/SimpleDirectoryReader.edge.js"
},
"edge-light": {
"types": "./dist/type/readers/SimpleDirectoryReader.edge.d.ts",
"default": "./dist/readers/SimpleDirectoryReader.edge.js"
},
"import": {
"types": "./dist/type/readers/SimpleDirectoryReader.d.ts",
"default": "./dist/readers/SimpleDirectoryReader.js"
},
"require": {
"types": "./dist/type/readers/SimpleDirectoryReader.d.ts",
"default": "./dist/cjs/readers/SimpleDirectoryReader.js"
}
},
"./*": {
"import": {
"types": "./dist/type/*.d.ts",
+3 -3
View File
@@ -55,9 +55,9 @@ class GlobalSettings implements Config {
get debug() {
const debug = getEnv("DEBUG");
return (
getEnv("NODE_ENV") === "development" &&
Boolean(debug) &&
debug?.includes("llamaindex")
(Boolean(debug) && debug?.includes("llamaindex")) ||
debug === "*" ||
debug === "true"
);
}

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