Skip to content

Conversation

@leehuwuj
Copy link
Collaborator

@leehuwuj leehuwuj commented Apr 28, 2025

Summary by CodeRabbit

  • New Features

    • Introduced a new "Artifacts" use case for generating code and document artifacts using LLM-driven workflows.
    • Added interactive UI components to display artifact workflow progress and status updates.
    • Provided ready-to-use Python workflow templates for both code and document artifact generation.
    • Included a comprehensive README with setup instructions and usage guidance for artifact workflows.
  • Enhancements

    • Expanded use case selection and configuration options to support the new "Artifacts" workflow.
    • Updated dependency requirements for improved compatibility.
  • Documentation

    • Added detailed documentation for setting up and customizing artifact workflows.

@changeset-bot
Copy link

changeset-bot bot commented Apr 28, 2025

🦋 Changeset detected

Latest commit: 347ba8e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
create-llama Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link

coderabbitai bot commented Apr 28, 2025

Walkthrough

This update introduces a new "artifacts" use case to the LlamaIndex project template generator. It extends type definitions and user prompts to support the new use case, adds a Python workflow template for artifact generation (including code and document workflows), and provides a corresponding React UI component for workflow progress visualization. The update also includes a new README template with setup and usage instructions for the artifacts workflow, and adjusts file operations to copy all Python files for the workflow template. Additionally, dependencies are updated to require a newer version of "llama-index-server".

Changes

File(s) Change Summary
.changeset/chilly-foxes-remain.md Added a changeset metadata file documenting the "create-llama" patch and the new "artifacts" use case.
packages/create-llama/helpers/python.ts Modified file copy logic to include all Python files (*.py) from the workflow use case directory instead of just workflow.py.
packages/create-llama/helpers/types.ts Extended the TemplateUseCase type to include "artifacts".
packages/create-llama/questions/simple.ts Added "artifacts" to the AppType union, updated prompts and logic for the new use case, renamed and updated the model configuration, and added a new lookup entry for "artifacts".
packages/create-llama/templates/components/ui/workflows/artifacts/ui_event.jsx Added a new React component to display artifact workflow progress and status based on event states.
packages/create-llama/templates/components/workflows/python/artifacts/README-template.md Added a README template with setup, usage, and customization instructions for the artifacts workflow.
packages/create-llama/templates/components/workflows/python/artifacts/code_workflow.py Added a Python workflow for code artifact generation, including planning, generation, and answer synthesis steps with LLM integration.
packages/create-llama/templates/components/workflows/python/artifacts/document_workflow.py Added a Python workflow for document artifact generation, handling planning, document creation, and explanation steps.
packages/create-llama/templates/components/workflows/python/artifacts/workflow.py Added a workflow factory function to instantiate the code artifact workflow with a specific LLM configuration.
packages/create-llama/templates/types/llamaindexserver/fastapi/pyproject.toml Updated the llama-index-server dependency version constraint from >=0.1.14,<0.2.0 to >=0.1.15,<0.2.0.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI (React)
    participant FastAPI Server
    participant Workflow (Python)
    participant LLM

    User->>UI (React): Sends chat input
    UI (React)->>FastAPI Server: POST /api/chat with message
    FastAPI Server->>Workflow (Python): Passes chat request
    Workflow (Python)->>LLM: Planning step (analyze user request)
    LLM-->>Workflow (Python): Returns plan (e.g., code or document requirement)
    Workflow (Python)->>LLM: Generate artifact (code/doc) if needed
    LLM-->>Workflow (Python): Returns generated artifact content
    Workflow (Python)->>UI (React): Emits UI event (progress, requirement, etc.)
    Workflow (Python)->>LLM: Synthesize answer (explanation)
    LLM-->>Workflow (Python): Returns answer
    Workflow (Python)->>FastAPI Server: Streams answer and events
    FastAPI Server->>UI (React): Streams response and events
    UI (React)->>User: Displays progress, artifact, and answer
Loading

Possibly related PRs

Suggested reviewers

  • marcusschiesser

Poem

In the land of code, a new path appears,
"Artifacts" join the warren—let's give three cheers!
Python workflows now craft docs and code,
UI cards show progress as the stories unfold.
With a hop and a skip, dependencies align,
🐇 This rabbit’s quite proud of the new design!


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fa5ec73 and 347ba8e.

