Skip to content

Commit

Permalink
feat: show modal info
Browse files Browse the repository at this point in the history
  • Loading branch information
kangfenmao committed Jul 11, 2024
1 parent 6899775 commit 77ed7e1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
33 changes: 28 additions & 5 deletions src/renderer/src/pages/settings/components/ModelListPopup.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { LoadingOutlined, MinusOutlined, PlusOutlined } from '@ant-design/icons'
import { LoadingOutlined, MinusOutlined, PlusOutlined, QuestionCircleOutlined } from '@ant-design/icons'
import { SYSTEM_MODELS } from '@renderer/config/models'
import { useProvider } from '@renderer/hooks/useProvider'
import { fetchModels } from '@renderer/services/api'
import { getModelLogo } from '@renderer/services/provider'
import { Model, Provider } from '@renderer/types'
import { getDefaultGroupName, runAsyncFunction } from '@renderer/utils'
import { Avatar, Button, Empty, Flex, Modal } from 'antd'
import { getDefaultGroupName, isFreeModel, runAsyncFunction } from '@renderer/utils'
import { Avatar, Button, Empty, Flex, Modal, Tag } from 'antd'
import Search from 'antd/es/input/Search'
import { groupBy, isEmpty, uniqBy } from 'lodash'
import { useEffect, useState } from 'react'
Expand Down Expand Up @@ -67,7 +67,9 @@ const PopupContainer: React.FC<Props> = ({ provider: _provider, resolve }) => {
// @ts-ignore name
name: model.name || model.id,
provider: _provider.id,
group: getDefaultGroupName(model.id)
group: getDefaultGroupName(model.id),
// @ts-ignore name
description: model?.description
}))
)
setLoading(false)
Expand Down Expand Up @@ -115,7 +117,15 @@ const PopupContainer: React.FC<Props> = ({ provider: _provider, resolve }) => {
<Avatar src={getModelLogo(model.id)} size={24}>
{model.name[0].toUpperCase()}
</Avatar>
<ListItemName>{model.name}</ListItemName>
<ListItemName>
{model.name}
{isFreeModel(model) && (
<Tag style={{ marginLeft: 10 }} color="green">
Free
</Tag>
)}
{!isEmpty(model.description) && <Question onClick={() => onShowModelInfo(model)} />}
</ListItemName>
</ListItemHeader>
{hasModel ? (
<Button type="default" onClick={() => onRemoveModel(model)} icon={<MinusOutlined />} />
Expand All @@ -133,6 +143,13 @@ const PopupContainer: React.FC<Props> = ({ provider: _provider, resolve }) => {
)
}

const onShowModelInfo = (model: Model) => {
window.modal.info({
title: model.name,
content: model.description
})
}

const SearchContainer = styled.div`
display: flex;
flex-direction: row;
Expand Down Expand Up @@ -189,6 +206,12 @@ const ModelHeaderTitle = styled.div`
margin-right: 10px;
`

const Question = styled(QuestionCircleOutlined)`
cursor: pointer;
margin: 0 10px;
color: #888;
`

export default class ModelListPopup {
static topviewId = 0
static hide() {
Expand Down
1 change: 1 addition & 0 deletions src/renderer/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export type Model = {
provider: string
name: string
group: string
description?: string
}

export type SystemAssistant = {
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { v4 as uuidv4 } from 'uuid'
import imageCompression from 'browser-image-compression'
import { Model } from '@renderer/types'

export const runAsyncFunction = async (fn: () => void) => {
await fn()
Expand Down Expand Up @@ -93,3 +94,7 @@ export function droppableReorder<T>(list: T[], startIndex: number, endIndex: num
export const firstLetter = (str?: string) => {
return str ? str[0] : ''
}

export function isFreeModel(model: Model) {
return (model.id + model.name).toLocaleLowerCase().includes('free')
}

0 comments on commit 77ed7e1

Please sign in to comment.