"use client"; import { FormEvent, useState } from "react"; type GenerateResponse = { message: string; unique_id: string; url: string; query_url: string; title?: string | null; source?: string | null; request_id?: string | null; size_bytes: number; created_at: string; expires_at: string; }; const apiBaseUrl = process.env.NEXT_PUBLIC_API_BASE_URL?.replace(/\/$/, "") || "http://localhost:8000"; const initialHtml = `

勾股定理

在直角三角形中,两条直角边长度分别为 a、b,斜边长度为 c,则 a² + b² = c²。

`; export default function Home() { const [title, setTitle] = useState("知识点讲解"); const [source, setSource] = useState("tencent-agent"); const [requestId, setRequestId] = useState(""); const [htmlContent, setHtmlContent] = useState(initialHtml); const [loading, setLoading] = useState(false); const [result, setResult] = useState(null); const [error, setError] = useState(null); const handleSubmit = async (event: FormEvent) => { event.preventDefault(); setLoading(true); setError(null); setResult(null); try { const response = await fetch(`${apiBaseUrl}/api/html/generate`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ title, source, request_id: requestId || undefined, html_content: htmlContent, }), }); const data = await response.json(); if (!response.ok) { throw new Error(data.detail || data.message || "生成 HTML 失败"); } setResult(data); } catch (submissionError) { setError( submissionError instanceof Error ? submissionError.message : "生成 HTML 失败,请稍后重试。" ); } finally { setLoading(false); } }; return (

HTML Explanation API

教育智能体 HTML 发布接口演示

这个页面用于手工联调。智能体调用后端接口提交 HTML 内容,后端会返回唯一链接和查询地址。