-
Notifications
You must be signed in to change notification settings - Fork 191
feat: add examples package for easily testing workflow #599
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7079521
feat: add example folders for easily testing workflow
thucpn bd4d1a0
add dev command
thucpn 6f482bb
add typecheck examples to ci
thucpn ad85ee5
Create odd-tomatoes-explode.md
thucpn b69e50f
run build
thucpn c534269
Merge branch 'main' into tp/add-example-folder
thucpn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"] | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.