Compare commits

...

5 Commits

Author SHA1 Message Date
thucpn 1c5fc33c42 Merge branch 'main' into tp/support-fully-custom-next-folder 2025-05-26 09:56:40 +07:00
thucpn 590637e862 fix import 2025-05-23 17:57:33 +07:00
thucpn 38e3b9a88b bump packages for examples 2025-05-23 17:57:26 +07:00
thucpn 111a869a99 merge with main 2025-05-23 17:01:35 +07:00
thucpn 078b31de1c feat: support fully custom next folder 2025-05-23 16:06:47 +07:00
12 changed files with 597 additions and 175 deletions
@@ -1,12 +1,7 @@
import { OpenAI, OpenAIEmbedding } from "@llamaindex/openai";
import { LlamaIndexServer } from "@llamaindex/server";
import { agent } from "@llamaindex/workflow";
import {
Document,
OpenAI,
OpenAIEmbedding,
Settings,
VectorStoreIndex,
} from "llamaindex";
import { Document, Settings, VectorStoreIndex } from "llamaindex";
Settings.llm = new OpenAI({
model: "gpt-4o-mini",
@@ -1,8 +1,11 @@
import { OpenAI } from "@llamaindex/openai";
import { LlamaIndexServer } from "@llamaindex/server";
import { agent } from "@llamaindex/workflow";
import { tool } from "llamaindex";
import { Settings, tool } from "llamaindex";
import { z } from "zod";
Settings.llm = new OpenAI({ model: "gpt-4o-mini" });
const weatherAgent = agent({
tools: [
tool({
@@ -1,6 +1,10 @@
import { OpenAI } from "@llamaindex/openai";
import { LlamaIndexServer } from "@llamaindex/server";
import { Settings } from "llamaindex";
import { workflowFactory } from "./src/app/workflow";
Settings.llm = new OpenAI({ model: "gpt-4o-mini" });
new LlamaIndexServer({
workflow: workflowFactory,
uiConfig: {
@@ -6,10 +6,10 @@ export const workflowFactory = async () => {
return agent({
tools: [
tool({
name: "weather",
description: "Get the weather in a specific city",
parameters: z.object({ city: z.string() }),
execute: ({ city }) => `The weather in ${city} is sunny`,
name: "add",
description: "Adds two numbers",
parameters: z.object({ x: z.number(), y: z.number() }),
execute: ({ x, y }) => x + y,
}),
],
});
@@ -0,0 +1,2 @@
next/
next-env.d.ts
@@ -0,0 +1,15 @@
# Fully Custom Next Folder
This example shows how to fully customize the Next.js frontend and Route Handlers.
## Running ejection
```bash
pnpm run eject
```
## Running the example
```bash
npx nodemon --exec tsx src/index.ts --ignore next/
```
@@ -0,0 +1,8 @@
import { OpenAI } from "@llamaindex/openai";
import { Settings } from "llamaindex";
export function initSettings() {
Settings.llm = new OpenAI({
model: "gpt-4.1",
});
}
@@ -0,0 +1,16 @@
import { agent } from "@llamaindex/workflow";
import { tool } from "llamaindex";
import { z } from "zod";
export const workflowFactory = async () => {
return agent({
tools: [
tool({
name: "weather",
description: "Get the weather in a given city",
parameters: z.object({ city: z.string() }),
execute: ({ city }) => `The weather in ${city} is sunny`,
}),
],
});
};
@@ -0,0 +1,14 @@
import { LlamaIndexServer } from "@llamaindex/server";
import "dotenv/config";
import { initSettings } from "./app/settings";
import { workflowFactory } from "./app/workflow";
initSettings();
new LlamaIndexServer({
workflow: workflowFactory,
// dir: "./src/next",
uiConfig: {
// maybe having an option here to use ejected next folder
},
}).start();
+5 -5
View File
@@ -7,13 +7,13 @@
"dev": "nodemon --exec tsx simple-workflow/calculator.ts"
},
"dependencies": {
"@llamaindex/openai": "^0.2.0",
"@llamaindex/readers": "^3.0.0",
"@llamaindex/openai": "~0.4.0",
"@llamaindex/readers": "~3.1.4",
"@llamaindex/server": "workspace:*",
"@llamaindex/tools": "0.0.4",
"@llamaindex/workflow": "1.1.0",
"@llamaindex/tools": "~0.0.11",
"@llamaindex/workflow": "~1.1.3",
"dotenv": "^16.4.7",
"llamaindex": "0.10.2",
"llamaindex": "~0.11.3",
"zod": "^3.23.8"
},
"devDependencies": {
@@ -1,8 +1,11 @@
import { OpenAI } from "@llamaindex/openai";
import { LlamaIndexServer } from "@llamaindex/server";
import { agent } from "@llamaindex/workflow";
import { tool } from "llamaindex";
import { Settings, tool } from "llamaindex";
import { z } from "zod";
Settings.llm = new OpenAI({ model: "gpt-4o-mini" });
const calculatorAgent = agent({
tools: [
tool({
+519 -157
View File
File diff suppressed because it is too large Load Diff