Skip to content

Commit 44b4d89

Browse files
authored
Update document link and fix import (#565)
1 parent 60f10c5 commit 44b4d89

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

llama-index-server/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ When enabled, the server provides a chat interface at the root path (`/`) with:
110110
### Custom UI Components
111111

112112
You can add custom UI components for your workflow by providing `component_dir` config and adding custom .jsx or .tsx files to the directory.
113-
See [Custom UI Components](docs/custom_ui_component.md) for more details.
113+
See [Custom UI Components](https://github.com/run-llama/create-llama/blob/main/llama-index-server/docs/custom_ui_component.md) for more details.
114114

115115
## Development Mode
116116

llama-index-server/llama_index/server/gen_ui/main.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import re
22
from typing import Any, Dict, List, Optional, Type
33

4+
from pydantic import BaseModel
5+
from rich.console import Console
6+
from rich.live import Live
7+
from rich.panel import Panel
8+
49
from llama_index.core.llms import LLM
510
from llama_index.core.prompts import PromptTemplate
611
from llama_index.core.workflow import (
@@ -12,10 +17,6 @@
1217
step,
1318
)
1419
from llama_index.server.gen_ui.parse_workflow_code import get_workflow_event_schemas
15-
from pydantic import BaseModel
16-
from rich.console import Console
17-
from rich.live import Live
18-
from rich.panel import Panel
1920

2021

2122
class PlanningEvent(Event):
@@ -80,11 +81,7 @@ class GenUIWorkflow(Workflow):
8081

8182
code_structure: str = """
8283
```jsx
83-
// Note: Only shadcn/ui and lucide-react and tailwind css are allowed.
84-
// shadcn import pattern: import { ComponentName } from "@/components/ui/<component_path>";
85-
// e.g: import { Card, CardHeader, CardTitle, CardContent } from "@/components/ui/card";
86-
// import { Button } from "@/components/ui/button";
87-
// import cn from "@/lib/utils"; // clsx is not supported
84+
// Note: Only React, shadcn/ui, lucide-react, LlamaIndex's markdown-ui and tailwind css (cn) are allowed.
8885
8986
// export the component
9087
export default function Component({ events }) {
@@ -103,6 +100,21 @@ class GenUIWorkflow(Workflow):
103100
```
104101
"""
105102

103+
supported_deps = """
104+
- React: import { useState } from "react";
105+
- shadcn/ui: import { ComponentName } from "@/components/ui/<component_path>";
106+
Supported shadcn components:
107+
accordion, alert, alert-dialog, aspect-ratio, avatar, badge,
108+
breadcrumb, button, calendar, card, carousel, chart, checkbox, collapsible, command,
109+
context-menu, dialog, drawer, dropdown-menu, form, hover-card, input, input-otp, label,
110+
menubar, navigation-menu, pagination, popover, progress, radio-group, resizable,
111+
scroll-area, select, separator, sheet, sidebar, skeleton, slider, sonner, switch, table,
112+
tabs, textarea, toggle, toggle-group, tooltip
113+
- lucide-react: import { IconName } from "lucide-react";
114+
- tailwind css: import { cn } from "@/lib/utils"; // Note: clsx is not supported
115+
- LlamaIndex's markdown-ui: import { Markdown } from "@llamaindex/chat-ui/widgets";
116+
"""
117+
106118
def __init__(self, llm: LLM, **kwargs: Any):
107119
super().__init__(**kwargs)
108120
self.llm = llm
@@ -239,7 +251,7 @@ async def write_ui_component(
239251
) -> RefineGeneratedCodeEvent:
240252
prompt_template = """
241253
# Your role
242-
You are a frontend developer who is developing a React component using shadcn/ui (@/components/ui/<component_name>) and lucide-react for the UI.
254+
You are a frontend developer who is developing a React component using shadcn/ui, lucide-react, LlamaIndex's chat-ui, and tailwind css (cn) for the UI.
243255
You are given a list of events and other context.
244256
Your task is to write a beautiful UI for the events that will be included in a chat UI.
245257
@@ -251,8 +263,11 @@ async def write_ui_component(
251263
{ui_description}
252264
```
253265
266+
# Supported dependencies:
267+
{supported_deps}
268+
254269
# Requirements:
255-
- Write beautiful UI components for the events using shadcn/ui and lucide-react.
270+
- Write beautiful UI components for the events using the supported dependencies
256271
- The component text/label should be specified for each event type.
257272
258273
# Instructions:
@@ -265,7 +280,7 @@ async def write_ui_component(
265280
You should display the jump, run and meow actions in different ways. don't try to render "height" for the "run" and "meow" action.
266281
267282
## UI notice
268-
- Use shadcn/ui and lucide-react and tailwind CSS for the UI.
283+
- Use the supported dependencies for the UI.
269284
- Be careful on state handling, make sure the update should be updated in the state and there is no duplicate state.
270285
- For a long content, consider to use markdown along with dropdown to show the full content.
271286
e.g:
@@ -287,6 +302,7 @@ async def write_ui_component(
287302
aggregation_function_context=aggregation_function_context,
288303
code_structure=self.code_structure,
289304
ui_description=ev.ui_description,
305+
supported_deps=self.supported_deps,
290306
)
291307
response = await self.llm.acomplete(prompt, formatted=True)
292308

@@ -317,6 +333,7 @@ async def refine_code(
317333
{code_structure}
318334
319335
# Requirements:
336+
- Only use supported dependencies: {supported_deps}
320337
- Refine the code if needed to ensure there are no potential bugs.
321338
- Be careful on code placement, make sure it doesn't call any undefined code.
322339
- Make sure the import statements are correct.
@@ -329,6 +346,7 @@ async def refine_code(
329346
generated_code=ev.generated_code,
330347
code_structure=self.code_structure,
331348
aggregation_function_context=ev.aggregation_function_context,
349+
supported_deps=self.supported_deps,
332350
)
333351

334352
response = await self.llm.acomplete(prompt, formatted=True)

0 commit comments

Comments
 (0)