Skip to content

Commit

Permalink
Remove commented out code. Fix lint errors in frontend code.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnguonly committed Apr 16, 2024
1 parent e210dd5 commit 024c224
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
10 changes: 7 additions & 3 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ function App(props: { edit?: boolean }) {
const { currentChat, assistantConfig, isLoading } = useThreadAndAssistant();

const startTurn = useCallback(
async (message: MessageWithFiles | null, thread_id: string, assistantType: string) => {
async (
message: MessageWithFiles | null,
thread_id: string,
assistantType: string,
) => {
const files = message?.files || [];
if (files.length > 0) {
const formData = files.reduce((formData, file) => {
Expand Down Expand Up @@ -58,7 +62,7 @@ function App(props: { edit?: boolean }) {
example: false,
id: `human-${Math.random()}`,
},
]
];

if (assistantType === "chat_retrieval") {
// The RAG assistant type requires an object with a `messages` field.
Expand All @@ -68,7 +72,7 @@ function App(props: { edit?: boolean }) {
msg.role = "human";
return msg;
}),
}
};
}
}

Expand Down
16 changes: 14 additions & 2 deletions frontend/src/components/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,27 @@ export function Chat(props: ChatProps) {
{next.length > 0 && props.stream?.status !== "inflight" && (
<div
className="flex items-center rounded-md bg-blue-50 px-2 py-1 text-xs font-medium text-blue-800 ring-1 ring-inset ring-yellow-600/20 cursor-pointer"
onClick={() => props.startStream(null, currentChat.thread_id, assistantConfig.config.configurable?.type as string)}
onClick={() =>
props.startStream(
null,
currentChat.thread_id,
assistantConfig.config.configurable?.type as string,
)
}
>
<ArrowDownCircleIcon className="h-5 w-5 mr-1" />
Click to continue.
</div>
)}
<div className="fixed left-0 lg:left-72 bottom-0 right-0 p-4">
<TypingBox
onSubmit={(msg) => props.startStream(msg, currentChat.thread_id, assistantConfig.config.configurable?.type as string)}
onSubmit={(msg) =>
props.startStream(
msg,
currentChat.thread_id,
assistantConfig.config.configurable?.type as string,
)
}
onInterrupt={
props.stream?.status === "inflight" ? props.stopStream : undefined
}
Expand Down
10 changes: 8 additions & 2 deletions frontend/src/hooks/useStreamState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ export interface StreamState {

export interface StreamStateProps {
stream: StreamState | null;
startStream: (input: Message[] | Record<string, any> | null, thread_id: string) => Promise<void>;
startStream: (
input: Message[] | Record<string, any> | null,
thread_id: string,
) => Promise<void>;
stopStream?: (clear?: boolean) => void;
}

Expand All @@ -19,7 +22,10 @@ export function useStreamState(): StreamStateProps {
const [controller, setController] = useState<AbortController | null>(null);

const startStream = useCallback(
async (input: Message[] | Record<string, any> |null, thread_id: string) => {
async (
input: Message[] | Record<string, any> | null,
thread_id: string,
) => {
const controller = new AbortController();
setController(controller);
setCurrent({ status: "inflight", messages: input || [] });
Expand Down

0 comments on commit 024c224

Please sign in to comment.