Skip to content

Commit

Permalink
Add interstitial for tool_start messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathewjordan committed Dec 17, 2024
1 parent b0025a7 commit af28bcd
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 13 deletions.
21 changes: 21 additions & 0 deletions components/Chat/Response/Response.styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@ const StyledResponse = styled("section", {
},
});

const StyledInterstitial = styled("div", {
color: "$black",
padding: "$gr2 0",
fontFamily: "$northwesternSansBold",
fontSize: "$gr3",
display: "flex",
alignItems: "center",
gap: "$gr2",
margin: "0",

div: {
display: "block",
width: "1.5rem",
height: "1.5rem",
borderRadius: "50%",
backgroundColor: "$brightBlueB",
content: "",
},
});

const StyledResponseAside = styled("aside", {});

const StyledResponseContent = styled("div", {});
Expand Down Expand Up @@ -154,6 +174,7 @@ export {
StyledResponseDisclaimer,
StyledResponseWrapper,
StyledImages,
StyledInterstitial,
StyledQuestion,
StyledResponseMarkdown,
StyledUnsubmitted,
Expand Down
32 changes: 32 additions & 0 deletions components/Chat/Response/Response.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useEffect, useState } from "react";
import {
StyledInterstitial,
StyledQuestion,
StyledResponse,
StyledResponseWrapper,
Expand Down Expand Up @@ -49,6 +50,37 @@ const ChatResponse: React.FC<ChatResponseProps> = ({
));
}

if (type === "tool_start") {
// @ts-ignore
const { tool, input } = message?.message;
let interstitialMessage = "";
switch (tool) {
case "discover_fields":
interstitialMessage = "Discovering fields";
break;
case "search":
interstitialMessage = `Searching for: ${input?.query}`;
break;
case "aggregate":
console.log(`aggregate input`, input);
interstitialMessage = `Aggregating ${input?.agg_field} by ${input?.term_field} ${input?.term}`;
break;
default:
console.warn("Unknown tool_start message", message);
}

// @ts-ignore
setRenderedMessage((prev) => (
<>
{prev}
<StyledInterstitial>
<div></div>
<label>{interstitialMessage}</label>
</StyledInterstitial>
</>
));
}

if (type === "search_result") {
// @ts-ignore
setRenderedMessage((prev) => (
Expand Down
2 changes: 1 addition & 1 deletion components/Shared/BouncingLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const bouncingLoader = keyframes({

const StyledBouncingLoader = styled("div", {
display: "flex",
margin: "$gr2 auto",
margin: "$gr2 0",

"& > div": {
width: "$gr2",
Expand Down
27 changes: 15 additions & 12 deletions types/components/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,21 @@ type MessageModel = {
model: string;
};

type MessageTool = {
input: {
query:
| string
| {
agg_field: string;
term_field: string;
term: string;
};
};
tool: "search" | "aggregate";
};
type MessageTool =
| {
tool: "discover_fields";
input: {};
}
| {
tool: "search";
input: {
query: string;
};
}
| {
tool: "aggregate";
input: { agg_field: string; term_field: string; term: string };
};

type MessageShape =
| string
Expand Down

0 comments on commit af28bcd

Please sign in to comment.