Skip to content

Commit 64f76ae

Browse files
feat: add tavily search citations (#1778)
* feat: add citations for website knowledge * chore: remove console logs Signed-off-by: Ryan Hopper-Lowe <[email protected]> * feat: add citations for tavily search --------- Signed-off-by: Ryan Hopper-Lowe <[email protected]>
1 parent 02b9fe8 commit 64f76ae

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

ui/admin/app/lib/model/chatEvents.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,31 @@ export type ToolInput = {
33
content: string;
44
};
55

6-
export type KnowledgeToolOutput = { url?: string; content: string }[];
6+
export type KnowledgeToolOutput = {
7+
url?: string;
8+
content: string;
9+
}[];
710

811
export type GoogleSearchOutput = {
912
duration: { search: number; refine: number; response: number };
1013
query: string;
1114
results: { url: string; content: string }[];
1215
};
1316

17+
export type TavilySearchOutput = {
18+
query: string;
19+
follow_up_questions: string;
20+
answer: string;
21+
images: string[];
22+
results: {
23+
title: string;
24+
url: string;
25+
content: string;
26+
score: number;
27+
raw_content: string;
28+
}[];
29+
};
30+
1431
export type ToolCall = {
1532
name: string;
1633
description: string;
@@ -19,6 +36,7 @@ export type ToolCall = {
1936
metadata?: {
2037
category?: string;
2138
icon?: string;
39+
toolBundle?: string;
2240
};
2341
};
2442

ui/admin/app/lib/store/chat/message-store.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
ChatEvent,
55
GoogleSearchOutput,
66
KnowledgeToolOutput,
7+
TavilySearchOutput,
78
ToolCall,
89
} from "~/lib/model/chatEvents";
910
import { Message, promptMessage, toolCallMessage } from "~/lib/model/messages";
@@ -196,7 +197,6 @@ export const createMessageStore = () => {
196197
const { toolCall } = event;
197198

198199
const sources = pullSources(toolCall);
199-
200200
if (sources) parsedSources.push(...sources);
201201

202202
// if the toolCall is an output event
@@ -223,14 +223,23 @@ function pullSources(toolCall: ToolCall) {
223223

224224
const [err, output] = handleTry(() => JSON.parse(toolCall.output));
225225

226-
if (err) return [];
226+
if (err) {
227+
console.error(err);
228+
return [];
229+
}
227230

228231
if (toolCall.name === "Knowledge") {
229232
const o = output as KnowledgeToolOutput;
230233
return o;
231234
}
232235

233236
if (toolCall.name === "Search") {
237+
if (toolCall.metadata?.toolBundle === "Tavily Search") {
238+
const o = output as TavilySearchOutput;
239+
240+
return o.results;
241+
}
242+
234243
const o = output as GoogleSearchOutput;
235244
return o.results;
236245
}

0 commit comments

Comments
 (0)