diff --git a/frontend/packages/core/src/pages/playground/index.tsx b/frontend/packages/core/src/pages/playground/index.tsx index 3602683b..3afb24f7 100644 --- a/frontend/packages/core/src/pages/playground/index.tsx +++ b/frontend/packages/core/src/pages/playground/index.tsx @@ -9,11 +9,13 @@ import './styles.css' interface ModelCardProps { title: string - status: 'success' | 'failure' + status: ModelCardStatus defaultModel: string onSettingClick?: () => void } +export type ModelCardStatus = 'success' | 'failure' + const ModelCard: React.FC = ({ title, status, defaultModel, onSettingClick }) => (
@@ -22,50 +24,54 @@ const ModelCard: React.FC = ({ title, status, defaultModel, onSe
{title} -
-
-
+
{defaultModel}
) +interface KeyStatus { + status: ModelCardStatus + keyID: number | string +} + interface KeyStatusCardProps { - keys: Array<'success' | 'failure'> + keys: KeyStatus[] title: string } const KeyStatusCard: React.FC = ({ keys, title }) => ( -
+
-
{title}
-
- {keys.map((status, index) => ( -
- ))} +
+
{title}
+
+ {keys.map((key) => ( +
+ ))} +
) const ServiceCard: React.FC = () => ( -
+
@@ -74,109 +80,118 @@ const ServiceCard: React.FC = () => (
) +const calculateNodePositions = (models: Array<{ id: string; type: string }>, startY = 50, gap = 150) => { + return models.reduce( + (acc, model, index) => { + acc[model.id] = { + x: 400, + y: startY + index * gap + } + acc[`${model.id}-keys`] = { + x: 750, + y: startY + index * gap + } + return acc + }, + {} as Record + ) +} + +const modelData = [ + { id: 'openai', type: 'openai', title: 'OpenAI', status: 'success', defaultModel: 'gpt-4' }, + { id: 'anthropic', type: 'anthropic', title: 'Anthropic', status: 'success', defaultModel: 'claude-2' }, + { id: 'gemini', type: 'gemini', title: 'Google Gemini', status: 'failure', defaultModel: 'gemini-pro' } +] + +const positions = calculateNodePositions(modelData) + const initialNodes: Node[] = [ { id: 'service', type: 'default', - position: { x: 50, y: 100 }, + position: { x: 50, y: 200 }, data: { label: } }, - { - id: 'openai', + ...modelData.map((model) => ({ + id: model.id, type: 'default', - position: { x: 400, y: 50 }, + position: positions[model.id], data: { - label: + label: } - }, - { - id: 'anthropic', - type: 'default', - position: { x: 400, y: 200 }, - data: { - label: - } - }, - { - id: 'gemini', - type: 'default', - position: { x: 400, y: 350 }, - data: { - label: - } - }, + })), { id: 'openai-keys', type: 'default', - position: { x: 750, y: 50 }, + position: positions['openai-keys'], data: { - label: + label: ( + ({ + status: i < 8 ? 'success' : 'failure', + keyID: `key${i + 1}` + }))} + /> + ) } }, { id: 'anthropic-keys', type: 'default', - position: { x: 750, y: 200 }, + position: positions['anthropic-keys'], data: { - label: + label: ( + ({ + status: 'success', + keyID: `key${i + 1}` + }))} + /> + ) } }, { id: 'gemini-keys', type: 'default', - position: { x: 750, y: 350 }, + position: positions['gemini-keys'], data: { - label: + label: ( + ({ + status: 'failure', + keyID: `key${i + 1}` + }))} + /> + ) } } ] const initialEdges: Edge[] = [ - { - id: 'service-openai', + ...modelData.map((model) => ({ + id: `service-${model.id}`, source: 'service', - target: 'openai', + target: model.id, animated: true, label: 'apis', style: { stroke: '#3d46f2', cursor: 'pointer' } - }, - { - id: 'service-anthropic', - source: 'service', - target: 'anthropic', - animated: true, - label: 'apis', - style: { stroke: '#3d46f2', cursor: 'pointer' } - }, - { - id: 'service-gemini', - source: 'service', - target: 'gemini', - animated: true, - label: 'apis', - style: { stroke: '#3d46f2', cursor: 'pointer' } - }, - { - id: 'openai-keys', - source: 'openai', - target: 'openai-keys', + })), + ...modelData.map((model) => ({ + id: `${model.id}-keys`, + source: model.id, + target: `${model.id}-keys`, animated: true, style: { stroke: '#3d46f2' } - }, - { - id: 'anthropic-keys', - source: 'anthropic', - target: 'anthropic-keys', - animated: true, - style: { stroke: '#3d46f2' } - }, - { - id: 'gemini-keys', - source: 'gemini', - target: 'gemini-keys', - animated: true, - style: { stroke: '#3d46f2' } - } + })) ] const Playground: React.FC = () => {