Skip to content

Commit 3130cdf

Browse files
authored
Add support for artifact in llama-index-server (#580)
* support artifact * migrate poetry to uv * fix ci * update ci * Refactor artifact generation tools by introducing separate CodeGenerator and DocumentGenerator classes. Update app_writer to utilize FunctionAgent for code and document generation workflows. Remove deprecated ArtifactGenerator class. Enhance artifact transformation logic in callbacks. Improve system prompts for clarity and instruction adherence. * enhance code * remove previous content from tool input * fix test * bump chat ui * revert changes * remove dead code * Add artifact workflows for code and document generation - Introduced `code_workflow.py` for generating and updating code artifacts based on user requests. - Introduced `document_workflow.py` for generating and updating document artifacts (Markdown/HTML). - Created `main.py` to set up FastAPI server with artifact workflows. - Added a README for setup instructions and usage. - Implemented UI components for displaying artifact status and progress. - Updated chat router to remove unused event callbacks. * remove app_writer workflow * Refactor artifact workflow classes and UI event handling - Renamed `ArtifactUIEvents` to `UIEventData` for clarity. - Introduced `last_artifact` attribute in `ArtifactWorkflow` to streamline artifact retrieval. - Updated chat history handling to utilize the new `last_artifact` attribute. - Modified event streaming to use `UIEventData` for consistent event structure. - Added a new UI component for displaying artifact workflow status and progress. * Use uv to release package * Refactor artifact workflows and UI components - Updated `code_workflow.py` and `document_workflow.py` to improve chat history handling and user message storage. - Enhanced `ArtifactWorkflow` to utilize optional fields in the `Requirement` model. - Revised prompt instructions for clarity and conciseness in generating requirements. - Modified UI event components to reflect changes in workflow stages and improve user feedback. - Improved error handling for JSON parsing in artifact annotations. * move code * Merge remote-tracking branch 'origin/main' into lee/add-artifact * sort artifact * fix mypy * fix adding custom route does not work * fix mypy * revert create-llama change * disable e2e test for python package change * fix missing set memory * remove include last artifact in the code * Add ArtifactEvent model and update workflows to use it
1 parent 7711216 commit 3130cdf

File tree

19 files changed

+6333
-6337
lines changed

19 files changed

+6333
-6337
lines changed

.github/workflows/e2e.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ on:
44
branches: [main]
55
paths-ignore:
66
- "python/llama-index-server/**"
7+
- ".github/workflows/*llama_index_server.yml"
78
pull_request:
89
branches: [main]
910
paths-ignore:
1011
- "python/llama-index-server/**"
12+
- ".github/workflows/*llama_index_server.yml"
1113

1214
jobs:
1315
e2e-python:

.github/workflows/release_llama_index_server.yml

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,41 +22,46 @@ jobs:
2222
working-directory: ./python/llama-index-server
2323
if: |
2424
github.event_name == 'push' &&
25-
!startsWith(github.ref, 'refs/heads/release/llama-index-server-v')
25+
!startsWith(github.ref, 'refs/heads/release/llama-index-server-v') &&
26+
!contains(github.event.head_commit.message, 'Release: llama-index-server v')
2627
2728
steps:
2829
- name: Checkout Repository
2930
uses: actions/checkout@v4
3031
with:
3132
fetch-depth: 0
3233

34+
- name: Install uv
35+
uses: astral-sh/setup-uv@v5
36+
with:
37+
enable-cache: true
38+
3339
- name: Set up Python
3440
uses: actions/setup-python@v5
3541
with:
3642
python-version: "3.11"
3743

38-
- name: Install Poetry
39-
run: |
40-
curl -sSL https://install.python-poetry.org | python3 -
41-
4244
- name: Install dependencies
43-
run: poetry install
45+
shell: bash
46+
run: uv sync --all-extras --dev
4447

4548
- name: Setup Git
4649
run: |
4750
git config --global user.email "github-actions[bot]@users.noreply.github.com"
4851
git config --global user.name "github-actions[bot]"
4952
5053
- name: Bump patch version
54+
shell: bash
5155
run: |
52-
poetry version patch
56+
uvx --from=toml-cli toml set --toml-path=pyproject.toml project.version $(uvx --from=toml-cli toml get --toml-path=pyproject.toml project.version | awk -F. '{$NF = $NF + 1;}1' OFS=.)
5357
git add pyproject.toml
54-
git commit -m "chore(release): bump version to $(poetry version -s)"
58+
git commit -m "chore(release): bump llama-index-server version to $(uvx --from=toml-cli toml get --toml-path=pyproject.toml project.version)"
5559
5660
- name: Get current version
5761
id: get_version
62+
shell: bash
5863
run: |
59-
version=$(poetry version -s)
64+
version=$(uvx --from=toml-cli toml get --toml-path=pyproject.toml project.version)
6065
echo "current_version=${version}" >> "$GITHUB_OUTPUT"
6166
6267
- name: Create Release PR
@@ -91,31 +96,34 @@ jobs:
9196
- name: Checkout Repository
9297
uses: actions/checkout@v4
9398

99+
- name: Install uv
100+
uses: astral-sh/setup-uv@v5
101+
with:
102+
enable-cache: true
103+
94104
- name: Set up Python
95105
uses: actions/setup-python@v5
96106
with:
97107
python-version: "3.11"
98108

99-
- name: Install Poetry
100-
run: |
101-
curl -sSL https://install.python-poetry.org | python3 -
102-
103109
- name: Install dependencies
104-
run: poetry install
110+
shell: bash
111+
run: uv sync --all-extras
105112

106113
- name: Get current version
107114
id: get_version
115+
shell: bash
108116
run: |
109-
version=$(poetry version -s)
117+
version=$(uvx --from=toml-cli toml get --toml-path=pyproject.toml project.version)
110118
echo "current_version=${version}" >> "$GITHUB_OUTPUT"
111119
112-
- name: Build and publish to PyPI
113-
uses: JRubics/[email protected]
114-
with:
115-
python_version: "3.11"
116-
pypi_token: ${{ secrets.PYPI_TOKEN }}
117-
package_directory: "python/llama-index-server"
118-
poetry_install_options: "--without dev"
120+
- name: Build package
121+
shell: bash
122+
run: uv build --no-sources
123+
124+
- name: Publish to PyPI
125+
shell: bash
126+
run: uv publish --token ${{ secrets.PYPI_TOKEN }}
119127

120128
- name: Create GitHub Release
121129
uses: softprops/action-gh-release@v2

.github/workflows/test_llama_index_server.yml

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on:
44
pull_request:
55

66
env:
7-
POETRY_VERSION: "1.8.3"
87
PYTHON_VERSION: "3.9"
98

109
jobs:
@@ -21,29 +20,23 @@ jobs:
2120
steps:
2221
- uses: actions/checkout@v4
2322

24-
- name: Install Poetry
25-
run: pipx install poetry==${{ env.POETRY_VERSION }}
23+
- name: Install uv
24+
uses: astral-sh/setup-uv@v5
25+
with:
26+
enable-cache: true
2627

27-
- name: Set up python ${{ matrix.python-version }}
28+
- name: Set up Python ${{ matrix.python-version }}
2829
uses: actions/setup-python@v5
2930
with:
3031
python-version: ${{ matrix.python-version }}
31-
cache: "poetry"
32-
33-
- name: Configure Poetry
34-
run: |
35-
poetry config virtualenvs.create true
36-
poetry config virtualenvs.in-project true
37-
poetry env use python
3832

3933
- name: Install dependencies
4034
shell: bash
41-
run: poetry install --with dev
35+
run: uv sync --all-extras --dev
4236

4337
- name: Run unit tests
4438
shell: bash
45-
run: |
46-
poetry run pytest tests
39+
run: uv run pytest tests
4740

4841
type-check:
4942
name: Type Check
@@ -54,28 +47,23 @@ jobs:
5447
steps:
5548
- uses: actions/checkout@v4
5649

57-
- name: Install Poetry
58-
run: pipx install poetry==${{ env.POETRY_VERSION }}
50+
- name: Install uv
51+
uses: astral-sh/setup-uv@v5
52+
with:
53+
enable-cache: true
5954

6055
- name: Set up Python
6156
uses: actions/setup-python@v5
6257
with:
6358
python-version: ${{ env.PYTHON_VERSION }}
64-
cache: "poetry"
65-
66-
- name: Configure Poetry
67-
run: |
68-
poetry config virtualenvs.create true
69-
poetry config virtualenvs.in-project true
70-
poetry env use python
7159

7260
- name: Install dependencies
7361
shell: bash
74-
run: poetry install --with dev
62+
run: uv sync --all-extras --dev
7563

7664
- name: Run mypy
7765
shell: bash
78-
run: poetry run mypy llama_index
66+
run: uv run mypy llama_index
7967

8068
build:
8169
needs: [unit-test, type-check]
@@ -85,25 +73,25 @@ jobs:
8573
working-directory: python/llama-index-server
8674
steps:
8775
- uses: actions/checkout@v4
88-
- name: Install Poetry
89-
run: pipx install poetry==${{ env.POETRY_VERSION }}
76+
77+
- name: Install uv
78+
uses: astral-sh/setup-uv@v5
79+
with:
80+
enable-cache: true
81+
9082
- name: Set up Python
9183
uses: actions/setup-python@v5
9284
with:
9385
python-version: ${{ env.PYTHON_VERSION }}
94-
- name: Clear python cache
95-
shell: bash
96-
run: poetry cache clear --all pypi
97-
- name: Build package
98-
shell: bash
99-
run: poetry build
100-
- name: Test installing built package
86+
87+
- name: Install build package
10188
shell: bash
102-
run: python -m pip install .
89+
run: uv sync --all-extras
90+
10391
- name: Test import
10492
shell: bash
105-
working-directory: ${{ vars.RUNNER_TEMP }}
106-
run: python -c "from llama_index.server import LlamaIndexServer"
93+
run: uv run python -c "from llama_index.server import LlamaIndexServer"
94+
10795
- name: Upload artifact
10896
uses: actions/upload-artifact@v4
10997
with:

python/llama-index-server/.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Python files
2+
**/__pycache__
3+
**/build
4+
**/dist
5+
**/venv
6+
**/env
7+
**/llama-index-server.egg-info
8+
9+
# Jupyter files
10+
**/*.ipynb
11+
12+
# Pytest files
13+
**/pytest.ini
14+
**/pytest.ini
15+
16+
# Pytest cache
17+
**/pytest_cache
18+
19+
# Tools
20+
**/.ruff_cache
21+
**/.mypy_cache
22+
**/.pylint.d
23+
**/.pyrightconfig.json
24+
**/.ui
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Artifacts App
2+
3+
This guide explains how to set up and use the LlamaIndex server with the artifact workflow to write code or documents.
4+
5+
## Prerequisites
6+
7+
- [uv](https://github.com/astral-sh/uv) installed (a fast Python package manager and runner)
8+
- An OpenAI API key
9+
10+
## Steps
11+
12+
1. **Set the OpenAI API Key**
13+
14+
Export your OpenAI API key as an environment variable:
15+
16+
```sh
17+
export OPENAI_API_KEY=your_openai_api_key_here
18+
```
19+
20+
2. **Run the Server Using uv**
21+
22+
Start the server with the following command:
23+
24+
```sh
25+
uv run main.py
26+
```
27+
28+
This will launch the FastAPI server using the workflow defined in `main.py`.
29+
30+
3. **Access the Application**
31+
32+
Open your browser and go to:
33+
34+
```
35+
http://localhost:8000
36+
```
37+
38+
You will see the LlamaIndex Artifact app UI, where you can interact with the workflow.
39+
40+
## Notes
41+
42+
- By default, the server uses the code artifact workflow. If you want to use the document artifact workflow, edit `main.py` and uncomment the following line:
43+
44+
```python
45+
# from examples.artifact.document_workflow import ArtifactWorkflow
46+
```
47+
48+
and comment out the code workflow import.
49+
50+
- The UI provides starter questions to help you get started, or you can enter your own requests.
51+
52+
- The workflow will guide you through planning and generating code or documents based on your input.

0 commit comments

Comments
 (0)