Compare commits

...

21 Commits

Author SHA1 Message Date
Alex Yang 53ae50517a fix: remove openapi 2025-03-07 23:19:47 -08:00
Alex Yang 27882dadde fix: import 2025-03-07 09:50:08 -08:00
Alex Yang e144cbf04f fix: import 2025-03-07 09:38:38 -08:00
thucpn f9e95b4649 use agentworkflow for agent examples 2025-03-07 17:16:37 +07:00
thucpn 2ec03eb164 update tool docs 2025-03-07 16:45:15 +07:00
thucpn 2884f734f5 Merge branch 'main' into himself65/2025/02/27/bump 2025-03-07 16:31:15 +07:00
thucpn 43edd06c8d refactor: use zod 2025-03-07 16:30:08 +07:00
thucpn dd8acacf18 Merge branch 'main' into himself65/2025/02/27/bump 2025-03-07 15:48:20 +07:00
thucpn 53c3cc45b7 fix: lock 2025-03-07 15:42:51 +07:00
thucpn 3ed84d1a0a Merge branch 'main' into himself65/2025/02/27/bump 2025-03-07 15:30:19 +07:00
Alex Yang 840e31d876 fix: mjs 2025-03-01 07:29:51 -08:00
Alex Yang edc0d9a679 fix: type module 2025-02-28 13:36:28 -08:00
Alex Yang 6d63b2d18a fix: as 2025-02-28 13:34:13 -08:00
Alex Yang 50ec55f7fa fix: as 2025-02-28 13:34:13 -08:00
Alex Yang 78d5aafd88 fix: dev mod 2025-02-28 13:34:12 -08:00
Alex Yang 484d4a0ccd fix: not expect error 2025-02-28 13:34:12 -08:00
Alex Yang 9165909b3c docs: update install section 2025-02-28 13:34:12 -08:00
Alex Yang d7e7590438 fix: shiki 2025-02-28 13:34:12 -08:00
Alex Yang 062d441df7 fix: cleanup unused deps 2025-02-28 13:34:12 -08:00
Alex Yang 8945a6f8de chore: remove 02_nextjs 2025-02-28 13:34:12 -08:00
Alex Yang bd1cc535c0 feat: use fumadoc 15 + tailwind 4 2025-02-28 13:34:12 -08:00
78 changed files with 2127 additions and 4201 deletions
+20 -19
View File
@@ -8,11 +8,11 @@
"start": "next start",
"postdev": "fumadocs-mdx",
"postbuild": "fumadocs-mdx && tsx scripts/post-build.mts",
"build:docs": "cross-env NODE_OPTIONS=\"--max-old-space-size=8192\" typedoc && node ./scripts/generate-docs.mjs"
"build:docs": "cross-env NODE_OPTIONS=\"--max-old-space-size=8192\" typedoc && tsx scripts/generate-docs.mts"
},
"dependencies": {
"@icons-pack/react-simple-icons": "^10.1.0",
"@llamaindex/chat-ui": "0.0.9",
"@llamaindex/chat-ui": "0.2.0",
"@llamaindex/cloud": "workspace:*",
"@llamaindex/core": "workspace:*",
"@llamaindex/node-parser": "workspace:*",
@@ -27,24 +27,24 @@
"@radix-ui/react-slider": "^1.2.1",
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-tooltip": "^1.1.4",
"@vercel/functions": "^1.5.0",
"@scalar/api-client-react": "^1.1.25",
"@vercel/functions": "^1.5.0",
"ai": "^3.4.33",
"class-variance-authority": "^0.7.0",
"clsx": "2.1.1",
"foxact": "^0.2.41",
"framer-motion": "^11.11.17",
"fumadocs-core": "^14.7.7",
"fumadocs-docgen": "^1.3.7",
"fumadocs-mdx": "^11.5.3",
"fumadocs-openapi": "^5.12.0",
"fumadocs-twoslash": "^2.0.3",
"fumadocs-typescript": "^3.0.3",
"fumadocs-ui": "^14.7.7",
"fumadocs-core": "^15.0.15",
"fumadocs-docgen": "^2.0.0",
"fumadocs-mdx": "^11.5.6",
"fumadocs-openapi": "^6.3.0",
"fumadocs-twoslash": "^3.1.0",
"fumadocs-typescript": "^3.1.0",
"fumadocs-ui": "^15.0.15",
"hast-util-to-jsx-runtime": "^2.3.2",
"llamaindex": "workspace:*",
"lucide-react": "^0.460.0",
"next": "15.1.7",
"next": "15.2.0",
"next-themes": "^0.4.3",
"react": "^19.0.0",
"react-dom": "^19.0.0",
@@ -55,8 +55,8 @@
"rehype-katex": "^7.0.1",
"remark-math": "^6.0.0",
"rimraf": "^6.0.1",
"shiki": "^2.3.2",
"shiki-magic-move": "^1.0.0",
"shiki": "^3.1.0",
"shiki-magic-move": "^1.0.1",
"swr": "^2.2.5",
"tailwind-merge": "^2.5.2",
"tailwindcss-animate": "^1.0.7",
@@ -68,26 +68,27 @@
},
"devDependencies": {
"@next/env": "^15.0.3",
"@tailwindcss/postcss": "^4.0.9",
"@types/mdx": "^2.0.13",
"@types/node": "22.9.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@types/react": "^19.0.10",
"@types/react-dom": "^19.0.4",
"autoprefixer": "^10.4.20",
"cross-env": "^7.0.3",
"fast-glob": "^3.3.2",
"gray-matter": "^4.0.3",
"monaco-editor-webpack-plugin": "^7.1.0",
"postcss": "^8.4.49",
"postcss": "^8.5.3",
"raw-loader": "^4.0.2",
"remark": "^15.0.1",
"remark-gfm": "^4.0.0",
"remark-mdx": "^3.1.0",
"remark-stringify": "^11.0.0",
"tailwindcss": "^3.4.15",
"tsx": "^4.19.2",
"tailwindcss": "^4.0.9",
"tsx": "^4.19.3",
"typedoc": "0.27.4",
"typedoc-plugin-markdown": "^4.3.1",
"typedoc-plugin-merge-modules": "^6.1.0",
"typescript": "^5.7.2"
"typescript": "^5.7.3"
}
}
-6
View File
@@ -1,6 +0,0 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};
+5
View File
@@ -0,0 +1,5 @@
export default {
plugins: {
"@tailwindcss/postcss": {},
},
};
@@ -1,8 +1,6 @@
import * as OpenAPI from "fumadocs-openapi";
import { generateFiles } from "fumadocs-typescript";
import fs from "node:fs";
import * as path from "node:path";
import { fileURLToPath } from "node:url";
import { rimrafSync } from "rimraf";
const out = "./src/content/docs/cloud/api";
@@ -15,28 +13,17 @@ rimrafSync(out, {
},
});
void OpenAPI.generateFiles({
input: [
fileURLToPath(
new URL("../../../packages/cloud/openapi.json", import.meta.url),
),
],
output: out,
groupBy: "tag",
});
void generateFiles({
input: ["./src/content/docs/api/**/*.mdx"],
output: (file) => path.resolve(path.dirname(file), path.basename(file)),
transformOutput,
});
function transformOutput(filePath, content) {
function transformOutput(filePath: string, content: string) {
const fileName = path.basename(filePath);
let title = fileName.split(".")[0];
let pageContent = content;
if (title === "index") title = "LlamaIndex API Reference";
return `---\ntitle: ${title}\n---\n\n${transformAbsoluteUrl(pageContent, filePath)}`;
return `---\ntitle: ${title}\n---\n\n${transformAbsoluteUrl(content, filePath)}`;
}
/**
@@ -46,20 +33,17 @@ function transformOutput(filePath, content) {
* [text](BaseVectorStore.mdx#constructors) -> [text](/docs/api/classes/BaseVectorStore#constructors)
* [text](TaskStep.mdx) -> [text](/docs/api/type-aliases/TaskStep)
*/
function transformAbsoluteUrl(content, filePath) {
function transformAbsoluteUrl(content: string, filePath: string) {
const group = path.dirname(filePath).split(path.sep).pop();
return content.replace(
/\]\(([^)]+)\.mdx([^)]*)\)/g,
(match, slug, anchor) => {
const slugParts = slug.split("/");
const fileName = slugParts[slugParts.length - 1];
const fileGroup = slugParts[slugParts.length - 2] ?? group;
const result = ["/docs/api", fileGroup, fileName, anchor]
.filter(Boolean)
.join("/");
return `](${result})`;
},
);
return content.replace(/\]\(([^)]+)\.mdx([^)]*)\)/g, (_, slug, anchor) => {
const slugParts = slug.split("/");
const fileName = slugParts[slugParts.length - 1];
const fileGroup = slugParts[slugParts.length - 2] ?? group;
const result = ["/docs/api", fileGroup, fileName, anchor]
.filter(Boolean)
.join("/");
return `](${result})`;
});
}
// append meta.json for API page
+4 -7
View File
@@ -1,11 +1,7 @@
import { upsertBatchPipelineDocumentsApiV1PipelinesPipelineIdDocumentsPut } from "@llamaindex/cloud/api";
import fg from "fast-glob";
import {
fileGenerator,
remarkDocGen,
remarkInstall,
typescriptGenerator,
} from "fumadocs-docgen";
import { fileGenerator, remarkDocGen, remarkInstall } from "fumadocs-docgen";
import { remarkAutoTypeTable } from "fumadocs-typescript";
import matter from "gray-matter";
import * as fs from "node:fs/promises";
import path, { relative } from "node:path";
@@ -21,7 +17,8 @@ async function processContent(content: string): Promise<string> {
const file = await remark()
.use(remarkMdx)
.use(remarkGfm)
.use(remarkDocGen, { generators: [typescriptGenerator(), fileGenerator()] })
.use(remarkAutoTypeTable)
.use(remarkDocGen, { generators: [fileGenerator()] })
.use(remarkInstall, { persist: { id: "package-manager" } })
.use(remarkStringify)
.process(content);
+10 -40
View File
@@ -1,6 +1,12 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
@import "tailwindcss";
@import "fumadocs-ui/css/neutral.css";
@import "fumadocs-ui/css/preset.css";
@plugin "tailwindcss-animate";
@source '../../node_modules/fumadocs-ui/dist/**/*.js';
@source "../../node_modules/fumadocs-openapi/dist/**/*.js",
@source '../../node_modules/@llamaindex/chat-ui/dist/**/*.js';
@config "../../tailwind.config.mjs";
@layer base {
:root {
--page-max-width: 1840px;
@@ -46,6 +52,7 @@
--chart-5: 27 87% 67%;
--radius: 0.5rem;
}
.dark {
--color-neutral-000: #0e0c15;
--color-neutral-100: #252134;
@@ -87,40 +94,3 @@
--chart-5: 340 75% 55%;
}
}
@layer base {
* {
@apply border-border;
}
body {
@apply bg-background text-foreground;
}
/*
* Override default styles for Markdown
*/
.prose
:where(blockquote):not(
:where([class~="not-prose"], [class~="not-prose"] *)
) {
font-style: normal !important;
}
.prose
:where(blockquote p:first-of-type):not(
:where([class~="not-prose"], [class~="not-prose"] *)
):before {
content: none !important;
}
.prose
:where(blockquote p:first-of-type):not(
:where([class~="not-prose"], [class~="not-prose"] *)
):after {
content: none !important;
}
.prose
:where(code):not(:where([class~="not-prose"], [class~="not-prose"] *)) {
@apply text-blue-600 !important;
}
}
+4 -5
View File
@@ -1,5 +1,5 @@
import * as Base from "fumadocs-ui/components/codeblock";
import { toJsxRuntime, type Jsx } from "hast-util-to-jsx-runtime";
import { toJsxRuntime } from "hast-util-to-jsx-runtime";
import { Fragment } from "react";
import { jsx, jsxs } from "react/jsx-runtime";
import { codeToHast } from "shiki";
@@ -39,12 +39,11 @@ export async function CodeBlock({
});
const rendered = toJsxRuntime(hast, {
jsx: jsx as Jsx,
jsxs: jsxs as Jsx,
jsx: jsx,
jsxs: jsxs,
Fragment,
development: false,
development: process.env.NODE_ENV === "development",
components: {
// @ts-expect-error -- JSX component
pre: Base.Pre,
},
});
@@ -1,11 +1,16 @@
"use client";
import { ChatInput, ChatMessages, ChatSection } from "@llamaindex/chat-ui";
import {
ChatHandler,
ChatInput,
ChatMessages,
ChatSection,
} from "@llamaindex/chat-ui";
import { useChat } from "ai/react";
export const ChatDemo = () => {
const handler = useChat();
return (
<ChatSection handler={handler}>
<ChatSection handler={handler as ChatHandler}>
<ChatMessages>
<ChatMessages.List className="h-auto max-h-[400px]" />
<ChatMessages.Actions />
@@ -1,23 +1,25 @@
"use client";
import {
ChatHandler,
ChatInput,
ChatMessage,
ChatMessages,
ChatSection as ChatSectionUI,
Message,
} from "@llamaindex/chat-ui";
import { useChatRSC } from "./use-chat-rsc";
export const ChatSectionRSC = () => {
const handler = useChatRSC();
return (
<ChatSectionUI handler={handler}>
<ChatSectionUI handler={handler as ChatHandler}>
<ChatMessages>
<ChatMessages.List className="h-auto max-h-[400px]">
{handler.messages.map((message, index) => (
<ChatMessage
key={index}
message={message}
message={message as Message}
isLast={index === handler.messages.length - 1}
>
<ChatMessage.Avatar />
@@ -34,6 +34,7 @@ First we'll need to pull in our dependencies. These are:
import { FunctionTool, Settings } from "llamaindex";
import { OpenAI, OpenAIAgent } from "@llamaindex/openai";
import "dotenv/config";
import { z } from "zod";
```
### Initialize your LLM
@@ -86,20 +87,14 @@ This is the most complicated part of creating an agent. We need to define a `Fun
const tool = FunctionTool.from(sumNumbers, {
name: "sumNumbers",
description: "Use this function to sum two numbers",
parameters: {
type: "object",
properties: {
a: {
type: "number",
description: "First number to sum",
},
b: {
type: "number",
description: "Second number to sum",
},
},
required: ["a", "b"],
},
parameters: z.object({
a: z.number({
description: "First number to sum",
}),
b: z.number({
description: "Second number to sum",
}),
}),
});
```
@@ -2,7 +2,7 @@
title: A RAG agent that does math
---
In [our third iteration of the agent](https://github.com/run-llama/ts-agents/blob/main/3_rag_and_tools/agent.ts) we've combined the two previous agents, so we've defined both `sumNumbers` and a `QueryEngineTool` and created an array of two tools:
In [our third iteration of the agent](https://github.com/run-llama/ts-agents/blob/main/3_rag_and_tools/agent.ts) we've combined the two previous agents, so we've defined both `sumNumbers` and a `QueryEngineTool` and created an array of two tools. The tools support both Zod and JSON Schema for parameter definition:
```javascript
// define the query engine as a tool
@@ -17,24 +17,42 @@ const tools = [
FunctionTool.from(sumNumbers, {
name: "sumNumbers",
description: "Use this function to sum two numbers",
parameters: {
type: "object",
properties: {
a: {
type: "number",
description: "First number to sum",
},
b: {
type: "number",
description: "Second number to sum",
},
},
required: ["a", "b"],
},
parameters: z.object({
a: z.number({
description: "First number to sum",
}),
b: z.number({
description: "Second number to sum",
}),
}),
}),
];
```
You can also use JSON Schema to define the tool parameters as an alternative to Zod.
```javascript
FunctionTool.from(sumNumbers, {
name: "sumNumbers",
description: "Use this function to sum two numbers",
parameters: {
type: "object",
properties: {
a: {
type: "number",
description: "First number to sum",
},
b: {
type: "number",
description: "Second number to sum",
},
},
required: ["a", "b"],
},
}),
```
These tool descriptions are identical to the ones we previously defined. Now let's ask it 3 questions in a row:
```javascript
@@ -3,8 +3,6 @@ title: Using API Route
description: Chat interface for your LlamaIndexTS application using API Route
---
import { ChatDemo } from '../../../../../components/demo/chat/api/demo';
import "@llamaindex/chat-ui/styles/code.css";
import "@llamaindex/chat-ui/styles/katex.css";
Using [chat-ui](https://github.com/run-llama/chat-ui), it's easy to add a chat interface to your LlamaIndexTS application.
You just need to create an API route that provides an `api/chat` endpoint and a chat component to consume the API.
@@ -0,0 +1,22 @@
---
title: Install @llamaindex/chat
description: Chat interface for your LlamaIndexTS application
---
## Quick Start
You can quickly add a chatbot to your project by using Shadcn CLI command:
```sh
npx shadcn@latest add https://ui.llamaindex.ai/r/chat.json
```
## Manual Installation
To install the package, run the following command in your project directory:
```sh
npm install @llamaindex/chat-ui
```
For more information, check out the [github.comrun-llama/chat-ui](https://github.com/run-llama/chat-ui)
@@ -1,6 +1,6 @@
{
"title": "Chat-UI",
"title": "Chat UI",
"description": "Use chat-ui to add a chat interface to your LlamaIndexTS application.",
"defaultOpen": false,
"pages": ["chat", "rsc"]
"pages": ["install", "chat", "rsc"]
}
@@ -3,8 +3,6 @@ title: Using Next.js RSC
description: Chat interface for your LlamaIndexTS application using Next.js RSC
---
import { ChatDemoRSC } from '../../../../../components/demo/chat/rsc/demo';
import "@llamaindex/chat-ui/styles/code.css";
import "@llamaindex/chat-ui/styles/katex.css";
Using [chat-ui](https://github.com/run-llama/chat-ui), it's easy to add a chat interface to your LlamaIndexTS application using [Next.js RSC](https://nextjs.org/docs/app/building-your-application/rendering/server-components) and [Vercel AI RSC](https://sdk.vercel.ai/docs/ai-sdk-rsc/overview).
@@ -127,26 +127,21 @@ async function main() {
```ts
import { BEDROCK_MODELS, Bedrock } from "@llamaindex/community";
import { FunctionTool, LLMAgent } from "llamaindex";
import { z } from "zod";
const sumNumbers = FunctionTool.from(
({ a, b }: { a: number; b: number }) => `${a + b}`,
{
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"],
},
parameters: z.object({
a: z.number({
description: "The first number",
}),
b: z.number({
description: "The second number",
}),
}),
},
);
@@ -155,20 +150,14 @@ const divideNumbers = FunctionTool.from(
{
name: "divideNumbers",
description: "Use this function to divide two numbers",
parameters: {
type: "object",
properties: {
a: {
type: "number",
description: "The dividend a to divide",
},
b: {
type: "number",
description: "The divisor b to divide by",
},
},
required: ["a", "b"],
},
parameters: z.object({
a: z.number({
description: "The dividend a to divide",
}),
b: z.number({
description: "The divisor b to divide by",
}),
}),
},
);
@@ -39,16 +39,11 @@ const queryKnowledgeBase = async ({ question }, { userToken }) => {
const kbTool = FunctionTool.from(queryKnowledgeBase, {
name: 'queryKnowledgeBase',
description: 'Query knowledge base',
parameters: {
type: 'object',
properties: {
question: {
type: 'string',
description: 'The user question',
},
},
required: ['question'],
},
parameters: z.object({
question: z.string({
description: 'The user question',
}),
}),
});
// create an agent
@@ -1,5 +1,3 @@
import { createPreset } from "fumadocs-ui/tailwind-plugin";
/** @type {import('tailwindcss').Config} */
export default {
darkMode: ["class"],
@@ -8,13 +6,7 @@ export default {
"./src/app/**/*.{ts,tsx}",
"./src/content/**/*.{md,mdx}",
"./src/mdx-components.{ts,tsx}",
"./node_modules/fumadocs-ui/dist/**/*.js",
"./node_modules/fumadocs-openapi/dist/**/*.js",
"./node_modules/@llamaindex/chat-ui/**/*.{ts,tsx}",
],
presets: [createPreset()],
// eslint-disable-next-line @typescript-eslint/no-require-imports
plugins: [require("tailwindcss-animate")],
theme: {
extend: {
borderRadius: {
+1 -1
View File
@@ -11,7 +11,7 @@
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20241112.0",
"typescript": "^5.7.2",
"typescript": "^5.7.3",
"wrangler": "^3.89.0"
},
"dependencies": {
@@ -16,7 +16,7 @@
"@cloudflare/workers-types": "^4.20241112.0",
"@vitest/runner": "2.1.5",
"@vitest/snapshot": "2.1.5",
"typescript": "^5.7.2",
"typescript": "^5.7.3",
"vitest": "2.1.5",
"wrangler": "^3.87.0"
},
@@ -9,7 +9,7 @@
"preview": "vite preview"
},
"devDependencies": {
"typescript": "^5.7.2",
"typescript": "^5.7.3",
"vite": "^5.4.12",
"vite-plugin-wasm": "^3.3.0"
},
+4 -6
View File
@@ -10,18 +10,16 @@
"dependencies": {
"ai": "^4.0.0",
"llamaindex": "workspace:*",
"next": "15.1.7",
"next": "15.2.0",
"react": "19.0.0",
"react-dom": "19.0.0"
},
"devDependencies": {
"@types/node": "^22.9.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@types/react": "^19.0.10",
"@types/react-dom": "^19.0.4",
"eslint": "9.16.0",
"eslint-config-next": "15.1.0",
"postcss": "^8.4.49",
"tailwindcss": "^3.4.15",
"typescript": "^5.7.2"
"typescript": "^5.7.3"
}
}
@@ -1,8 +0,0 @@
/** @type {import('postcss-load-config').Config} */
const config = {
plugins: {
tailwindcss: {},
},
};
export default config;
@@ -1,3 +0,0 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
@@ -1,6 +1,5 @@
import type { Metadata } from "next";
import { Inter } from "next/font/google";
import "./globals.css";
const inter = Inter({ subsets: ["latin"] });
@@ -1,20 +0,0 @@
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;
@@ -9,14 +9,14 @@
},
"dependencies": {
"llamaindex": "workspace:*",
"next": "15.1.7",
"react": "^18.3.1",
"react-dom": "^18.3.1"
"next": "15.2.0",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"devDependencies": {
"@types/node": "^22.9.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"typescript": "^5.7.2"
"@types/react": "^19.0.10",
"@types/react-dom": "^19.0.4",
"typescript": "^5.7.3"
}
}
@@ -8,21 +8,19 @@
"start": "next start"
},
"dependencies": {
"llamaindex": "workspace:*",
"@llamaindex/huggingface": "workspace:*",
"@llamaindex/readers": "workspace:*",
"next": "15.1.7",
"llamaindex": "workspace:*",
"next": "15.2.0",
"react": "19.0.0",
"react-dom": "19.0.0"
},
"devDependencies": {
"@types/node": "^22.9.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@types/react": "^19.0.10",
"@types/react-dom": "^19.0.4",
"eslint": "9.16.0",
"eslint-config-next": "15.1.0",
"postcss": "^8.4.49",
"tailwindcss": "^3.4.15",
"typescript": "^5.7.2"
"typescript": "^5.7.3"
}
}
@@ -1,8 +0,0 @@
/** @type {import('postcss-load-config').Config} */
const config = {
plugins: {
tailwindcss: {},
},
};
export default config;
@@ -1,3 +0,0 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
@@ -1,6 +1,5 @@
import type { Metadata } from "next";
import { Inter } from "next/font/google";
import "./globals.css";
const inter = Inter({ subsets: ["latin"] });
@@ -1,20 +0,0 @@
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;
@@ -15,7 +15,7 @@
"devDependencies": {
"@size-limit/preset-big-lib": "^11.1.6",
"size-limit": "^11.1.6",
"typescript": "^5.7.2",
"typescript": "^5.7.3",
"vite": "^6.1.0"
},
"dependencies": {
+4 -4
View File
@@ -17,10 +17,10 @@
"waku": "0.21.20"
},
"devDependencies": {
"@types/react": "18.3.12",
"@types/react-dom": "18.3.1",
"@types/react": "19.0.10",
"@types/react-dom": "19.0.4",
"autoprefixer": "^10.4.20",
"tailwindcss": "^3.4.15",
"typescript": "5.7.2"
"tailwindcss": "^4.0.9",
"typescript": "5.7.3"
}
}
@@ -1,7 +0,0 @@
/** @type {import('postcss-load-config').Config} */
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};
@@ -0,0 +1,5 @@
export default {
plugins: {
"@tailwindcss/postcss": {},
},
};
@@ -1,4 +1,2 @@
@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;
@import "tailwindcss";
+22 -38
View File
@@ -1,4 +1,5 @@
import { FunctionTool } from "llamaindex";
import { z } from "zod";
function sumNumbers({ a, b }: { a: number; b: number }) {
return `${a + b}`;
@@ -11,39 +12,27 @@ function divideNumbers({ a, b }: { a: number; b: number }) {
export const sumNumbersTool = FunctionTool.from(sumNumbers, {
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"],
},
parameters: z.object({
a: z.number({
description: "The first number",
}),
b: z.number({
description: "The second number",
}),
}),
});
export const divideNumbersTool = FunctionTool.from(divideNumbers, {
name: "divideNumbers",
description: "Use this function to divide two numbers",
parameters: {
type: "object",
properties: {
a: {
type: "number",
description: "The first number",
},
b: {
type: "number",
description: "The second number",
},
},
required: ["a", "b"],
},
parameters: z.object({
a: z.number({
description: "The first number",
}),
b: z.number({
description: "The second number",
}),
}),
});
// should always return the 72 degrees
@@ -54,15 +43,10 @@ export const getWeatherTool = FunctionTool.from(
{
name: "getWeather",
description: "Get the weather for a city",
parameters: {
type: "object",
properties: {
city: {
type: "string",
description: "The city to get the weather for",
},
},
required: ["city"],
},
parameters: z.object({
city: z.string({
description: "The city to get the weather for",
}),
}),
},
);
+5 -4
View File
@@ -10,22 +10,23 @@
},
"devDependencies": {
"@faker-js/faker": "^9.2.0",
"@huggingface/transformers": "^3.0.2",
"@llamaindex/anthropic": "workspace:*",
"@llamaindex/clip": "workspace:*",
"@llamaindex/core": "workspace:*",
"@llamaindex/env": "workspace:*",
"@llamaindex/ollama": "workspace:*",
"@llamaindex/openai": "workspace:*",
"@llamaindex/pinecone": "workspace:*",
"@llamaindex/postgres": "workspace:*",
"@llamaindex/clip": "workspace:*",
"@llamaindex/anthropic": "workspace:*",
"@types/node": "^22.9.0",
"@types/pg": "^8.11.8",
"@huggingface/transformers": "^3.0.2",
"consola": "^3.2.3",
"dotenv": "^16.4.5",
"llamaindex": "workspace:*",
"pg": "^8.12.0",
"pgvector": "0.2.0",
"tsx": "^4.19.0"
"tsx": "^4.19.3",
"zod": "^3.24.2"
}
}
+19 -29
View File
@@ -1,5 +1,6 @@
import { OpenAI, OpenAIAgent } from "@llamaindex/openai";
import { FunctionTool } from "llamaindex";
import { OpenAI } from "@llamaindex/openai";
import { AgentWorkflow, FunctionTool } from "llamaindex";
import { z } from "zod";
const csvData =
"TITLE,RELEASE_YEAR,SCORE,NUMBER_OF_VOTES,DURATION,MAIN_GENRE,MAIN_PRODUCTION\nDavid Attenborough: A Life on Our Planet,2020,9,31180,83,documentary,GB\nInception,2010,8.8,2268288,148,scifi,GB\nForrest Gump,1994,8.8,1994599,142,drama,US\nAnbe Sivam,2003,8.7,20595,160,comedy,IN\nBo Burnham: Inside,2021,8.7,44074,87,comedy,US\nSaving Private Ryan,1998,8.6,1346020,169,drama,US\nDjango Unchained,2012,8.4,1472668,165,western,US\nDangal,2016,8.4,180247,161,action,IN\nBo Burnham: Make Happy,2016,8.4,14356,60,comedy,US\nLouis C.K.: Hilarious,2010,8.4,11973,84,comedy,US\nDave Chappelle: Sticks & Stones,2019,8.4,25687,65,comedy,US\n3 Idiots,2009,8.4,385782,170,comedy,IN\nBlack Friday,2004,8.4,20611,143,crime,IN\nSuper Deluxe,2019,8.4,13680,176,thriller,IN\nWinter on Fire: Ukraine's Fight for Freedom,2015,8.3,17710,98,documentary,UA\nOnce Upon a Time in America,1984,8.3,342335,229,drama,US\nTaxi Driver,1976,8.3,795222,113,crime,US\nLike Stars on Earth,2007,8.3,188234,165,drama,IN\nBo Burnham: What.,2013,8.3,11488,60,comedy,US\nFull Metal Jacket,1987,8.3,723306,116,drama,GB\nWarrior,2011,8.2,463276,140,drama,US\nDrishyam,2015,8.2,79075,163,thriller,IN\nQueen,2014,8.2,64805,146,drama,IN\nPaan Singh Tomar,2012,8.2,35888,135,drama,IN";
@@ -8,13 +9,9 @@ const userQuestion = "which are the best comedies after 2010?";
(async () => {
// The agent will succeed if we increase `maxTokens` to 1024
const llm = new OpenAI({ model: "gpt-4-turbo", maxTokens: 256 });
const llm = new OpenAI({ model: "gpt-4-turbo", maxTokens: 1024 });
type Input = {
code: string;
};
// initiate fake code interpreter
const interpreterTool = FunctionTool.from<Input>(
const interpreterTool = FunctionTool.from(
({ code }) => {
console.log(
`To answer the user's question, call the following code:\n${code}`,
@@ -25,41 +22,34 @@ const userQuestion = "which are the best comedies after 2010?";
name: "interpreter",
description:
"Execute python code in a Jupyter notebook cell and return any result, stdout, stderr, display_data, and error.",
parameters: {
type: "object",
properties: {
code: {
type: "string",
description: "The python code to execute in a single cell.",
},
},
required: ["code"],
},
parameters: z.object({
code: z.string({
description: "The python code to execute in a single cell.",
}),
}),
},
);
const systemPrompt =
"You are a Python interpreter.\n - You are given tasks to complete and you run python code to solve them.\n - The python code runs in a Jupyter notebook. Every time you call $(interpreter) tool, the python code is executed in a separate cell. It's okay to make multiple calls to $(interpreter).\n - Display visualizations using matplotlib or any other visualization library directly in the notebook. Shouldn't save the visualizations to a file, just return the base64 encoded data.\n - You can install any pip package (if it exists) if you need to but the usual packages for data analysis are already preinstalled.\n - You can run any python code you want in a secure environment.";
const agent = new OpenAIAgent({
llm,
const workflow = AgentWorkflow.fromTools({
tools: [interpreterTool],
llm,
verbose: false,
systemPrompt,
verbose: true,
});
console.log(`User question: ${userQuestion}\n`);
await agent.chat({
message: [
const result = await workflow.run(userQuestion, {
chatHistory: [
{
type: "text",
text: userQuestion,
},
{
type: "text",
text: `Use data from following CSV raw contents:\n${csvData}`,
role: "user",
content: `Use data from following CSV raw contents:\n${csvData}`,
},
],
});
console.log(result);
})();
+6 -10
View File
@@ -1,5 +1,6 @@
import { OpenAI } from "@llamaindex/openai";
import { FunctionTool, ToolCallOptions } from "llamaindex";
import { z } from "zod";
(async () => {
// The tool call will generate a partial JSON for `gpt-4-turbo`
@@ -27,16 +28,11 @@ async function callLLM(init: { model: string }) {
name: "interpreter",
description:
"Execute python code in a Jupyter notebook cell and return any result, stdout, stderr, display_data, and error.",
parameters: {
type: "object",
properties: {
code: {
type: "string",
description: "The python code to execute in a single cell.",
},
},
required: ["code"],
},
parameters: z.object({
code: z.string({
description: "The python code to execute in a single cell.",
}),
}),
},
);
+16 -36
View File
@@ -1,25 +1,16 @@
import { OpenAIAgent } from "@llamaindex/openai";
import { FunctionTool } from "llamaindex";
import { OpenAI } from "@llamaindex/openai";
import { AgentWorkflow, FunctionTool } from "llamaindex";
import { z } from "zod";
const sumNumbers = FunctionTool.from(
({ a, b }: { a: number; b: number }) => `${a + b}`,
{
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"],
},
parameters: z.object({
a: z.number().describe("The first number"),
b: z.number().describe("The second number"),
}),
},
);
@@ -28,33 +19,22 @@ const divideNumbers = FunctionTool.from(
{
name: "divideNumbers",
description: "Use this function to divide two numbers",
parameters: {
type: "object",
properties: {
a: {
type: "number",
description: "The dividend a to divide",
},
b: {
type: "number",
description: "The divisor b to divide by",
},
},
required: ["a", "b"],
},
parameters: z.object({
a: z.number().describe("The dividend a to divide"),
b: z.number().describe("The divisor b to divide by"),
}),
},
);
async function main() {
const agent = new OpenAIAgent({
const workflow = AgentWorkflow.fromTools({
tools: [sumNumbers, divideNumbers],
llm: new OpenAI({ model: "gpt-4o-mini" }),
verbose: false,
});
const response = await agent.chat({
message: "How much is 5 + 5? then divide by 2",
});
console.log(response.message);
const response = await workflow.run("How much is 5 + 5? then divide by 2");
console.log(response.data);
}
void main().then(() => {
+4 -10
View File
@@ -6,6 +6,7 @@ import {
NodeWithScore,
VectorStoreIndex,
} from "llamaindex";
import { z } from "zod";
async function main() {
// Load the documents
@@ -32,16 +33,9 @@ async function main() {
{
name: "get_abramov_info",
description: "Get information about the Abramov documents",
parameters: {
type: "object",
properties: {
query: {
type: "string",
description: "The query about Abramov",
},
},
required: ["query"],
},
parameters: z.object({
query: z.string().describe("The query about Abramov"),
}),
},
);
+11 -31
View File
@@ -1,5 +1,6 @@
import { OpenAIAgent } from "@llamaindex/openai";
import { FunctionTool } from "llamaindex";
import { z } from "zod";
// Define a function to sum two numbers
function sumNumbers({ a, b }: { a: number; b: number }) {
@@ -11,50 +12,29 @@ 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 sumSchema = z.object({
a: z.number().describe("The first number"),
b: z.number().describe("The second number"),
});
const divideJSON = {
type: "object",
properties: {
a: {
type: "number",
description: "The dividend",
},
b: {
type: "number",
description: "The divisor",
},
},
required: ["a", "b"],
} as const;
const divideSchema = z.object({
a: z.number().describe("The dividend"),
b: z.number().describe("The divisor"),
});
async function main() {
// Create a function tool from the sum function
const functionTool = FunctionTool.from(sumNumbers, {
name: "sumNumbers",
description: "Use this function to sum two numbers",
parameters: sumJSON,
parameters: sumSchema,
});
// Create a function tool from the divide function
const functionTool2 = FunctionTool.from(divideNumbers, {
name: "divideNumbers",
description: "Use this function to divide two numbers",
parameters: divideJSON,
parameters: divideSchema,
});
// Create an OpenAIAgent with the function tools
+7 -20
View File
@@ -1,4 +1,5 @@
import { FunctionTool } from "llamaindex";
import { z } from "zod";
export const getCurrentIDTool = FunctionTool.from(
() => {
@@ -19,16 +20,9 @@ export const getUserInfoTool = FunctionTool.from(
{
name: "get_user_info",
description: "Get user info",
parameters: {
type: "object",
properties: {
userId: {
type: "string",
description: "The user id",
},
},
required: ["userId"],
},
parameters: z.object({
userId: z.string().describe("The user id"),
}),
},
);
@@ -40,15 +34,8 @@ export const getWeatherTool = FunctionTool.from(
{
name: "get_weather",
description: "Get the current weather for a location",
parameters: {
type: "object",
properties: {
address: {
type: "string",
description: "The address",
},
},
required: ["address"],
},
parameters: z.object({
address: z.string().describe("The address"),
}),
},
);
+14 -10
View File
@@ -1,24 +1,28 @@
import { OpenAI, OpenAIAgent } from "@llamaindex/openai";
import { OpenAI } from "@llamaindex/openai";
import { AgentStream, AgentWorkflow } from "llamaindex";
import { WikipediaTool } from "../wiki";
async function main() {
const llm = new OpenAI({ model: "gpt-4-turbo" });
const wikiTool = new WikipediaTool();
// Create an OpenAIAgent with the Wikipedia tool
const agent = new OpenAIAgent({
llm,
const workflow = AgentWorkflow.fromTools({
tools: [wikiTool],
llm,
verbose: false,
});
// Chat with the agent
const response = await agent.chat({
message: "Who was Goethe?",
stream: true,
});
const context = workflow.run("Who was Goethe?");
for await (const { delta } of response) {
process.stdout.write(delta);
for await (const event of context) {
if (event instanceof AgentStream) {
for (const chunk of event.data.delta) {
process.stdout.write(chunk);
}
} else {
console.log(event);
}
}
}
+5 -11
View File
@@ -1,5 +1,6 @@
import { Anthropic, AnthropicAgent } from "@llamaindex/anthropic";
import { FunctionTool, Settings } from "llamaindex";
import { z } from "zod";
import { WikipediaTool } from "../wiki";
Settings.callbackManager.on("llm-tool-call", (event) => {
@@ -14,23 +15,16 @@ const anthropic = new Anthropic({
const agent = new AnthropicAgent({
llm: anthropic,
tools: [
FunctionTool.from<{ location: string }>(
FunctionTool.from(
(query) => {
return `The weather in ${query.location} is sunny`;
},
{
name: "weather",
description: "Get the weather",
parameters: {
type: "object",
properties: {
location: {
type: "string",
description: "The location to get the weather for",
},
},
required: ["location"],
},
parameters: z.object({
location: z.string().describe("The location to get the weather for"),
}),
},
),
new WikipediaTool(),
+13 -42
View File
@@ -1,5 +1,6 @@
import { Gemini, GEMINI_MODEL } from "@llamaindex/google";
import { FunctionTool, LLMAgent, Settings } from "llamaindex";
import { z } from "zod";
Settings.callbackManager.on("llm-tool-call", (event) => {
console.log(event.detail);
@@ -14,20 +15,10 @@ const sumNumbers = FunctionTool.from(
{
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"],
},
parameters: z.object({
a: z.number().describe("The first number"),
b: z.number().describe("The second number"),
}),
},
);
@@ -36,20 +27,10 @@ const divideNumbers = FunctionTool.from(
{
name: "divideNumbers",
description: "Use this function to divide two numbers",
parameters: {
type: "object",
properties: {
a: {
type: "number",
description: "The dividend a to divide",
},
b: {
type: "number",
description: "The divisor b to divide by",
},
},
required: ["a", "b"],
},
parameters: z.object({
a: z.number().describe("The dividend a to divide"),
b: z.number().describe("The divisor b to divide by"),
}),
},
);
@@ -58,20 +39,10 @@ const subtractNumbers = FunctionTool.from(
{
name: "subtractNumbers",
description: "Use this function to subtract two numbers",
parameters: {
type: "object",
properties: {
a: {
type: "number",
description: "The number to subtract from",
},
b: {
type: "number",
description: "The number to subtract",
},
},
required: ["a", "b"],
},
parameters: z.object({
a: z.number().describe("The number to subtract from"),
b: z.number().describe("The number to subtract"),
}),
},
);
+2 -2
View File
@@ -64,8 +64,8 @@
},
"devDependencies": {
"@types/node": "^22.9.0",
"tsx": "^4.19.0",
"typescript": "^5.7.2"
"tsx": "^4.19.3",
"typescript": "^5.7.3"
},
"stackblitz": {
"startCommand": "npm start"
+2 -2
View File
@@ -25,7 +25,7 @@
},
"devDependencies": {
"@types/node": "^22.9.0",
"tsx": "^4.19.0",
"typescript": "^5.7.2"
"tsx": "^4.19.3",
"typescript": "^5.7.3"
}
}
+3 -3
View File
@@ -21,7 +21,7 @@
},
"devDependencies": {
"@changesets/cli": "^2.27.5",
"eslint": "9.16.0",
"eslint": "9.22.0",
"eslint-config-next": "^15.1.0",
"eslint-config-prettier": "^9.1.0",
"eslint-config-turbo": "^2.3.3",
@@ -32,8 +32,8 @@
"madge": "^8.0.0",
"prettier": "^3.4.2",
"prettier-plugin-organize-imports": "^4.1.0",
"turbo": "^2.3.3",
"typescript": "^5.7.2",
"turbo": "^2.4.4",
"typescript": "^5.7.3",
"typescript-eslint": "^8.18.0"
},
"packageManager": "pnpm@9.12.3",
@@ -8,7 +8,7 @@
"openai": "^4.73.1"
},
"devDependencies": {
"tsx": "^4.19.0"
"tsx": "^4.19.3"
},
"scripts": {
"start": "node --import tsx --import @llamaindex/autotool/node ./src/index.ts"
@@ -1,3 +0,0 @@
# Rename this file to `.env.local` to use environment variables locally with `next dev`
# https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables
MY_HOST="example.com"
@@ -1,35 +0,0 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# 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
File diff suppressed because it is too large Load Diff
@@ -1,30 +0,0 @@
This is a [LlamaIndex](https://www.llamaindex.ai/) project using [Next.js](https://nextjs.org/) bootstrapped with [`create-llama`](https://github.com/run-llama/LlamaIndexTS/tree/main/packages/create-llama).
## Getting Started
First, install the dependencies:
```
npm install
```
Second, run the development server:
```
npm run 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 LlamaIndex, take a look at the following resources:
- [LlamaIndex Documentation](https://docs.llamaindex.ai) - learn about LlamaIndex (Python features).
- [LlamaIndexTS Documentation](https://ts.llamaindex.ai) - learn about LlamaIndex (Typescript features).
You can check out [the LlamaIndexTS GitHub repository](https://github.com/run-llama/LlamaIndexTS) - your feedback and contributions are welcome!
@@ -1,38 +0,0 @@
"use server";
import { OpenAIAgent } from "llamaindex";
// import your tools on top, that's it
import { runWithStreamableUI } from "@/context";
import "@/tool";
import { convertTools } from "@llamaindex/autotool";
import { createStreamableUI } from "ai/rsc";
import type { ReactNode } from "react";
export async function chatWithAI(message: string): Promise<ReactNode> {
const agent = new OpenAIAgent({
tools: convertTools("llamaindex"),
});
const uiStream = createStreamableUI();
runWithStreamableUI(uiStream, () =>
agent
.chat({
stream: true,
message,
})
.then(async (responseStream) => {
return responseStream.pipeTo(
new WritableStream({
start: () => {
uiStream.append("\n");
},
write: async (message) => {
uiStream.append(message.response);
},
close: () => {
uiStream.done();
},
}),
);
}),
).catch(uiStream.error);
return uiStream.value;
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

@@ -1,91 +0,0 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer base {
:root {
--background: 0 0% 100%;
--foreground: 222.2 47.4% 11.2%;
--muted: 210 40% 96.1%;
--muted-foreground: 215.4 16.3% 46.9%;
--popover: 0 0% 100%;
--popover-foreground: 222.2 47.4% 11.2%;
--border: 214.3 31.8% 91.4%;
--input: 214.3 31.8% 91.4%;
--card: 0 0% 100%;
--card-foreground: 222.2 47.4% 11.2%;
--primary: 222.2 47.4% 11.2%;
--primary-foreground: 210 40% 98%;
--secondary: 210 40% 96.1%;
--secondary-foreground: 222.2 47.4% 11.2%;
--accent: 210 40% 96.1%;
--accent-foreground: 222.2 47.4% 11.2%;
--destructive: 0 100% 50%;
--destructive-foreground: 210 40% 98%;
--ring: 215 20.2% 65.1%;
--radius: 0.5rem;
}
.dark {
--background: 224 71% 4%;
--foreground: 213 31% 91%;
--muted: 223 47% 11%;
--muted-foreground: 215.4 16.3% 56.9%;
--accent: 216 34% 17%;
--accent-foreground: 210 40% 98%;
--popover: 224 71% 4%;
--popover-foreground: 215 20.2% 65.1%;
--border: 216 34% 17%;
--input: 216 34% 17%;
--card: 224 71% 4%;
--card-foreground: 213 31% 91%;
--primary: 210 40% 98%;
--primary-foreground: 222.2 47.4% 1.2%;
--secondary: 222.2 47.4% 11.2%;
--secondary-foreground: 210 40% 98%;
--destructive: 0 63% 31%;
--destructive-foreground: 210 40% 98%;
--ring: 216 34% 17%;
--radius: 0.5rem;
}
}
@layer base {
* {
@apply border-border;
}
body {
@apply bg-background text-foreground;
font-feature-settings:
"rlig" 1,
"calt" 1;
}
.background-gradient {
background-color: #fff;
background-image:
radial-gradient(at 21% 11%, rgba(186, 186, 233, 0.53) 0, transparent 50%),
radial-gradient(at 85% 0, hsla(46, 57%, 78%, 0.52) 0, transparent 50%),
radial-gradient(at 91% 36%, rgba(194, 213, 255, 0.68) 0, transparent 50%),
radial-gradient(at 8% 40%, rgba(251, 218, 239, 0.46) 0, transparent 50%);
}
}
@@ -1,26 +0,0 @@
import type { Metadata } from "next";
import { Inter } from "next/font/google";
import { Toaster } from "sonner";
import "./globals.css";
const inter = Inter({ subsets: ["latin"] });
export const metadata: Metadata = {
title: "Create Llama App",
description: "Generated by create-llama",
};
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body className={inter.className}>
<Toaster />
{children}
</body>
</html>
);
}
@@ -1,11 +0,0 @@
import { ChatSection } from "@/components/chat-section";
export const runtime = "edge";
export default function Home() {
return (
<main className="flex min-h-screen flex-col items-center gap-10 p-24 background-gradient">
<ChatSection />
</main>
);
}
@@ -1,35 +0,0 @@
"use client";
import { chatWithAI } from "@/actions";
import { ReactNode, useActionState } from "react";
import { toast } from "sonner";
export function ChatSection() {
const [state, formAction] = useActionState<ReactNode | null, FormData>(
async (state, payload) => {
const input = payload.get("input") as string | null;
if (!input) {
toast.error("Please type a message");
return null;
}
return chatWithAI(input);
},
null,
);
return (
<form>
<div className="border border-gray-400 p-2 max-w-md">{state}</div>
<input
className="border border-gray-400 p-2"
type="text"
name="input"
placeholder="Type your message here"
/>
<button
className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"
formAction={formAction}
>
Chat
</button>
</form>
);
}
@@ -1,9 +0,0 @@
export function LocationCard() {
return (
<div className="border border-gray-400 p-2 max-w-md">
<h1>Weather</h1>
<p>San Francisco, CA</p>
<p>Sunny</p>
</div>
);
}
@@ -1,23 +0,0 @@
export function Spinner() {
return (
<div role="status">
<svg
aria-hidden="true"
className="w-8 h-8 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600"
viewBox="0 0 100 101"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
fill="currentColor"
/>
<path
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
fill="currentFill"
/>
</svg>
<span className="sr-only">Loading...</span>
</div>
);
}
@@ -1,14 +0,0 @@
import type { createStreamableUI } from "ai/rsc";
import { AsyncLocalStorage } from "node:async_hooks";
type StreamableUI = ReturnType<typeof createStreamableUI>;
const streamUIAsyncLocalStorage = new AsyncLocalStorage<StreamableUI>();
export function getCurrentStreamableUI() {
return streamUIAsyncLocalStorage.getStore();
}
export function runWithStreamableUI<T>(streamUI: StreamableUI, fn: () => T): T {
return streamUIAsyncLocalStorage.run(streamUI, fn);
}
@@ -1,7 +0,0 @@
import { withNext } from "@llamaindex/autotool/next";
import withLlamaIndex from "llamaindex/next";
/** @type {import('next').NextConfig} */
const nextConfig = {};
export default withLlamaIndex(withNext(nextConfig));
@@ -1,37 +0,0 @@
{
"name": "@llamaindex/autotool-02-next-example",
"private": true,
"version": "0.1.134",
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"@llamaindex/autotool": "workspace:*",
"@radix-ui/react-slot": "^1.1.0",
"ai": "^4.0.0",
"class-variance-authority": "^0.7.0",
"dotenv": "^16.3.1",
"llamaindex": "workspace:*",
"lucide-react": "^0.460.0",
"next": "15.1.7",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-markdown": "^9.0.1",
"react-syntax-highlighter": "^15.5.0",
"sonner": "^1.7.0",
"tailwind-merge": "^2.5.2"
},
"devDependencies": {
"@types/node": "^22.9.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@types/react-syntax-highlighter": "^15.5.11",
"autoprefixer": "^10.4.20",
"cross-env": "^7.0.3",
"postcss": "^8.4.49",
"tailwindcss": "^3.4.15",
"typescript": "^5.7.2"
}
}
@@ -1,6 +0,0 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};
Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

@@ -1,78 +0,0 @@
import type { Config } from "tailwindcss";
import { fontFamily } from "tailwindcss/defaultTheme";
const config: Config = {
darkMode: ["class"],
content: ["app/**/*.{ts,tsx}", "components/**/*.{ts,tsx}"],
theme: {
container: {
center: true,
padding: "2rem",
screens: {
"2xl": "1400px",
},
},
extend: {
colors: {
border: "hsl(var(--border))",
input: "hsl(var(--input))",
ring: "hsl(var(--ring))",
background: "hsl(var(--background))",
foreground: "hsl(var(--foreground))",
primary: {
DEFAULT: "hsl(var(--primary))",
foreground: "hsl(var(--primary-foreground))",
},
secondary: {
DEFAULT: "hsl(var(--secondary))",
foreground: "hsl(var(--secondary-foreground))",
},
destructive: {
DEFAULT: "hsl(var(--destructive) / <alpha-value>)",
foreground: "hsl(var(--destructive-foreground) / <alpha-value>)",
},
muted: {
DEFAULT: "hsl(var(--muted))",
foreground: "hsl(var(--muted-foreground))",
},
accent: {
DEFAULT: "hsl(var(--accent))",
foreground: "hsl(var(--accent-foreground))",
},
popover: {
DEFAULT: "hsl(var(--popover))",
foreground: "hsl(var(--popover-foreground))",
},
card: {
DEFAULT: "hsl(var(--card))",
foreground: "hsl(var(--card-foreground))",
},
},
borderRadius: {
xl: `calc(var(--radius) + 4px)`,
lg: `var(--radius)`,
md: `calc(var(--radius) - 2px)`,
sm: "calc(var(--radius) - 4px)",
},
fontFamily: {
sans: ["var(--font-sans)", ...fontFamily.sans],
},
keyframes: {
"accordion-down": {
from: { height: "0" },
to: { height: "var(--radix-accordion-content-height)" },
},
"accordion-up": {
from: { height: "var(--radix-accordion-content-height)" },
to: { height: "0" },
},
},
animation: {
"accordion-down": "accordion-down 0.2s ease-out",
"accordion-up": "accordion-up 0.2s ease-out",
},
},
},
plugins: [],
};
export default config;
@@ -1,27 +0,0 @@
"use tool";
import { getCurrentStreamableUI } from "@/context";
export async function getMyUserID() {
const ui = getCurrentStreamableUI()!;
ui.update("Getting user ID...");
await new Promise((resolve) => setTimeout(resolve, 2000));
return "12345";
}
export async function showUserInfo(userId: string) {
const ui = getCurrentStreamableUI()!;
ui.update("Getting user info...");
await new Promise((resolve) => setTimeout(resolve, 2000));
ui.update(
<div>
User ID: {userId}
<br />
Name: John Doe
</div>,
);
return `User ID: ${userId}\nName: John Doe\nEmail: alex@gmail.com\nPhone: 123-456-7890\nAddress: 123 Main St\nCity: San Francisco\nState: CA\nZip: 94105\nCountry: USA\n`;
}
export function getWeather(address: string) {
return `The weather in ${address} is sunny!`;
}
@@ -1,28 +0,0 @@
{
"compilerOptions": {
"target": "es5",
"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": {
"@/*": ["./*"]
},
"forceConsistentCasingInFileNames": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
+3 -3
View File
@@ -77,10 +77,10 @@
"@types/node": "^22.9.0",
"bunchee": "6.3.4",
"llamaindex": "workspace:*",
"next": "15.1.7",
"next": "15.2.0",
"rollup": "^4.28.1",
"tsx": "^4.19.0",
"typescript": "^5.7.2",
"tsx": "^4.19.3",
"typescript": "^5.7.3",
"vitest": "^2.1.5",
"webpack": "^5.97.1"
}
+3 -9
View File
@@ -11,15 +11,9 @@ describe("FunctionTool", () => {
FunctionTool.from(({ input }: { input: string }) => input, {
name: "test",
description: "test",
parameters: {
type: "object",
properties: {
input: {
type: "string",
},
},
required: ["input"],
},
parameters: z.object({
input: z.string(),
}),
});
const inputSchema = z
.object({
+2 -1
View File
@@ -29,6 +29,7 @@
"@types/lodash": "^4.17.7",
"@types/node": "^22.9.0",
"ajv": "^8.17.1",
"gpt-tokenizer": "^2.6.2",
"lodash": "^4.17.21",
"magic-bytes.js": "^1.10.0"
},
@@ -37,7 +38,7 @@
"@swc/core": "^1.9.2",
"concurrently": "^9.1.0",
"glob": "^11.0.0",
"typescript": "^5.7.2"
"typescript": "^5.7.3"
},
"engines": {
"node": ">=18.0.0"
+1 -1
View File
@@ -11,7 +11,7 @@
"@swc/cli": "^0.5.0",
"@swc/core": "^1.9.2",
"assemblyscript": "^0.27.31",
"typescript": "^5.7.2"
"typescript": "^5.7.3"
},
"engines": {
"node": ">=20.0.0"
+1801 -2010
View File
File diff suppressed because it is too large Load Diff
+4 -4
View File
@@ -9,8 +9,8 @@
"devDependencies": {
"@azure/cosmos": "^4.1.1",
"@faker-js/faker": "^9.2.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@types/react": "^19.0.10",
"@types/react-dom": "^19.0.4",
"msw": "^2.6.5",
"vitest": "^2.1.5"
},
@@ -22,8 +22,8 @@
"@llamaindex/readers": "workspace:*",
"@llamaindex/workflow": "workspace:*",
"llamaindex": "workspace:*",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"tree-sitter": "^0.22.1",
"tree-sitter-javascript": "^0.23.1",
"tree-sitter-typescript": "^0.23.2",