1
1
import re
2
2
from typing import Any , Dict , List , Optional , Type
3
3
4
+ from pydantic import BaseModel
5
+ from rich .console import Console
6
+ from rich .live import Live
7
+ from rich .panel import Panel
8
+
4
9
from llama_index .core .llms import LLM
5
10
from llama_index .core .prompts import PromptTemplate
6
11
from llama_index .core .workflow import (
12
17
step ,
13
18
)
14
19
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
19
20
20
21
21
22
class PlanningEvent (Event ):
@@ -80,11 +81,7 @@ class GenUIWorkflow(Workflow):
80
81
81
82
code_structure : str = """
82
83
```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.
88
85
89
86
// export the component
90
87
export default function Component({ events }) {
@@ -103,6 +100,21 @@ class GenUIWorkflow(Workflow):
103
100
```
104
101
"""
105
102
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
+
106
118
def __init__ (self , llm : LLM , ** kwargs : Any ):
107
119
super ().__init__ (** kwargs )
108
120
self .llm = llm
@@ -239,7 +251,7 @@ async def write_ui_component(
239
251
) -> RefineGeneratedCodeEvent :
240
252
prompt_template = """
241
253
# 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.
243
255
You are given a list of events and other context.
244
256
Your task is to write a beautiful UI for the events that will be included in a chat UI.
245
257
@@ -251,8 +263,11 @@ async def write_ui_component(
251
263
{ui_description}
252
264
```
253
265
266
+ # Supported dependencies:
267
+ {supported_deps}
268
+
254
269
# 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
256
271
- The component text/label should be specified for each event type.
257
272
258
273
# Instructions:
@@ -265,7 +280,7 @@ async def write_ui_component(
265
280
You should display the jump, run and meow actions in different ways. don't try to render "height" for the "run" and "meow" action.
266
281
267
282
## UI notice
268
- - Use shadcn/ui and lucide-react and tailwind CSS for the UI.
283
+ - Use the supported dependencies for the UI.
269
284
- Be careful on state handling, make sure the update should be updated in the state and there is no duplicate state.
270
285
- For a long content, consider to use markdown along with dropdown to show the full content.
271
286
e.g:
@@ -287,6 +302,7 @@ async def write_ui_component(
287
302
aggregation_function_context = aggregation_function_context ,
288
303
code_structure = self .code_structure ,
289
304
ui_description = ev .ui_description ,
305
+ supported_deps = self .supported_deps ,
290
306
)
291
307
response = await self .llm .acomplete (prompt , formatted = True )
292
308
@@ -317,6 +333,7 @@ async def refine_code(
317
333
{code_structure}
318
334
319
335
# Requirements:
336
+ - Only use supported dependencies: {supported_deps}
320
337
- Refine the code if needed to ensure there are no potential bugs.
321
338
- Be careful on code placement, make sure it doesn't call any undefined code.
322
339
- Make sure the import statements are correct.
@@ -329,6 +346,7 @@ async def refine_code(
329
346
generated_code = ev .generated_code ,
330
347
code_structure = self .code_structure ,
331
348
aggregation_function_context = ev .aggregation_function_context ,
349
+ supported_deps = self .supported_deps ,
332
350
)
333
351
334
352
response = await self .llm .acomplete (prompt , formatted = True )
0 commit comments