📒 Files selected for processing (2)
  • packages/create-llama/templates/components/workflows/python/artifacts/code_workflow.py (1 hunks)
  • packages/create-llama/templates/components/workflows/python/artifacts/document_workflow.py (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/create-llama/templates/components/workflows/python/artifacts/code_workflow.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/create-llama/templates/components/workflows/python/artifacts/document_workflow.py
⏰ Context from checks skipped due to timeout of 90000ms (27)
  • GitHub Check: typescript (22, 3.11, ubuntu-22.04, nextjs, --llamacloud)
  • GitHub Check: typescript (22, 3.11, ubuntu-22.04, nextjs, --example-file)
  • GitHub Check: typescript (22, 3.11, ubuntu-22.04, nextjs, --no-files)
  • GitHub Check: typescript (22, 3.11, windows-latest, nextjs, --llamacloud)
  • GitHub Check: typescript (22, 3.11, windows-latest, nextjs, --example-file)
  • GitHub Check: typescript (22, 3.11, windows-latest, nextjs, --no-files)
  • GitHub Check: typescript (22, 3.11, macos-latest, nextjs, --llamacloud)
  • GitHub Check: typescript (22, 3.11, macos-latest, nextjs, --example-file)
  • GitHub Check: typescript (22, 3.11, macos-latest, nextjs, --no-files)
  • GitHub Check: typescript (20, 3.11, ubuntu-22.04, nextjs, --llamacloud)
  • GitHub Check: python (20, 3.11, ubuntu-22.04, fastapi, --llamacloud)
  • GitHub Check: typescript (20, 3.11, ubuntu-22.04, nextjs, --example-file)
  • GitHub Check: python (20, 3.11, ubuntu-22.04, fastapi, --example-file)
  • GitHub Check: typescript (20, 3.11, ubuntu-22.04, nextjs, --no-files)
  • GitHub Check: python (20, 3.11, ubuntu-22.04, fastapi, --no-files)
  • GitHub Check: typescript (20, 3.11, windows-latest, nextjs, --llamacloud)
  • GitHub Check: python (20, 3.11, windows-latest, fastapi, --llamacloud)
  • GitHub Check: typescript (20, 3.11, windows-latest, nextjs, --example-file)
  • GitHub Check: python (20, 3.11, windows-latest, fastapi, --example-file)
  • GitHub Check: typescript (20, 3.11, windows-latest, nextjs, --no-files)
  • GitHub Check: python (20, 3.11, windows-latest, fastapi, --no-files)
  • GitHub Check: typescript (20, 3.11, macos-latest, nextjs, --llamacloud)
  • GitHub Check: python (20, 3.11, macos-latest, fastapi, --llamacloud)
  • GitHub Check: typescript (20, 3.11, macos-latest, nextjs, --example-file)
  • GitHub Check: python (20, 3.11, macos-latest, fastapi, --example-file)
  • GitHub Check: typescript (20, 3.11, macos-latest, nextjs, --no-files)
  • GitHub Check: python (20, 3.11, macos-latest, fastapi, --no-files)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@leehuwuj leehuwuj force-pushed the lee/cl-add-artifact branch from 8e5847f to bff0f77 Compare April 28, 2025 05:12
- Introduced `CodeArtifactWorkflow` and `DocumentArtifactWorkflow` classes to handle code and document artifacts respectively.
- Updated README to include instructions for modifying the factory method to select the appropriate workflow.
- Enhanced clarity in class documentation and improved naming conventions for better understanding.
@leehuwuj leehuwuj marked this pull request as ready for review April 28, 2025 09:38
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

♻️ Duplicate comments (4)
packages/create-llama/templates/components/workflows/python/artifacts/workflow.py (1)

3-3: Improve the import comment clarity.

The comment on line 3 is meant to provide guidance on how to import the document workflow, but it's missing the "from" keyword which makes it unclear that it's an import instruction.

-# from app.document_workflow import DocumentArtifactWorkflow to generate documents
+# import DocumentArtifactWorkflow from app.document_workflow to generate documents
packages/create-llama/templates/components/workflows/python/artifacts/README-template.md (1)

39-41: Clarify workflow selection instructions.

The sentence explaining workflow selection is missing a comma and could be made clearer.

-- [Document Workflow](./document_workflow.py): Generate and update a document like OpenAI's canvas.
+- [Document Workflow](./document_workflow.py): Generate and update a document like OpenAI's canvas.

-Modify the factory method in `workflow.py` to decide which artifact workflow to use. Without any changes the Code Workflow is used.
+Modify the factory method in `workflow.py` to decide which artifact workflow to use. Without any changes, the Code Workflow is used.
🧰 Tools
🪛 LanguageTool

[typographical] ~41-~41: It appears that a comma is missing.
Context: ...h artifact workflow to use. Without any changes the Code Workflow is used. You can sta...

(DURING_THAT_TIME_COMMA)

packages/create-llama/templates/components/workflows/python/artifacts/code_workflow.py (2)

187-194: Same greedy-JSON issue as in the document workflow

Reuse the non-greedy pattern suggested earlier to avoid capturing unrelated back-tick blocks and crashing at Requirement.model_validate_json.


289-292: Confirm formatted=True kwarg

Same concern as with the document workflow – please verify the driver signature.

🧹 Nitpick comments (8)
packages/create-llama/templates/components/workflows/python/artifacts/README-template.md (4)

26-28: Add a language specifier to the code block.

For better syntax highlighting and documentation consistency, specify the shell language in the code fence.

-```
+```shell
 uv run fastapi run

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 markdownlint-cli2 (0.17.2)</summary>

26-26: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

</details>

</details>

---

`43-43`: **Fix article usage with "request".**

Use "a" instead of "an" before "request" since "request" begins with a consonant sound.

```diff
-You can start by sending an request on the [chat UI](http://localhost:8000) or you can test the `/api/chat` endpoint with the following curl request:
+You can start by sending a request on the [chat UI](http://localhost:8000) or you can test the `/api/chat` endpoint with the following curl request:
🧰 Tools
🪛 LanguageTool

[misspelling] ~43-~43: Use “a” instead of ‘an’ if the following word doesn’t start with a vowel sound, e.g. ‘a sentence’, ‘a university’.
Context: ...flow is used. You can start by sending an request on the [chat UI](http://localho...

(EN_A_VS_AN)


45-49: Add a language specifier to the code block.

For better syntax highlighting and documentation consistency, specify the shell language in the code fence.

-```
+```shell
 curl --location 'localhost:8000/api/chat' \
 --header 'Content-Type: application/json' \
 --data '{ "messages": [{ "role": "user", "content": "Create a report comparing the finances of Apple and Tesla" }] }'

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 markdownlint-cli2 (0.17.2)</summary>

45-45: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

</details>

</details>

---

`57-59`: **Add a language specifier to the code block.**

For better syntax highlighting and documentation consistency, specify the shell language in the code fence.

```diff
-```
+```shell
 uv run generate_ui

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 markdownlint-cli2 (0.17.2)</summary>

57-57: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

</details>

</details>

</blockquote></details>
<details>
<summary>packages/create-llama/templates/components/ui/workflows/artifacts/ui_event.jsx (1)</summary><blockquote>

`128-137`: **Improve handling of undefined or null events.**

The `aggregateEvents` function handles empty arrays, but the component could be more robust by adding a null check in the default export function.

```diff
 export default function Component({ events }) {
+  if (!events) return null;
+
   const aggregateEvents = () => {
     if (!events || events.length === 0) return null;
     return events[events.length - 1];
   };

   const event = aggregateEvents();

   return <ArtifactWorkflowCard event={event} />;
 }
packages/create-llama/templates/components/workflows/python/artifacts/document_workflow.py (1)

266-285: Minor: ensure doc_type is lower-case before persisting

If the LLM returns “Markdown”, the captured group retains the original case; DocumentArtifactData.type is a Literal["markdown","html"] so upper-case would break validation downstream.

-doc_type = doc_match.group(1)
+doc_type = doc_match.group(1).lower()
packages/create-llama/templates/components/workflows/python/artifacts/code_workflow.py (2)

294-300: Make code-block regex non-greedy & verify language

-language_pattern = r"```(\w+)([\s\S]*)```"
+language_pattern = r"```(\w+)\s*([\s\S]*?)\s*```"

After extraction, ensure lang.lower() ∈ {“typescript”, “python”}.
If not, emit a graceful error so that users discover the mismatch early.


310-320: Propagate the captured language when LLM omits it

When event.requirement.language is None, you already fall back to "".
However, if the LLM does return a language tag in the code block (code_match.group(1)), you can use that as a better default:

-    language=event.requirement.language or "",
+    language=(event.requirement.language or code_match.group(1).lower()),

This prevents empty strings in the stored artifact and keeps UI tooling consistent.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b16cfd8 and 04151b0.

📒 Files selected for processing (10)
  • .changeset/chilly-foxes-remain.md (1 hunks)
  • packages/create-llama/helpers/python.ts (1 hunks)
  • packages/create-llama/helpers/types.ts (1 hunks)
  • packages/create-llama/questions/simple.ts (4 hunks)
  • packages/create-llama/templates/components/ui/workflows/artifacts/ui_event.jsx (1 hunks)
  • packages/create-llama/templates/components/workflows/python/artifacts/README-template.md (1 hunks)
  • packages/create-llama/templates/components/workflows/python/artifacts/code_workflow.py (1 hunks)
  • packages/create-llama/templates/components/workflows/python/artifacts/document_workflow.py (1 hunks)
  • packages/create-llama/templates/components/workflows/python/artifacts/workflow.py (1 hunks)
  • packages/create-llama/templates/types/llamaindexserver/fastapi/pyproject.toml (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
packages/create-llama/templates/components/workflows/python/artifacts/workflow.py (2)
python/llama-index-server/llama_index/server/api/models.py (1)
  • ChatRequest (32-41)
python/llama-index-server/tests/api/test_event_stream.py (1)
  • chat_request (23-26)
packages/create-llama/questions/simple.ts (1)
packages/create-llama/helpers/types.ts (1)
  • ModelConfig (14-21)
packages/create-llama/templates/components/workflows/python/artifacts/document_workflow.py (5)
python/llama-index-server/llama_index/server/api/models.py (2)
  • ChatRequest (32-41)
  • UIEvent (147-155)
python/llama-index-server/llama_index/server/api/utils/chat_request.py (1)
  • get_last_artifact (21-23)
packages/create-llama/templates/components/workflows/python/artifacts/code_workflow.py (9)
  • PlanEvent (37-39)
  • GenerateArtifactEvent (42-43)
  • SynthesizeAnswerEvent (46-47)
  • UIEventData (50-52)
  • ArtifactWorkflow (55-354)
  • prepare_chat_history (80-102)
  • planning (105-218)
  • generate_artifact (221-322)
  • synthesize_answer (325-354)
python/llama-index-server/tests/api/test_event_stream.py (1)
  • chat_request (23-26)
packages/create-llama/templates/components/ui/workflows/artifacts/ui_event.jsx (2)
  • event (44-44)
  • event (134-134)
🪛 LanguageTool
packages/create-llama/templates/components/workflows/python/artifacts/README-template.md

[typographical] ~41-~41: It appears that a comma is missing.
Context: ...h artifact workflow to use. Without any changes the Code Workflow is used. You can sta...

(DURING_THAT_TIME_COMMA)


[misspelling] ~43-~43: Use “a” instead of ‘an’ if the following word doesn’t start with a vowel sound, e.g. ‘a sentence’, ‘a university’.
Context: ...flow is used. You can start by sending an request on the [chat UI](http://localho...

(EN_A_VS_AN)

🪛 markdownlint-cli2 (0.17.2)
packages/create-llama/templates/components/workflows/python/artifacts/README-template.md

26-26: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


45-45: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


57-57: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

🔇 Additional comments (13)
packages/create-llama/templates/types/llamaindexserver/fastapi/pyproject.toml (1)

15-15: Version bump for llama-index-server dependency to support artifacts use case.

The version requirement for llama-index-server has been updated from ">=0.1.14,<0.2.0" to ">=0.1.15,<0.2.0" to support the new artifacts use case functionality.

.changeset/chilly-foxes-remain.md (1)

1-6: LGTM! Changeset documented appropriately.

The changeset file correctly documents the patch for adding the artifacts use case (Python implementation) to create-llama.

packages/create-llama/helpers/types.ts (1)

60-61: Good addition to the TemplateUseCase type.

Adding "artifacts" to the TemplateUseCase union type correctly integrates the new use case into the type system, ensuring type safety throughout the application.

packages/create-llama/helpers/python.ts (1)

565-565:

✅ Verification successful

Modified file copy pattern to handle multiple workflow files.

Good change! This modifies the copy pattern from a specific "workflow.py" file to all Python files ("*.py") in the use case directory, which is necessary to support the multiple workflow files in the new artifacts use case.


🏁 Script executed:

#!/bin/bash
# Verify existence of multiple Python files in the artifacts directory
fd -t f -e py . packages/create-llama/templates/components/workflows/python/artifacts --exec ls -la {} \;

Length of output: 518


Copy pattern update correctly supports multiple workflow files

Verified that the artifacts directory contains multiple Python files (workflow.py, code_workflow.py, document_workflow.py), so changing the copy pattern to "*.py" is necessary and correct.
No further action required.

packages/create-llama/templates/components/workflows/python/artifacts/workflow.py (1)

9-15: LGTM: Clean and clear workflow factory implementation.

The create_workflow function correctly implements a factory pattern that returns a configured CodeArtifactWorkflow instance with appropriate parameters. This structure makes it easy to switch between different workflow implementations.

packages/create-llama/templates/components/ui/workflows/artifacts/ui_event.jsx (3)

10-27: LGTM: Well-structured workflow stage configuration.

The STAGE_META object is well-organized with clear stage-specific styling and configuration, making it easy to understand and maintain.


29-48: LGTM: Clean state management for workflow card visibility.

The component effectively manages visibility and animation states based on the event state, with proper effect cleanup.


49-126: LGTM: Responsive and well-styled artifact workflow card UI.

The card UI is well-structured with appropriate conditional rendering based on the workflow stage, clear visual indicators of progress, and good use of styling for a polished user experience.

packages/create-llama/questions/simple.ts (4)

9-13: LGTM: Clean type extension for new artifacts use case.

The AppType union has been properly extended to include the new "artifacts" use case.


49-54: LGTM: Clear description for the artifacts use case option.

The new choice added to the use case selection prompt has a descriptive title and explanation that clearly conveys the purpose of the artifacts use case.


124-128: LGTM: Model constant rename and update.

The model constant has been appropriately renamed from MODEL_GPT4o to MODEL_GPT41 and updated to use "gpt-4.1" instead of "gpt-4o", maintaining consistency with the model used in the workflow implementation.


156-161: LGTM: Well-configured artifacts use case.

The new entry in the lookup table for the "artifacts" use case is properly configured with the appropriate template, empty data sources and tools arrays, and the GPT-4.1 model configuration.

packages/create-llama/templates/components/workflows/python/artifacts/document_workflow.py (1)

164-167: Double-check formatted=True – not all LLM drivers support it

self.llm.acomplete(prompt=prompt, formatted=True) assumes the driver accepts a formatted kwarg. In llama-index (≥0.10) it’s usually format=True (no ed) or the prompt must be pre-formatted manually. A mismatch will raise TypeError: got an unexpected keyword. Please verify against the exact version in requirements.txt.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

♻️ Duplicate comments (1)
packages/create-llama/templates/components/workflows/python/artifacts/code_workflow.py (1)

30-33: Restrict language to allowed literals for static safety

We can catch typos (“pyhton”) and invalid languages at parse-time by encoding the contract in the model:

-    language: Optional[str] = None
+    language: Optional[Literal["typescript", "python"]] = None

Pydantic will still accept None, but any other value outside the two allowed options will raise immediately, preventing runtime surprises.

🧹 Nitpick comments (2)
packages/create-llama/templates/components/workflows/python/artifacts/code_workflow.py (2)

313-317: Prefer detected language over requested one when emitting artifact

The LLM might return a fenced block tagged with a different language (or none). Deriving the language from the regex keeps the UI in sync with what was actually generated:

-                        language=event.requirement.language or "",
+                        language=(code_match.group(1) if code_match else event.requirement.language) or "",

This also removes silent fall-back to an empty string, which can break downstream renderers.


120-144: Consider extracting the verbose prompt to a constant for reuse & readability

The 120-line inline prompt makes the method hard to scan and is duplicated almost verbatim in document_workflow.py. Moving it to a module-level constant (or a .prompt file) reduces noise and promotes reuse:

PLANNING_PROMPT = PromptTemplate(\"\"\" ... long text ... \"\"\")

...

prompt = PLANNING_PROMPT.format(
    context="..." if event.context is None else f"...",
    user_msg=event.user_msg,
)

This keeps business logic focused on control flow, not string literals.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 04151b0 and ff9ee2a.

📒 Files selected for processing (3)
  • packages/create-llama/questions/simple.ts (5 hunks)
  • packages/create-llama/templates/components/workflows/python/artifacts/code_workflow.py (1 hunks)
  • packages/create-llama/templates/components/workflows/python/artifacts/document_workflow.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/create-llama/questions/simple.ts
  • packages/create-llama/templates/components/workflows/python/artifacts/document_workflow.py
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/create-llama/templates/components/workflows/python/artifacts/code_workflow.py (3)
python/llama-index-server/llama_index/server/api/models.py (2)
  • ChatRequest (32-41)
  • UIEvent (147-155)
python/llama-index-server/llama_index/server/api/utils/chat_request.py (1)
  • get_last_artifact (21-23)
packages/create-llama/templates/components/workflows/python/artifacts/document_workflow.py (8)
  • PlanEvent (35-37)
  • GenerateArtifactEvent (40-41)
  • SynthesizeAnswerEvent (44-46)
  • UIEventData (49-51)
  • prepare_chat_history (77-99)
  • planning (102-195)
  • generate_artifact (198-292)
  • synthesize_answer (295-325)
⏰ Context from checks skipped due to timeout of 90000ms (29)
  • GitHub Check: typescript (22, 3.11, ubuntu-22.04, nextjs, --llamacloud)
  • GitHub Check: typescript (22, 3.11, ubuntu-22.04, nextjs, --example-file)
  • GitHub Check: typescript (22, 3.11, ubuntu-22.04, nextjs, --no-files)
  • GitHub Check: typescript (22, 3.11, windows-latest, nextjs, --llamacloud)
  • GitHub Check: typescript (22, 3.11, windows-latest, nextjs, --example-file)
  • GitHub Check: typescript (22, 3.11, windows-latest, nextjs, --no-files)
  • GitHub Check: typescript (22, 3.11, macos-latest, nextjs, --llamacloud)
  • GitHub Check: typescript (22, 3.11, macos-latest, nextjs, --example-file)
  • GitHub Check: typescript (22, 3.11, macos-latest, nextjs, --no-files)
  • GitHub Check: typescript (20, 3.11, ubuntu-22.04, nextjs, --llamacloud)
  • GitHub Check: python (20, 3.11, ubuntu-22.04, fastapi, --llamacloud)
  • GitHub Check: typescript (20, 3.11, ubuntu-22.04, nextjs, --example-file)
  • GitHub Check: python (20, 3.11, ubuntu-22.04, fastapi, --example-file)
  • GitHub Check: python (20, 3.11, ubuntu-22.04, fastapi, --no-files)
  • GitHub Check: typescript (20, 3.11, ubuntu-22.04, nextjs, --no-files)
  • GitHub Check: python (20, 3.11, windows-latest, fastapi, --llamacloud)
  • GitHub Check: typescript (20, 3.11, windows-latest, nextjs, --llamacloud)
  • GitHub Check: python (20, 3.11, windows-latest, fastapi, --example-file)
  • GitHub Check: typescript (20, 3.11, windows-latest, nextjs, --example-file)
  • GitHub Check: python (20, 3.11, windows-latest, fastapi, --no-files)
  • GitHub Check: typescript (20, 3.11, windows-latest, nextjs, --no-files)
  • GitHub Check: typescript (20, 3.11, macos-latest, nextjs, --llamacloud)
  • GitHub Check: python (20, 3.11, macos-latest, fastapi, --llamacloud)
  • GitHub Check: typescript (20, 3.11, macos-latest, nextjs, --example-file)
  • GitHub Check: Unit Tests (windows-latest, 3.9)
  • GitHub Check: python (20, 3.11, macos-latest, fastapi, --example-file)
  • GitHub Check: typescript (20, 3.11, macos-latest, nextjs, --no-files)
  • GitHub Check: python (20, 3.11, macos-latest, fastapi, --no-files)
  • GitHub Check: lint

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (4)
packages/create-llama/templates/components/workflows/typescript/artifacts/code-workflow.ts (2)

33-34: Avoid banned {} type – replace with void or Record<string, never>

Biome correctly reports that {} is too permissive.
void is most appropriate here because no payload is ever consumed downstream.

-const synthesizeAnswerEvent = workflowEvent<{}>();
+const synthesizeAnswerEvent = workflowEvent<void>();
🧰 Tools
🪛 Biome (1.9.4)

[error] 33-33: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)


342-366: Remove side-effecting test harness from production module

Shipping a self-executing run() causes:

• Extraneous console output in the browser/server.
• An additional LLM call every time the file is imported.
• Difficult-to-stub side effects in unit tests.

Move the snippet to a dedicated *.spec.ts or guard with if (require.main === module).

-// Test the workflow
-...
-run();
+// Uncomment the lines below when debugging locally
+// if (require.main === module) {
+//   run();
+// }
packages/create-llama/templates/components/workflows/typescript/artifacts/doc-workflow.ts (2)

336-361: Accidental execution on import – move the demo runner

As with code-workflow.ts, executing run() upon import introduces side effects. Wrap it or extract to tests.

-// Uncomment to run
-run();
+// Uncomment to run locally
+// if (require.main === module) {
+//   run();
+// }

63-63: Nit: use void instead of an empty tuple type

For parity with the earlier comment, prefer:

-const synthesizeAnswerEvent = workflowEvent<{
+const synthesizeAnswerEvent = workflowEvent<{
     requirement: DocumentRequirement;
     generatedArtifact: string;
-}>();
+}>();

Alternatively, if you never pass a payload, declare workflowEvent<void>().
(Here a payload is passed later, so keep the object but avoid {} elsewhere.)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ff9ee2a and f9d3723.

📒 Files selected for processing (3)
  • packages/create-llama/templates/components/workflows/typescript/artifacts/code-workflow.ts (1 hunks)
  • packages/create-llama/templates/components/workflows/typescript/artifacts/doc-workflow.ts (1 hunks)
  • packages/create-llama/templates/components/workflows/typescript/artifacts/workflow.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/create-llama/templates/components/workflows/typescript/artifacts/workflow.ts
🧰 Additional context used
🪛 Biome (1.9.4)
packages/create-llama/templates/components/workflows/typescript/artifacts/code-workflow.ts

[error] 33-33: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)

⏰ Context from checks skipped due to timeout of 90000ms (27)
  • GitHub Check: typescript (22, 3.11, ubuntu-22.04, nextjs, --llamacloud)
  • GitHub Check: typescript (22, 3.11, ubuntu-22.04, nextjs, --example-file)
  • GitHub Check: typescript (22, 3.11, ubuntu-22.04, nextjs, --no-files)
  • GitHub Check: typescript (22, 3.11, windows-latest, nextjs, --llamacloud)
  • GitHub Check: typescript (22, 3.11, windows-latest, nextjs, --example-file)
  • GitHub Check: typescript (22, 3.11, windows-latest, nextjs, --no-files)
  • GitHub Check: typescript (22, 3.11, macos-latest, nextjs, --llamacloud)
  • GitHub Check: typescript (22, 3.11, macos-latest, nextjs, --example-file)
  • GitHub Check: typescript (22, 3.11, macos-latest, nextjs, --no-files)
  • GitHub Check: typescript (20, 3.11, ubuntu-22.04, nextjs, --llamacloud)
  • GitHub Check: python (20, 3.11, ubuntu-22.04, fastapi, --llamacloud)
  • GitHub Check: typescript (20, 3.11, ubuntu-22.04, nextjs, --example-file)
  • GitHub Check: python (20, 3.11, ubuntu-22.04, fastapi, --example-file)
  • GitHub Check: typescript (20, 3.11, ubuntu-22.04, nextjs, --no-files)
  • GitHub Check: python (20, 3.11, ubuntu-22.04, fastapi, --no-files)
  • GitHub Check: python (20, 3.11, windows-latest, fastapi, --llamacloud)
  • GitHub Check: typescript (20, 3.11, windows-latest, nextjs, --llamacloud)
  • GitHub Check: typescript (20, 3.11, windows-latest, nextjs, --example-file)
  • GitHub Check: typescript (20, 3.11, windows-latest, nextjs, --no-files)
  • GitHub Check: python (20, 3.11, windows-latest, fastapi, --example-file)
  • GitHub Check: typescript (20, 3.11, macos-latest, nextjs, --llamacloud)
  • GitHub Check: python (20, 3.11, windows-latest, fastapi, --no-files)
  • GitHub Check: typescript (20, 3.11, macos-latest, nextjs, --example-file)
  • GitHub Check: python (20, 3.11, macos-latest, fastapi, --llamacloud)
  • GitHub Check: typescript (20, 3.11, macos-latest, nextjs, --no-files)
  • GitHub Check: python (20, 3.11, macos-latest, fastapi, --example-file)
  • GitHub Check: python (20, 3.11, macos-latest, fastapi, --no-files)
🔇 Additional comments (1)
packages/create-llama/templates/components/workflows/typescript/artifacts/code-workflow.ts (1)

272-279: Regex drops language & may capture trailing backticks

  1. (\w+) misses “typescript” if the model outputs ```ts.
  2. ([\s\S]*) is greedy – it will include the closing backticks in some cases because the first triple-backtick may appear inside a string literal.

Consider:

const codeMatch = response.text.match(/```(\w+)\s*([\s\S]*?)\s*```/);

and save the captured language:

const [, detectedLang, codeRaw] = codeMatch;
const code = codeRaw.trim();
const lang = detectedLang ?? planData.requirement.language ?? "";
...
language: lang,

@leehuwuj leehuwuj changed the title feat: add create-llama artifacts template feat: add create-llama artifacts template (python) Apr 29, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/create-llama/templates/components/workflows/python/artifacts/README-template.md (2)

26-28: Add language identifiers to fenced code blocks and fix the API URL in the curl example

Several fenced code blocks lack a language specifier, which helps with syntax highlighting and readability. Also, the curl command is missing the http:// protocol, causing it to be interpreted as a file path instead of an HTTP request.

Apply this diff to address both issues:

@@ lines 26-28
- ```
+ ```bash
  uv run fastapi run
- ```
+ ```

@@ lines 45-49
- ```
+ ```bash
  curl --location 'localhost:8000/api/chat' \
+ curl --location 'http://localhost:8000/api/chat' \
   --header 'Content-Type: application/json' \
   --data '{ "messages": [{ "role": "user", "content": "Create a report comparing the finances of Apple and Tesla" }] }'
- ```
+ ```

@@ lines 57-59
- ```
+ ```bash
  uv run generate_ui
- ```
+ ```

Also applies to: 45-49, 57-59

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

26-26: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


41-43: Correct punctuation and article usage

There are a couple of minor grammar issues that impact clarity:

@@ line 41
- Without any changes the Code Workflow is used.
+ Without any changes, the Code Workflow is used.

@@ line 43
- You can start by sending an request on the [chat UI]
+ You can start by sending a request on the [chat UI]
🧰 Tools
🪛 LanguageTool

[uncategorized] ~41-~41: A punctuation mark might be missing here.
Context: ...s canvas. Modify the factory method in workflow.py to decide...

(AI_EN_LECTOR_MISSING_PUNCTUATION)


[typographical] ~41-~41: It appears that a comma is missing.
Context: ...h artifact workflow to use. Without any changes the Code Workflow is used. You can sta...

(DURING_THAT_TIME_COMMA)


[misspelling] ~43-~43: Use “a” instead of ‘an’ if the following word doesn’t start with a vowel sound, e.g. ‘a sentence’, ‘a university’.
Context: ...flow is used. You can start by sending an request on the [chat UI](http://localho...

(EN_A_VS_AN)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f9d3723 and fa5ec73.

📒 Files selected for processing (1)
  • packages/create-llama/templates/components/workflows/python/artifacts/README-template.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
packages/create-llama/templates/components/workflows/python/artifacts/README-template.md

[uncategorized] ~41-~41: A punctuation mark might be missing here.
Context: ...s canvas. Modify the factory method in workflow.py to decide...

(AI_EN_LECTOR_MISSING_PUNCTUATION)


[typographical] ~41-~41: It appears that a comma is missing.
Context: ...h artifact workflow to use. Without any changes the Code Workflow is used. You can sta...

(DURING_THAT_TIME_COMMA)


[misspelling] ~43-~43: Use “a” instead of ‘an’ if the following word doesn’t start with a vowel sound, e.g. ‘a sentence’, ‘a university’.
Context: ...flow is used. You can start by sending an request on the [chat UI](http://localho...

(EN_A_VS_AN)

🪛 markdownlint-cli2 (0.17.2)
packages/create-llama/templates/components/workflows/python/artifacts/README-template.md

26-26: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


45-45: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


57-57: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

⏰ Context from checks skipped due to timeout of 90000ms (27)
  • GitHub Check: typescript (22, 3.11, ubuntu-22.04, nextjs, --llamacloud)
  • GitHub Check: typescript (22, 3.11, ubuntu-22.04, nextjs, --example-file)
  • GitHub Check: typescript (22, 3.11, ubuntu-22.04, nextjs, --no-files)
  • GitHub Check: typescript (22, 3.11, windows-latest, nextjs, --llamacloud)
  • GitHub Check: typescript (22, 3.11, windows-latest, nextjs, --example-file)
  • GitHub Check: typescript (22, 3.11, windows-latest, nextjs, --no-files)
  • GitHub Check: typescript (22, 3.11, macos-latest, nextjs, --llamacloud)
  • GitHub Check: typescript (22, 3.11, macos-latest, nextjs, --example-file)
  • GitHub Check: typescript (22, 3.11, macos-latest, nextjs, --no-files)
  • GitHub Check: typescript (20, 3.11, ubuntu-22.04, nextjs, --llamacloud)
  • GitHub Check: typescript (20, 3.11, ubuntu-22.04, nextjs, --example-file)
  • GitHub Check: typescript (20, 3.11, ubuntu-22.04, nextjs, --no-files)
  • GitHub Check: typescript (20, 3.11, windows-latest, nextjs, --llamacloud)
  • GitHub Check: typescript (20, 3.11, windows-latest, nextjs, --example-file)
  • GitHub Check: typescript (20, 3.11, windows-latest, nextjs, --no-files)
  • GitHub Check: python (20, 3.11, ubuntu-22.04, fastapi, --llamacloud)
  • GitHub Check: python (20, 3.11, ubuntu-22.04, fastapi, --example-file)
  • GitHub Check: typescript (20, 3.11, macos-latest, nextjs, --llamacloud)
  • GitHub Check: python (20, 3.11, ubuntu-22.04, fastapi, --no-files)
  • GitHub Check: typescript (20, 3.11, macos-latest, nextjs, --example-file)
  • GitHub Check: python (20, 3.11, windows-latest, fastapi, --llamacloud)
  • GitHub Check: python (20, 3.11, windows-latest, fastapi, --example-file)
  • GitHub Check: python (20, 3.11, windows-latest, fastapi, --no-files)
  • GitHub Check: typescript (20, 3.11, macos-latest, nextjs, --no-files)
  • GitHub Check: python (20, 3.11, macos-latest, fastapi, --llamacloud)
  • GitHub Check: python (20, 3.11, macos-latest, fastapi, --example-file)
  • GitHub Check: python (20, 3.11, macos-latest, fastapi, --no-files)

@marcusschiesser marcusschiesser merged commit 241d82a into main Apr 29, 2025
33 checks passed
@marcusschiesser marcusschiesser deleted the lee/cl-add-artifact branch April 29, 2025 07:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants