Skip to content

Commit

Permalink
feat: add tavily search citations (#1778)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
ryanhopperlowe authored Feb 19, 2025
1 parent 02b9fe8 commit 64f76ae
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
20 changes: 19 additions & 1 deletion ui/admin/app/lib/model/chatEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,31 @@ export type ToolInput = {
content: string;
};

export type KnowledgeToolOutput = { url?: string; content: string }[];
export type KnowledgeToolOutput = {
url?: string;
content: string;
}[];

export type GoogleSearchOutput = {
duration: { search: number; refine: number; response: number };
query: string;
results: { url: string; content: string }[];
};

export type TavilySearchOutput = {
query: string;
follow_up_questions: string;
answer: string;
images: string[];
results: {
title: string;
url: string;
content: string;
score: number;
raw_content: string;
}[];
};

export type ToolCall = {
name: string;
description: string;
Expand All @@ -19,6 +36,7 @@ export type ToolCall = {
metadata?: {
category?: string;
icon?: string;
toolBundle?: string;
};
};

Expand Down
13 changes: 11 additions & 2 deletions ui/admin/app/lib/store/chat/message-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ChatEvent,
GoogleSearchOutput,
KnowledgeToolOutput,
TavilySearchOutput,
ToolCall,
} from "~/lib/model/chatEvents";
import { Message, promptMessage, toolCallMessage } from "~/lib/model/messages";
Expand Down Expand Up @@ -196,7 +197,6 @@ export const createMessageStore = () => {
const { toolCall } = event;

const sources = pullSources(toolCall);

if (sources) parsedSources.push(...sources);

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

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

if (err) return [];
if (err) {
console.error(err);
return [];
}

if (toolCall.name === "Knowledge") {
const o = output as KnowledgeToolOutput;
return o;
}

if (toolCall.name === "Search") {
if (toolCall.metadata?.toolBundle === "Tavily Search") {
const o = output as TavilySearchOutput;

return o.results;
}

const o = output as GoogleSearchOutput;
return o.results;
}
Expand Down

0 comments on commit 64f76ae

Please sign in to comment.