Skip to content

Commit

Permalink
ok
Browse files Browse the repository at this point in the history
  • Loading branch information
HUAHUAI23 committed Nov 8, 2024
1 parent d4a4695 commit e64d455
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
2 changes: 1 addition & 1 deletion frontend/providers/aiproxy/app/[lng]/(user)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function UserLayout({ children }: { children: React.ReactNode })

const handleI18nChange = useCallback(
(data: { currentLanguage: string }) => {
const currentLng = i18n.resolvedLanguage // 这里会获取最新的 resolvedLanguage
const currentLng = i18n.resolvedLanguage // get the latest resolvedLanguage
const newLng = data.currentLanguage

if (currentLng !== newLng) {
Expand Down
6 changes: 3 additions & 3 deletions frontend/providers/aiproxy/app/[lng]/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ div.rdp {
--rdp-cell-size: 40px;
--rdp-accent-color: black;
--rdp-background-color: #f4f6f8;
/* 深色主题颜色 */
/* black theme color */
--rdp-accent-color-dark: #3003e1;
--rdp-background-color-dark: #180270;
/* 聚焦元素的轮廓边框 */
/* focus element outline border */
--rdp-outline: 2px solid var(--rdp-accent-color);
/* 聚焦且选中元素的轮廓边框 */
/* focus and selected element outline border */
--rdp-outline-selected: 2px solid rgba(0, 0, 0, 0.75);
}
1 change: 0 additions & 1 deletion frontend/providers/aiproxy/components/user/KeyList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
Th,
Thead,
Tr,
Tooltip,
Modal,
ModalOverlay,
ModalContent,
Expand Down
17 changes: 7 additions & 10 deletions frontend/providers/aiproxy/components/user/ModelList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,27 @@ const getIdentifier = (modelName: string): ModelIdentifier => {
}

const sortModels = (models: string[]): string[] => {
// 使用 Map 进行分组
// group by identifier
const groupMap = new Map<string, string[]>()

// 分组
// group by identifier
models.forEach((model) => {
const identifier = getIdentifier(model)
// 特殊处理 gpt o1,将它们归为同一组 'openai'
// special handle gpt and o1, group them as 'openai'
const groupKey = identifier === 'gpt' || identifier === 'o' ? 'openai' : identifier
if (!groupMap.has(groupKey)) {
groupMap.set(groupKey, [])
}
groupMap.get(groupKey)?.push(model)
})

// 按照 identifier 排序并扁平化结果
// sort by identifier and flatten the result
return Array.from(groupMap.entries())
.sort((a, b) => a[0].localeCompare(b[0])) // 按 identifier 排序
.flatMap(([_, models]) => models.sort()) // 扁平化并保持每组内的排序
.sort((a, b) => a[0].localeCompare(b[0])) // sort by identifier
.flatMap(([_, models]) => models.sort()) // flatten and keep the order in each group
}

// 模型组件
const ModelComponent = ({ modelName }: { modelName: string }) => {
// 图标映射和标识符关系
const modelGroups = {
openai: {
icon: OpenAIIcon,
Expand Down Expand Up @@ -88,7 +86,7 @@ const ModelComponent = ({ modelName }: { modelName: string }) => {
}
}

// 获取模型图标
// get model icon
const getModelIcon = (modelName: string): StaticImageData => {
const identifier = getIdentifier(modelName)
const group = Object.values(modelGroups).find((group) => group.identifiers.includes(identifier))
Expand Down Expand Up @@ -150,7 +148,6 @@ const ModelComponent = ({ modelName }: { modelName: string }) => {
)
}

// 模型列表组件
const ModelList: React.FC = () => {
const { lng } = useI18n()
const { t } = useTranslationClientSide(lng, 'common')
Expand Down
8 changes: 4 additions & 4 deletions frontend/providers/aiproxy/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ export function middleware(req: NextRequest): NextResponse {
return NextResponse.next()
}

// 从路径中获取语言设置
// get language from pathname
let lng = req.nextUrl.pathname.split('/')[1]

// 如果路径中没有有效的语言代码,则使用默认语言
// if pathname does not contain valid language code, use fallback language
if (!languages.includes(lng)) {
lng = fallbackLng
}

// 处理根路径和语言路径的重定向
// handle root path and language path redirect
if (
req.nextUrl.pathname === '/' ||
languages.some((lang) => req.nextUrl.pathname === `/${lang}`)
Expand All @@ -49,7 +49,7 @@ export function middleware(req: NextRequest): NextResponse {
return NextResponse.redirect(newUrl)
}

// 处理其他需要添加语言前缀的路径
// handle other paths that need to add language prefix
if (!languages.some((loc) => req.nextUrl.pathname.startsWith(`/${loc}`))) {
const newUrl = new URL(`/${lng}${req.nextUrl.pathname}${req.nextUrl.search}`, req.url)
return NextResponse.redirect(newUrl)
Expand Down

0 comments on commit e64d455

Please sign in to comment.