feat(mp): AI 聊天传递 patient_id 支持体征数据查询 Tool Call
- ai-chat service: sendAiMessage 新增 patientId 可选参数 - messages 页面: 从 authStore 获取 currentPatient.id 传入 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -26,6 +26,7 @@ function genId(): string {
|
|||||||
|
|
||||||
export default function Messages() {
|
export default function Messages() {
|
||||||
const user = useAuthStore((s) => s.user);
|
const user = useAuthStore((s) => s.user);
|
||||||
|
const currentPatient = useAuthStore((s) => s.currentPatient);
|
||||||
const modeClass = useElderClass();
|
const modeClass = useElderClass();
|
||||||
const [messages, setMessages] = useState<AiChatMessage[]>([]);
|
const [messages, setMessages] = useState<AiChatMessage[]>([]);
|
||||||
const [inputText, setInputText] = useState('');
|
const [inputText, setInputText] = useState('');
|
||||||
@@ -70,7 +71,7 @@ export default function Messages() {
|
|||||||
scrollToBottom(next);
|
scrollToBottom(next);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const resp = await sendAiMessage(content, next);
|
const resp = await sendAiMessage(content, next, currentPatient?.id);
|
||||||
const aiMsg: AiChatMessage = {
|
const aiMsg: AiChatMessage = {
|
||||||
id: resp.message_id || genId(),
|
id: resp.message_id || genId(),
|
||||||
role: 'assistant',
|
role: 'assistant',
|
||||||
|
|||||||
@@ -16,11 +16,16 @@ export interface AiChatResponse {
|
|||||||
export async function sendAiMessage(
|
export async function sendAiMessage(
|
||||||
message: string,
|
message: string,
|
||||||
history?: AiChatMessage[],
|
history?: AiChatMessage[],
|
||||||
|
patientId?: string,
|
||||||
): Promise<AiChatResponse> {
|
): Promise<AiChatResponse> {
|
||||||
const resp = await api.post<AiChatResponse>('/ai/chat', {
|
const body: Record<string, unknown> = {
|
||||||
message,
|
message,
|
||||||
history: history?.slice(-10),
|
history: history?.slice(-10),
|
||||||
});
|
};
|
||||||
|
if (patientId) {
|
||||||
|
body.patient_id = patientId;
|
||||||
|
}
|
||||||
|
const resp = await api.post<AiChatResponse>('/ai/chat', body);
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user