Ai.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { useEffect, useState } from "react";
  2. import type { IAiModel, IAiModelResponse } from "../../api/ai";
  3. import { get } from "../../request";
  4. import { Alert, Tag, Typography } from "antd";
  5. const { Text } = Typography;
  6. interface IAiCtl {
  7. model?: string;
  8. }
  9. const AiCtl = ({ model }: IAiCtl) => {
  10. const [curr, setCurr] = useState<IAiModel>();
  11. useEffect(() => {
  12. const url = `/v2/ai-model/${model}`;
  13. console.info("api request", url);
  14. get<IAiModelResponse>(url).then((json) => {
  15. console.info("api response", json);
  16. if (json.ok) {
  17. setCurr(json.data);
  18. }
  19. });
  20. }, [model]);
  21. return (
  22. <Alert
  23. message={
  24. <div>
  25. <Text strong style={{ display: "block" }}>
  26. {curr?.name}
  27. </Text>
  28. <Tag>{curr?.model}</Tag>
  29. <Text>{curr?.url}</Text>
  30. </div>
  31. }
  32. type="info"
  33. />
  34. );
  35. };
  36. interface IWidget {
  37. props: string;
  38. }
  39. const Widget = ({ props }: IWidget) => {
  40. const prop = JSON.parse(atob(props)) as IAiCtl;
  41. console.log(prop);
  42. return (
  43. <>
  44. <AiCtl {...prop} />
  45. </>
  46. );
  47. };
  48. export default Widget;