Skip to content

Commit b8a1ff6

Browse files
authored
feat: Support citation for agentic template (#642)
1 parent 5fe9e17 commit b8a1ff6

File tree

25 files changed

+3224
-2820
lines changed

25 files changed

+3224
-2820
lines changed

.changeset/few-news-marry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@create-llama/llama-index-server": patch
3+
---
4+
5+
Show agent widget in UI when making a tool call

.changeset/rich-nights-hug.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@create-llama/llama-index-server": patch
3+
---
4+
5+
Support citation for query engine tool

.changeset/small-insects-hug.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-llama": patch
3+
---
4+
5+
Support citation for agentic template (Python)

.changeset/stale-things-beg.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@llamaindex/server": patch
3+
---
4+
5+
Bump version: [email protected]

.github/workflows/e2e.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ jobs:
6464
run: pnpm run pack-install
6565
working-directory: packages/create-llama
6666

67+
- name: Build and store server package
68+
run: |
69+
pnpm run build
70+
wheel_file=$(ls dist/*.whl | head -n 1)
71+
mkdir -p "${{ runner.temp }}"
72+
cp "$wheel_file" "${{ runner.temp }}/"
73+
echo "SERVER_PACKAGE_PATH=${{ runner.temp }}/$(basename "$wheel_file")" >> $GITHUB_ENV
74+
working-directory: python/llama-index-server
75+
6776
- name: Run Playwright tests for Python
6877
run: pnpm run e2e:python
6978
env:
@@ -74,6 +83,7 @@ jobs:
7483
TEMPLATE_TYPE: ${{ matrix.template-types }}
7584
PYTHONIOENCODING: utf-8
7685
PYTHONLEGACYWINDOWSSTDIO: utf-8
86+
SERVER_PACKAGE_PATH: ${{ env.SERVER_PACKAGE_PATH }}
7787
working-directory: packages/create-llama
7888

7989
- uses: actions/upload-artifact@v4

packages/create-llama/helpers/python.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { parse, stringify } from "smol-toml";
55
import terminalLink from "terminal-link";
66
import { isUvAvailable, tryUvSync } from "./uv";
77

8+
import { isCI } from "ci-info";
89
import { assetRelocator, copy } from "./copy";
910
import { templatesDir } from "./dir";
1011
import { Tool } from "./tools";
@@ -278,6 +279,19 @@ const getAdditionalDependencies = (
278279
}
279280
}
280281

282+
// If app template is llama-index-server and CI and SERVER_PACKAGE_PATH is set,
283+
// add @llamaindex/server to dependencies
284+
if (
285+
templateType === "llamaindexserver" &&
286+
isCI &&
287+
process.env.SERVER_PACKAGE_PATH
288+
) {
289+
dependencies.push({
290+
name: "llama-index-server",
291+
version: `@file://${process.env.SERVER_PACKAGE_PATH}`,
292+
});
293+
}
294+
281295
return dependencies;
282296
};
283297

packages/create-llama/templates/components/use-cases/python/agentic_rag/workflow.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
from app.index import get_index
44
from llama_index.core.agent.workflow import AgentWorkflow
55
from llama_index.core.settings import Settings
6-
from llama_index.llms.openai import OpenAI
76
from llama_index.server.api.models import ChatRequest
87
from llama_index.server.tools.index import get_query_engine_tool
8+
from llama_index.server.tools.index.citation import (
9+
CITATION_SYSTEM_PROMPT,
10+
enable_citation,
11+
)
912

1013

1114
def create_workflow(chat_request: Optional[ChatRequest] = None) -> AgentWorkflow:
@@ -14,9 +17,16 @@ def create_workflow(chat_request: Optional[ChatRequest] = None) -> AgentWorkflow
1417
raise RuntimeError(
1518
"Index not found! Please run `uv run generate` to index the data first."
1619
)
17-
query_tool = get_query_engine_tool(index=index)
20+
# Create a query tool with citations enabled
21+
query_tool = enable_citation(get_query_engine_tool(index=index))
22+
23+
# Define the system prompt for the agent
24+
# Append the citation system prompt to the system prompt
25+
system_prompt = """You are a helpful assistant"""
26+
system_prompt += CITATION_SYSTEM_PROMPT
27+
1828
return AgentWorkflow.from_tools_or_functions(
1929
tools_or_functions=[query_tool],
20-
llm=Settings.llm or OpenAI(model="gpt-4o-mini"),
21-
system_prompt="You are a helpful assistant.",
30+
llm=Settings.llm,
31+
system_prompt=system_prompt,
2232
)

packages/create-llama/templates/types/llamaindexserver/fastapi/app/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
def init_settings():
99
if os.getenv("OPENAI_API_KEY") is None:
1010
raise RuntimeError("OPENAI_API_KEY is missing in environment variables")
11-
Settings.llm = OpenAI(model="gpt-4o-mini")
12-
Settings.embed_model = OpenAIEmbedding(model="text-embedding-3-small")
11+
Settings.llm = OpenAI(model="gpt-4.1")
12+
Settings.embed_model = OpenAIEmbedding(model="text-embedding-3-large")

packages/create-llama/templates/types/llamaindexserver/fastapi/pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ disable_error_code = [ "return-value", "assignment" ]
4646
module = "app.*"
4747
ignore_missing_imports = false
4848

49+
[tool.hatch.metadata]
50+
allow-direct-references = true
51+
4952
[build-system]
5053
requires = [ "hatchling>=1.24" ]
51-
build-backend = "hatchling.build"
54+
build-backend = "hatchling.build"

packages/server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"@babel/traverse": "^7.27.0",
6666
"@babel/types": "^7.27.0",
6767
"@hookform/resolvers": "^5.0.1",
68-
"@llamaindex/chat-ui": "0.4.5",
68+
"@llamaindex/chat-ui": "0.4.6",
6969
"@radix-ui/react-accordion": "^1.2.3",
7070
"@radix-ui/react-alert-dialog": "^1.1.7",
7171
"@radix-ui/react-aspect-ratio": "^1.1.3",

0 commit comments

Comments
 (0)