Skip to content

Lee/update citation format #504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nasty-dingos-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-llama": patch
---

Bump chat-ui and improve citation prompt
19 changes: 9 additions & 10 deletions helpers/env-variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,11 +483,12 @@ const getSystemPromptEnv = (
});
}
if (tools?.length == 0 && (dataSources?.length ?? 0 > 0)) {
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix the condition for adding citation prompt.

The current condition has operator precedence and logical issues. The expression dataSources?.length ?? 0 > 0 is not correctly checking if there are data sources.

Apply this diff to fix the condition:

-  if (tools?.length == 0 && (dataSources?.length ?? 0 > 0)) {
+  if (tools?.length == 0 && ((dataSources?.length ?? 0) > 0)) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (tools?.length == 0 && (dataSources?.length ?? 0 > 0)) {
if (tools?.length == 0 && ((dataSources?.length ?? 0) > 0)) {
🧰 Tools
🪛 Biome (1.9.4)

[error] 485-485: Comparing to itself is potentially pointless.

(lint/suspicious/noSelfCompare)

const citationPrompt = `'You have provided information from a knowledge base that has been passed to you in nodes of information.
Each node has useful metadata such as node ID, file name, page, etc.
Please add the citation to the data node for each sentence or paragraph that you reference in the provided information.
The citation format is: . [citation:<node_id>]()
Where the <node_id> is the unique identifier of the data node.
const citationPrompt = `'You have provided information from a knowledge base that separates the information into multiple nodes.
Always add a citation to each sentence or paragraph that you reference in the provided information using the node_id field in the header of each node.

The citation format is: [citation:<node_id>]
Where the <node_id> is the node_id field in the header of each node.
Always separate the citation by a space.

Example:
We have two nodes:
Expand All @@ -497,11 +498,9 @@ We have two nodes:
node_id: abc
file_name: animal.pdf

User question: Tell me a fun fact about Llama.
Your answer:
A baby llama is called "Cria" [citation:xyz]().
It often live in desert [citation:abc]().
It\\'s cute animal.
Your answer with citations:
A baby llama is called "Cria" [citation:xyz]
It often lives in desert [citation:abc] [citation:xyz]
'`;
systemPromptEnv.push({
name: "SYSTEM_CITATION_PROMPT",
Expand Down
2 changes: 1 addition & 1 deletion templates/types/streaming/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@radix-ui/react-select": "^2.1.1",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-tabs": "^1.1.0",
"@llamaindex/chat-ui": "0.0.14",
"@llamaindex/chat-ui": "0.0.16",
"ai": "^4.0.3",
"ajv": "^8.12.0",
"class-variance-authority": "^0.7.1",
Expand Down
Loading