|
| 1 | +import get from 'lodash/get'; |
| 2 | +import isEmpty from 'lodash/isEmpty'; |
| 3 | +import React from 'react'; |
| 4 | +import { Dataset } from '../Evaluator/types'; |
| 5 | +import { Col, Flex, Modal, Row, Space, Table, Tag, Typography } from 'antd'; |
| 6 | +import ExampleModal from './ExampleModal'; |
| 7 | +import { QuestionSolution } from '../DataGenerator/types'; |
| 8 | +import styled from 'styled-components'; |
| 9 | + |
| 10 | +const { Text } = Typography; |
| 11 | + |
| 12 | +interface Props { |
| 13 | + dataset: Dataset; |
| 14 | +} |
| 15 | + |
| 16 | +const StyledTable = styled(Table)` |
| 17 | + font-family: Roboto, -apple-system, 'Segoe UI', sans-serif; |
| 18 | + color: #5a656d; |
| 19 | + .ant-table-thead > tr > th { |
| 20 | + color: #5a656d; |
| 21 | + border-bottom: 1px solid #eaebec; |
| 22 | + font-weight: 500; |
| 23 | + text-align: left; |
| 24 | + // background: #ffffff; |
| 25 | + border-bottom: 1px solid #eaebec; |
| 26 | + transition: background 0.3s ease; |
| 27 | + } |
| 28 | + .ant-table-row { |
| 29 | + cursor: pointer; |
| 30 | + } |
| 31 | + .ant-table-row > td.ant-table-cell { |
| 32 | + padding: 8px; |
| 33 | + padding-left: 16px; |
| 34 | + font-size: 13px; |
| 35 | + font-family: Roboto, -apple-system, 'Segoe UI', sans-serif; |
| 36 | + color: #5a656d; |
| 37 | + .ant-typography { |
| 38 | + font-size: 13px; |
| 39 | + font-family: Roboto, -apple-system, 'Segoe UI', sans-serif; |
| 40 | + } |
| 41 | + } |
| 42 | +`; |
| 43 | + |
| 44 | +const StyledTitle = styled.div` |
| 45 | + margin-bottom: 4px; |
| 46 | + font-family: Roboto, -apple-system, 'Segoe UI', sans-serif; |
| 47 | + font-size: 16px; |
| 48 | + font-weight: 500; |
| 49 | + margin-left: 4px; |
| 50 | +
|
| 51 | +`; |
| 52 | + |
| 53 | +const Container = styled.div` |
| 54 | + padding: 16px; |
| 55 | + background-color: #ffffff; |
| 56 | +`; |
| 57 | + |
| 58 | +export const TagsContainer = styled.div` |
| 59 | + min-height: 30px; |
| 60 | + display: block; |
| 61 | + margin-bottom: 4px; |
| 62 | + margin-top: 4px; |
| 63 | + .ant-tag { |
| 64 | + max-width: 150px; |
| 65 | + } |
| 66 | + .tag-title { |
| 67 | + overflow: hidden; |
| 68 | + white-space: nowrap; |
| 69 | + text-overflow: ellipsis; |
| 70 | + } |
| 71 | +`; |
| 72 | + |
| 73 | + |
| 74 | +const ConfigurationTab: React.FC<Props> = ({ dataset }) => { |
| 75 | + const topics = get(dataset, 'topics', []); |
| 76 | + |
| 77 | + const exampleColummns = [ |
| 78 | + { |
| 79 | + title: 'Prompts', |
| 80 | + dataIndex: 'prompts', |
| 81 | + ellipsis: true, |
| 82 | + render: (_text: QuestionSolution, record: QuestionSolution) => <>{record.question}</> |
| 83 | + }, |
| 84 | + { |
| 85 | + title: 'Completions', |
| 86 | + dataIndex: 'completions', |
| 87 | + ellipsis: true, |
| 88 | + render: (_text: QuestionSolution, record: QuestionSolution) => <>{record.solution}</> |
| 89 | + }, |
| 90 | + ] |
| 91 | + |
| 92 | + const parameterColummns = [ |
| 93 | + { |
| 94 | + title: 'Temperature', |
| 95 | + dataIndex: 'temperature', |
| 96 | + ellipsis: true, |
| 97 | + render: (temperature: number) => <>{temperature}</> |
| 98 | + }, |
| 99 | + { |
| 100 | + title: 'Top K', |
| 101 | + dataIndex: 'top_k', |
| 102 | + ellipsis: true, |
| 103 | + render: (top_k: number) => <>{top_k}</> |
| 104 | + }, |
| 105 | + { |
| 106 | + title: 'Top P', |
| 107 | + dataIndex: 'top_p', |
| 108 | + ellipsis: true, |
| 109 | + render: (top_p: number) => <>{top_p}</> |
| 110 | + }, |
| 111 | + |
| 112 | + ]; |
| 113 | + console.log('topics:', topics); |
| 114 | + console.log('dataset:', dataset); |
| 115 | + console.log('examples:', dataset.examples); |
| 116 | + |
| 117 | + return ( |
| 118 | + <Container> |
| 119 | + <Row style={{ marginBottom: '16px', marginTop: '8px' }}> |
| 120 | + <Col sm={24}> |
| 121 | + <Flex vertical> |
| 122 | + <StyledTitle>Custom Prompt</StyledTitle> |
| 123 | + <Text copyable={{ |
| 124 | + text: dataset?.custom_prompt, |
| 125 | + tooltips: ['Copy Prompt', 'Copied!'], |
| 126 | + }}> |
| 127 | + {dataset?.custom_prompt} |
| 128 | + </Text> |
| 129 | + </Flex> |
| 130 | + </Col> |
| 131 | + </Row> |
| 132 | + {!isEmpty(topics) && |
| 133 | + <Row style={{ marginTop: '8px', marginBottom: '8px' }}> |
| 134 | + <Col sm={24}> |
| 135 | + <Flex vertical> |
| 136 | + <StyledTitle>Seed Instructions</StyledTitle> |
| 137 | + <TagsContainer> |
| 138 | + <Space size={[0, 'middle']} wrap> |
| 139 | + {topics.map((tag: string) => ( |
| 140 | + <Tag key={tag}> |
| 141 | + <div className="tag-title" title={tag}> |
| 142 | + {tag} |
| 143 | + </div> |
| 144 | + </Tag> |
| 145 | + ))} |
| 146 | + </Space> |
| 147 | + </TagsContainer> |
| 148 | + </Flex> |
| 149 | + </Col> |
| 150 | + </Row>} |
| 151 | + <Row style={{ marginTop: '16px', marginBottom: '8px' }}> |
| 152 | + <Col sm={24}> |
| 153 | + <Flex vertical> |
| 154 | + <StyledTitle>Examples</StyledTitle> |
| 155 | + <StyledTable |
| 156 | + bordered |
| 157 | + columns={exampleColummns} |
| 158 | + dataSource={dataset.examples || []} |
| 159 | + pagination={false} |
| 160 | + onRow={(record: { question: string, solution: string}) => ({ |
| 161 | + onClick: () => Modal.info({ |
| 162 | + title: 'View Details', |
| 163 | + content: <ExampleModal {...record} />, |
| 164 | + icon: undefined, |
| 165 | + maskClosable: false, |
| 166 | + width: 1000 |
| 167 | + }) |
| 168 | + })} |
| 169 | + rowKey={(_record, index) => `summary-examples-table-${index}`} |
| 170 | + /> |
| 171 | + </Flex> |
| 172 | + </Col> |
| 173 | + </Row> |
| 174 | + <Row style={{ marginTop: '16px' }}> |
| 175 | + <Col sm={24}> |
| 176 | + <Flex vertical> |
| 177 | + <StyledTitle>Parameters</StyledTitle> |
| 178 | + <StyledTable |
| 179 | + bordered |
| 180 | + columns={parameterColummns} |
| 181 | + dataSource={[dataset?.model_parameters]} |
| 182 | + pagination={false} |
| 183 | + rowKey={(_record, index) => `parameters-table-${index}`} |
| 184 | + /> |
| 185 | + </Flex> |
| 186 | + </Col> |
| 187 | + </Row> |
| 188 | + </Container> |
| 189 | + |
| 190 | + ); |
| 191 | +}; |
| 192 | + |
| 193 | +export default ConfigurationTab; |
| 194 | + |
| 195 | + |
0 commit comments