-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature (PersonaFlow-148): Tool streaming (#168)
* committed new poetry lock file * removed userID when fetching from useChat to use default user * made retrieval_description optional * added tools folder * added TToolCall and mapped each tool call to a ToolQuery * render tool_calls in MessagesContainer * updated styling for tools * adjusted border on build-panel * added tool-result * added link to url * remove transition * removed underline in accordion, added link to visit url * addressed pr comments
- Loading branch information
Showing
11 changed files
with
729 additions
and
531 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { TToolCall } from "@/data-provider/types"; | ||
import ToolQuery from "./tool-query"; | ||
|
||
type TToolContainer = { | ||
toolCalls: TToolCall[]; | ||
}; | ||
|
||
export default function ToolContainer({ toolCalls }: TToolContainer) { | ||
return ( | ||
<div className="flex flex-col py-2 px-3 text-base md:px-4 my-4 mr-auto w-3/4 md:px-5 lg:px-1 xl:px-5 flex-col gap-4"> | ||
{toolCalls.map((toolCall) => ( | ||
<ToolQuery | ||
query={toolCall.args.query} | ||
tool={toolCall.name} | ||
key={toolCall.id} | ||
/> | ||
))} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { List, Search } from "lucide-react"; | ||
|
||
const icons = [ | ||
{ title: "query", icon: <List /> }, | ||
{ title: "search", icon: <Search /> }, | ||
]; | ||
|
||
type TToolQueryProps = { | ||
query: string; | ||
tool: string; | ||
}; | ||
|
||
export default function ToolQuery({ query, tool }: TToolQueryProps) { | ||
return ( | ||
<> | ||
<h2 className="flex gap-2 rounded-sm border-2 p-2"> | ||
<List /> Query: {query} | ||
</h2> | ||
<h2 className="flex gap-2 rounded-sm border-2 p-2"> | ||
<Search /> Using: {tool} | ||
</h2> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { | ||
Accordion, | ||
AccordionItem, | ||
AccordionTrigger, | ||
AccordionContent, | ||
} from "@/components/ui/accordion"; | ||
import { Button } from "@/components/ui/button"; | ||
import { | ||
Collapsible, | ||
CollapsibleContent, | ||
CollapsibleTrigger, | ||
} from "@/components/ui/collapsible"; | ||
import { TMessage } from "@/data-provider/types"; | ||
import { CaretSortIcon } from "@radix-ui/react-icons"; | ||
import { MoveUpRight } from "lucide-react"; | ||
import Link from "next/link"; | ||
import { useState } from "react"; | ||
|
||
const AccordionToolContent = ({ | ||
content, | ||
url, | ||
}: { | ||
content: string; | ||
url: string; | ||
}) => { | ||
return ( | ||
<Accordion type="single" collapsible> | ||
<AccordionItem value={url}> | ||
<AccordionTrigger className="text-left"> | ||
<div className="flex w-full"> | ||
{url} | ||
<Button variant="outline" type="button" className="ml-auto mr-2"> | ||
<Link | ||
href={url} | ||
target="_blank" | ||
className="flex gap-2 items-center" | ||
> | ||
Visit | ||
<MoveUpRight className="w-4 h-4" /> | ||
</Link> | ||
</Button> | ||
</div> | ||
</AccordionTrigger> | ||
<AccordionContent>{content}</AccordionContent> | ||
</AccordionItem> | ||
</Accordion> | ||
); | ||
}; | ||
|
||
export function ToolResult({ toolResult }: { toolResult: TMessage }) { | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
return ( | ||
<div className="flex flex-col py-2 px-3 text-base md:px-4 mr-auto w-3/4 md:px-5 lg:px-1 xl:px-5 flex-col gap-4"> | ||
<Collapsible open={isOpen} onOpenChange={setIsOpen}> | ||
<div className="flex items-center justify-between"> | ||
<CollapsibleTrigger asChild> | ||
<Button variant="outline" type="button" className="gap-2 mb-2"> | ||
<span>Tool results: {toolResult.name}</span> | ||
<CaretSortIcon className="h-5 w-5" /> | ||
</Button> | ||
</CollapsibleTrigger> | ||
</div> | ||
<CollapsibleContent className="space-y-2"> | ||
{Array.isArray(toolResult.content) | ||
? toolResult.content.map((item) => ( | ||
<AccordionToolContent | ||
url={item.url} | ||
content={item.content} | ||
key={item.url} | ||
/> | ||
)) | ||
: toolResult.content} | ||
</CollapsibleContent> | ||
</Collapsible> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
"use client" | ||
|
||
import * as CollapsiblePrimitive from "@radix-ui/react-collapsible" | ||
|
||
const Collapsible = CollapsiblePrimitive.Root | ||
|
||
const CollapsibleTrigger = CollapsiblePrimitive.CollapsibleTrigger | ||
|
||
const CollapsibleContent = CollapsiblePrimitive.CollapsibleContent | ||
|
||
export { Collapsible, CollapsibleTrigger, CollapsibleContent } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters