Skip to content

Commit

Permalink
Merge branch 'main' into himself65/20240502/merge-message
Browse files Browse the repository at this point in the history
  • Loading branch information
himself65 authored May 3, 2024
2 parents 55665f7 + f1862cc commit ade144a
Show file tree
Hide file tree
Showing 35 changed files with 12,630 additions and 8,689 deletions.
5 changes: 0 additions & 5 deletions .changeset/four-vans-punch.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/hot-tools-pay.md

This file was deleted.

12 changes: 12 additions & 0 deletions apps/docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# docs

## 0.0.12

### Patch Changes

- Updated dependencies [1dce275]
- Updated dependencies [d10533e]
- Updated dependencies [2008efe]
- Updated dependencies [5e61934]
- Updated dependencies [9e74a43]
- Updated dependencies [ee719a1]
- [email protected]

## 0.0.11

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "docs",
"version": "0.0.11",
"version": "0.0.12",
"private": true,
"scripts": {
"docusaurus": "docusaurus",
Expand Down
1 change: 1 addition & 0 deletions examples/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DEBUG=llamaindex
62 changes: 7 additions & 55 deletions examples/agent/openai-task.ts
Original file line number Diff line number Diff line change
@@ -1,63 +1,15 @@
import { ChatResponseChunk, FunctionTool, OpenAIAgent } from "llamaindex";
import { ChatResponseChunk, OpenAIAgent } from "llamaindex";
import { ReadableStream } from "node:stream/web";

const functionTool = FunctionTool.from(
() => {
console.log("Getting user id...");
return crypto.randomUUID();
},
{
name: "get_user_id",
description: "Get a random user id",
},
);

const functionTool2 = 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"],
},
},
);

const functionTool3 = 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"],
},
},
);
import {
getCurrentIDTool,
getUserInfoTool,
getWeatherTool,
} from "./utils/tools";

async function main() {
// Create an OpenAIAgent with the function tools
const agent = new OpenAIAgent({
tools: [functionTool, functionTool2, functionTool3],
tools: [getCurrentIDTool, getUserInfoTool, getWeatherTool],
});

const task = await agent.createTask(
Expand Down
2 changes: 1 addition & 1 deletion examples/agent/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
40 changes: 40 additions & 0 deletions examples/agent/react-task.ts
Original file line number Diff line number Diff line change
@@ -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");
});
54 changes: 54 additions & 0 deletions examples/agent/utils/tools.ts
Original file line number Diff line number Diff line change
@@ -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"],
},
},
);
11 changes: 11 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# llamaindex

## 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
Expand Down
12 changes: 12 additions & 0 deletions packages/core/e2e/examples/cloudflare-worker-agent/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# @llamaindex/cloudflare-worker-agent-test

## 0.0.5

### Patch Changes

- Updated dependencies [1dce275]
- Updated dependencies [d10533e]
- Updated dependencies [2008efe]
- Updated dependencies [5e61934]
- Updated dependencies [9e74a43]
- Updated dependencies [ee719a1]
- [email protected]

## 0.0.4

### Patch Changes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/cloudflare-worker-agent-test",
"version": "0.0.4",
"version": "0.0.5",
"type": "module",
"private": true,
"scripts": {
Expand Down
12 changes: 12 additions & 0 deletions packages/core/e2e/examples/nextjs-agent/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# @llamaindex/next-agent-test

## 0.1.5

### Patch Changes

- Updated dependencies [1dce275]
- Updated dependencies [d10533e]
- Updated dependencies [2008efe]
- Updated dependencies [5e61934]
- Updated dependencies [9e74a43]
- Updated dependencies [ee719a1]
- [email protected]

## 0.1.4

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/core/e2e/examples/nextjs-agent/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/next-agent-test",
"version": "0.1.4",
"version": "0.1.5",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
12 changes: 12 additions & 0 deletions packages/core/e2e/examples/waku-query-engine/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# @llamaindex/waku-query-engine-test

## 0.0.5

### Patch Changes

- Updated dependencies [1dce275]
- Updated dependencies [d10533e]
- Updated dependencies [2008efe]
- Updated dependencies [5e61934]
- Updated dependencies [9e74a43]
- Updated dependencies [ee719a1]
- [email protected]

## 0.0.4

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/core/e2e/examples/waku-query-engine/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/waku-query-engine-test",
"version": "0.0.4",
"version": "0.0.5",
"type": "module",
"private": true,
"scripts": {
Expand Down
20 changes: 20 additions & 0 deletions packages/core/e2e/node/react.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
});
});
Loading

0 comments on commit ade144a

Please sign in to comment.