ModelSelector.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import { Button, Dropdown, Typography, Tag } from "antd";
  2. import {
  3. DownOutlined,
  4. ReloadOutlined,
  5. GlobalOutlined,
  6. } from "@ant-design/icons";
  7. import type { MenuProps } from "antd";
  8. const { Text } = Typography;
  9. const ModelSelector = () => {
  10. const modelItems: MenuProps["items"] = [
  11. {
  12. key: "auto",
  13. label: (
  14. <div className="py-2">
  15. <div className="font-medium text-gray-900">Auto</div>
  16. </div>
  17. ),
  18. },
  19. {
  20. key: "gpt-4o",
  21. label: (
  22. <div className="py-2">
  23. <div className="font-medium text-gray-900">
  24. GPT-4o<Tag>翻译</Tag>
  25. </div>
  26. <Text type="secondary">适用于大多数任务</Text>
  27. </div>
  28. ),
  29. },
  30. {
  31. key: "o4-mini",
  32. label: (
  33. <div className="py-2">
  34. <div className="font-medium text-gray-900">o4-mini</div>
  35. <Text type="secondary">快速进行高级推理</Text>
  36. </div>
  37. ),
  38. },
  39. {
  40. key: "gpt-4.1-mini",
  41. label: (
  42. <div className="py-2">
  43. <div className="font-medium text-gray-900">GPT-4.1-mini</div>
  44. <Text type="secondary">适合处理日常任务</Text>
  45. </div>
  46. ),
  47. },
  48. {
  49. type: "divider",
  50. },
  51. {
  52. key: "refresh",
  53. label: (
  54. <div className="py-2 flex items-center space-x-2 text-gray-700">
  55. <ReloadOutlined />
  56. <span>重试</span>
  57. <div className="ml-auto">
  58. <Text type="secondary">GPT-4o</Text>
  59. </div>
  60. </div>
  61. ),
  62. },
  63. {
  64. key: "search",
  65. label: (
  66. <div className="py-2 flex items-center space-x-2 text-gray-700">
  67. <GlobalOutlined />
  68. <span>搜索网页</span>
  69. </div>
  70. ),
  71. },
  72. ];
  73. const handleMenuClick: MenuProps["onClick"] = ({ key }) => {
  74. if (key === "refresh") {
  75. console.log("重试操作");
  76. return;
  77. }
  78. if (key === "search") {
  79. console.log("搜索网页");
  80. return;
  81. }
  82. };
  83. return (
  84. <div className="bg-gray-50 min-h-screen">
  85. <div className="max-w-md mx-auto">
  86. <Dropdown
  87. menu={{
  88. items: modelItems,
  89. onClick: handleMenuClick,
  90. className: "w-64",
  91. }}
  92. trigger={["click"]}
  93. placement="bottomLeft"
  94. overlayClassName="model-selector-dropdown"
  95. >
  96. <Button
  97. className="flex items-center justify-between w-48 h-12 px-4 border border-gray-300 rounded-lg bg-white hover:bg-gray-50 shadow-sm"
  98. type="text"
  99. >
  100. <div className="flex items-center space-x-2">
  101. <span className="font-medium text-gray-900 model_name">
  102. {"AI"}
  103. </span>
  104. <DownOutlined className="text-gray-500 text-sm" />
  105. </div>
  106. </Button>
  107. </Dropdown>
  108. </div>
  109. <style>{`
  110. .model-selector-dropdown .ant-dropdown-menu {
  111. padding: 8px;
  112. border-radius: 12px;
  113. box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
  114. border: 1px solid #e5e7eb;
  115. }
  116. .model-selector-dropdown .ant-dropdown-menu-item {
  117. padding: 0;
  118. margin: 2px 0;
  119. border-radius: 8px;
  120. }
  121. .model-selector-dropdown .ant-dropdown-menu-item:hover {
  122. background-color: #f3f4f6;
  123. }
  124. .model-selector-dropdown .ant-dropdown-menu-item-selected {
  125. background-color: #eff6ff;
  126. }
  127. .model-selector-dropdown .ant-dropdown-menu-divider {
  128. margin: 8px 0;
  129. background-color: #e5e7eb;
  130. }
  131. `}</style>
  132. </div>
  133. );
  134. };
  135. export default ModelSelector;