Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/odd-tomatoes-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@llamaindex/server": patch
"llamaindex-server-examples": patch
---

feat: add examples package for easily testing workflow
7 changes: 7 additions & 0 deletions .github/workflows/lint_on_push_or_pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ jobs:
- name: Run Prettier
run: pnpm run format

- name: Run build
run: pnpm run build

- name: Run Typecheck for examples
run: pnpm run typecheck
working-directory: packages/server/examples

- name: Run Python format check
uses: chartboost/ruff-action@v1
with:
Expand Down
12 changes: 12 additions & 0 deletions packages/server/examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# LlamaIndex Server Examples

This directory contains examples of how to use the LlamaIndex Server.

## Running the examples

```bash
export OPENAI_API_KEY=your_openai_api_key
npx tsx simple-workflow/calculator.ts
```

## Open browser at http://localhost:3000
43 changes: 43 additions & 0 deletions packages/server/examples/agentic-rag/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { LlamaIndexServer } from "@llamaindex/server";
import { agent } from "@llamaindex/workflow";
import {
Document,
OpenAI,
OpenAIEmbedding,
Settings,
VectorStoreIndex,
} from "llamaindex";

Settings.llm = new OpenAI({
model: "gpt-4o-mini",
});

Settings.embedModel = new OpenAIEmbedding({
model: "text-embedding-3-small",
});

export const workflowFactory = async () => {
const index = await VectorStoreIndex.fromDocuments([
new Document({ text: "The dog is brown" }),
new Document({ text: "The dog is yellow" }),
]);

const queryEngineTool = index.queryTool({
metadata: {
name: "query_document",
description: `This tool can retrieve information in documents`,
},
includeSourceNodes: true,
});

return agent({ tools: [queryEngineTool] });
};

new LlamaIndexServer({
workflow: workflowFactory,
uiConfig: {
appTitle: "LlamaIndex App",
starterQuestions: ["What is the color of the dog?"],
},
port: 4100,
}).start();
24 changes: 24 additions & 0 deletions packages/server/examples/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "llamaindex-server-examples",
"version": "0.0.1",
"private": true,
"scripts": {
"typecheck": "tsc --noEmit",
"dev": "tsx simple-workflow/calculator.ts"
},
"dependencies": {
"@llamaindex/openai": "^0.2.0",
"@llamaindex/readers": "^3.0.0",
"@llamaindex/server": "workspace:*",
"@llamaindex/tools": "0.0.4",
"@llamaindex/workflow": "1.1.0",
"dotenv": "^16.4.7",
"llamaindex": "0.10.2",
"zod": "^3.23.8"
},
"devDependencies": {
"@types/node": "^20.10.3",
"tsx": "^4.7.2",
"typescript": "^5.3.2"
}
}
24 changes: 24 additions & 0 deletions packages/server/examples/simple-workflow/calculator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { LlamaIndexServer } from "@llamaindex/server";
import { agent } from "@llamaindex/workflow";
import { tool } from "llamaindex";
import { z } from "zod";

const calculatorAgent = agent({
tools: [
tool({
name: "add",
description: "Adds two numbers",
parameters: z.object({ x: z.number(), y: z.number() }),
execute: ({ x, y }) => x + y,
}),
],
});

new LlamaIndexServer({
workflow: () => calculatorAgent,
uiConfig: {
appTitle: "Calculator",
starterQuestions: ["1 + 1", "2 + 2"],
},
port: 4000,
}).start();
14 changes: 14 additions & 0 deletions packages/server/examples/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "bundler",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"outDir": "dist"
},
"include": ["**/*"],
"exclude": ["node_modules", "dist"]
}
Loading
Loading