Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | import React from "react";
import { useParams } from "react-router-dom";
import InputField from "../InputField/InputField";
import "./ChatField.css";
import { useApiHandler } from "@/services/useApiHandler";
export interface ChatFieldProps {
placeholder?: string;
}
export type Message = {
user: string;
text: string | Promise<string | null>;
};
const ChatField: React.FC<ChatFieldProps> = (props) => {
const { getApiHandler } = useApiHandler();
const { modelId } = useParams();
const messages: Message[] = [];
// const prompt_model = (prompt: string) => {
// const res =
// api_handler.model_router.prompt(props.modelId, prompt) ?? "Error";
// messages.push({
// user: "model",
// text: res,
// });
// };
// const prompt = async (prompt: string) => {
// return await api_handler.model_router.prompt(props.modelId, prompt);
// };
return (
<div className="flex">
<InputField
placeholder={props.placeholder ?? "Ask me something..."}
classes={["chat-field"]}
onButtonClick={async (text) => {
if (!modelId) return;
try {
// Get API handler with Auth0 token
const api_handler = getApiHandler();
// Call the model prompt API
const res = await api_handler.model_router.prompt(
atob(modelId),
text,
);
// You can also update local state here if you want to display the message
} catch (err) {
console.error("Error calling model:", err);
}
}}
/>
</div>
);
};
export default ChatField;
|