"use client"; import React from "react"; import { PaperPlaneIcon, StopIcon } from "@radix-ui/react-icons"; import { ChatRequestOptions } from "ai"; import mistralTokenizer from "mistral-tokenizer-js"; import TextareaAutosize from "react-textarea-autosize"; import { tokenLimit } from "@/lib/token-counter"; import { Button } from "../ui/button"; interface ChatBottombarProps { selectedModel: string | undefined; input: string; handleInputChange: (e: React.ChangeEvent) => void; handleSubmit: ( e: React.FormEvent, chatRequestOptions?: ChatRequestOptions ) => void; isLoading: boolean; stop: () => void; } export default function ChatBottombar({ selectedModel, input, handleInputChange, handleSubmit, isLoading, stop, }: ChatBottombarProps) { const inputRef = React.useRef(null); const hasSelectedModel = selectedModel && selectedModel !== ""; const handleKeyPress = (e: React.KeyboardEvent) => { if (e.key === "Enter" && !e.shiftKey && hasSelectedModel && !isLoading) { e.preventDefault(); handleSubmit(e as unknown as React.FormEvent); } }; const tokenCount = input ? mistralTokenizer.encode(input).length - 1 : 0; return (
{/*
*/}
{tokenCount > tokenLimit ? ( {tokenCount} token{tokenCount == 1 ? "" : "s"} ) : ( {tokenCount} token{tokenCount == 1 ? "" : "s"} )}
{!isLoading ? ( ) : ( )}
Enter to send, Shift + Enter for new line
); }