import { useId, useMemo, useRef, useState } from "react"; import { Icon } from "../../../components/Icon"; import { CHAT_MAX_TOKENS_LIMIT, CHAT_QUESTION_MAX_LENGTH, CHAT_REQUEST_LIMIT_MAX, DEFAULT_CHAT_INPUT, type ChatCompletionRequest, type ChatFormInput, validateChatInput, } from "../types"; interface ChatComposerProps { isRunning: boolean; onStart: (request: ChatCompletionRequest) => void; onStop: () => void; } export function ChatComposer({ isRunning, onStart, onStop }: ChatComposerProps) { const [input, setInput] = useState(DEFAULT_CHAT_INPUT); const [submitted, setSubmitted] = useState(false); const formRef = useRef(null); const errorId = useId(); const validation = useMemo(() => validateChatInput(input), [input]); const showValidation = submitted && validation.request === null; function updateInput(key: K, value: ChatFormInput[K]) { setInput((current) => ({ ...current, [key]: value })); if (submitted) setSubmitted(false); } function submit() { setSubmitted(true); if (isRunning || validation.request === null) return; onStart(validation.request); } return (
GROUNDED QUESTION

提交证据约束问题

POST · SSE
{ event.preventDefault(); submit(); }} ref={formRef} > updateInput("knowledgeBaseId", event.target.value)} spellCheck={false} type="text" value={input.knowledgeBaseId} />

默认使用公开合成知识库,访问 scope 始终由后端身份决定。