Skip to content

Commit

Permalink
fix: Perform minor tweak to AI console pages
Browse files Browse the repository at this point in the history
  • Loading branch information
CH3CHO committed Dec 31, 2024
1 parent a783f45 commit 563e3b2
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 194 deletions.
47 changes: 21 additions & 26 deletions frontend/src/locales/en-US/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,33 +67,30 @@
},
"consumer": {
"columns": {
"name": "consumer name",
"credentialTypes": "authentication method",
"action": "action"
"name": "Consumer Name",
"credentialTypes": "Auth Methods",
"action": "Action"
},
"create": "create",
"edit": "edit",
"create": "Create Consumer",
"edit": "Edit Consumer",
"deleteConfirmation": "Are you sure you want to delete < 1 > {{currentConsumerName}} </1 >?",
"consumerForm": {
"name": "name",
"name": "Name",
"namePlaceholder": "Please enter a consumer name",
"nameRequired": "Please enter a consumer name",
"pleaseEnter":"please enter",
"pleaseSelect":"please select"
"nameRequired": "Please enter a consumer name"
},
"selectBEARER": "Authorization: Bearer ${value}",
"selectHEADER": "Custom HTTP Header",
"selectQUERY": "query parameters",
"tokenSource":"Token source",
"authenticationToken":"Auth token",
"underDevelopment":"Under development, stay tuned.",
"randomGeneration":"random generation",
"headerName":"Header name",
"paramsName":"parameter name",
"selectQUERY": "Query parameter",
"tokenSource": "Token Source",
"authToken": "Auth Token",
"underDevelopment": "Under development, stay tuned.",
"randomGeneration": "Randomize",
"headerName": "Header name",
"paramName": "Parameter name",
"deleteSuccess": "delete success",
"deleteFailed": "delete failed",
"creaetSuccess": "creaet success",
"creatFailed": "creat failed",
"createFailed": "creat failed",
"editSuccess": "edit successfully",
"editFailed": "edit failed"
},
Expand Down Expand Up @@ -170,7 +167,7 @@
"name": "Name",
"serviceName": "Service Name",
"domain": "Domain name",
"agreement": "Agreement",
"protocol": "Agreement",
"modelPredicate": "Whether to enable model-based route matching rules",
"extra": "When enabled, if the request to the target service fails, the gateway will instead request a downgraded service.",
"modelPredicatePrefix": "model name matching rule",
Expand All @@ -190,7 +187,7 @@
"placeholder": {
"type": "Please select LLM vendor",
"name": "Please enter a name",
"agreement": "Please select a protocol",
"protocol": "Please select a protocol",
"serviceName": "Please enter a service name",
"tokens": "Please enter authentication token",
"domain": "Please enter domain name",
Expand All @@ -205,9 +202,9 @@
"modelPredicatePrefix": "Please enter the model name prefix required to match this route",
"Name": "Supports uppercase and lowercase letters, numbers, and dashes, and starts with a letter or number and does not end with a dash (-). Length should not exceed 63 characters."
},
"creatDomain": "Create a domain name",
"howtouse": "How to use",
"AirouterUse": "How to use AI routing"
"createDomain": "Create a domain name",
"howToUse": "How to use",
"aiRouteUsage": "How to use AI routing"
},
"create": "Create AI service provider",
"edit": "Edit AI service provider",
Expand All @@ -220,8 +217,6 @@
"addTargetServer": "Add",
"operation": "Operation",
"modelMatchingType": "Model matching type",
"pleaseSelect": "Please select",
"pleaseEnter": "Please enter",
"exactMatch": "exact match",
"prefixMatch": "Prefix Match",
"modelNames": "Model names",
Expand Down Expand Up @@ -640,4 +635,4 @@
"isRequired": "is required",
"invalidSchema": "Since schema information cannot be properly parsed, this plugin only supports YAML editing."
}
}
}
55 changes: 27 additions & 28 deletions frontend/src/locales/zh-CN/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,23 @@
"name": "消费者名称",
"namePlaceholder": "请输入消费者名称",
"nameRequired": "请输入消费者名称",
"pleaseEnter":"请输入",
"pleaseSelect":"请输入"
"tokenSourceRequired": "请选择令牌来源",
"authTokenRequired": "请输入认证令牌",
"headerNameRequired": "请输入Header名称",
"paramNameRequired": "请输入参数名称"
},
"selectBEARER": "Authorization: Bearer ${value}",
"selectHEADER": "自定义 HTTP Header",
"selectQUERY": "查询参数",
"tokenSource":"令牌来源",
"authenticationToken":"认证令牌",
"underDevelopment":"开发中,敬请期待",
"randomGeneration":"随机生成",
"headerName":"Header 名称",
"paramsName":"参数名称",
"tokenSource": "令牌来源",
"authToken": "认证令牌",
"underDevelopment": "开发中,敬请期待",
"randomGeneration": "随机生成",
"headerName": "Header 名称",
"paramName": "参数名称",
"deleteSuccess": "删除成功",
"deleteFailed": "删除失败",
"creaetSuccess": "创建成功",
"creatFailed": "创建失败",
"editSuccess": "编辑成功",
"createFailed": "创建失败",
"editFailed": "编辑失败"
},
"domain": {
Expand Down Expand Up @@ -170,7 +170,7 @@
"name": "名称",
"serviceName": "服务名称",
"domain": "域名",
"agreement": "协议",
"protocol": "协议",
"modelPredicate": "是否启用基于模型的路由匹配规则",
"extra": "启用后,若请求目标服务失败,网关会改为请求降级服务。",
"modelPredicatePrefix": "模型名称匹配规则",
Expand All @@ -190,7 +190,7 @@
"placeholder": {
"type": "请选择大模型供应商",
"name": "请输入名称",
"agreement": "请选择协议",
"protocol": "请选择协议",
"serviceName": "请输入服务名称",
"tokens": "请输入凭证",
"domain": "请输入域名",
Expand All @@ -203,11 +203,12 @@
},
"rules": {
"modelPredicatePrefix": "请输入匹配本路由所需的模型名称前缀",
"name": "支持大小写字母、数字和短划线,并以字母或数字开头,且不以短划线(-)结尾。长度不超过63个字符。"
"name": "支持大小写字母、数字和短划线,并以字母或数字开头,且不以短划线(-)结尾。长度不超过63个字符。",
"tokenRequired": "请输入凭证"
},
"creatDomain": "创建域名",
"howtouse": "使用方法",
"AirouterUse": "AI路由使用方法"
"createDomain": "创建域名",
"howToUse": "使用方法",
"aiRouteUsage": "AI路由使用方法"
},
"create": "创建AI服务提供者",
"edit": "编辑AI服务提供者",
Expand All @@ -219,16 +220,14 @@
"addTargetAIservice": "添加目标AI服务",
"addTargetServer": "添加",
"operation": "操作",
"modelMatchingType":"模型匹配方式",
"pleaseSelect":"请选择",
"pleaseEnter":"请输入",
"exactMatch":"精确匹配",
"prefixMatch":"前缀匹配",
"modelNames":"模型名称",
"serviceName":"服务名称",
"requestPercentage":"请求比例",
"targetModel":"目标模型",
"modelNameTips":"请求 body 中的 model 参数"
"modelMatchingType": "模型匹配方式",
"exactMatch": "精确匹配",
"prefixMatch": "前缀匹配",
"modelNames": "模型名称",
"serviceName": "服务名称",
"requestPercentage": "请求比例",
"targetModel": "目标模型",
"modelNameTips": "请求 body 中的 model 参数"
},
"plugins": {
"title": "策略配置",
Expand Down Expand Up @@ -640,4 +639,4 @@
"isRequired": "是必填的",
"invalidSchema": "由于 schema 信息无法正常解析,本插件只支持 YAML 编辑方式。"
}
}
}
49 changes: 11 additions & 38 deletions frontend/src/pages/ai/components/ProviderForm/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { ServiceSourceTypes } from '@/interfaces/service-source';
import { Form, Input, Select, Tabs, Button, Switch, InputNumber } from 'antd';
import TextArea from 'antd/lib/input/TextArea';
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
import { Button, Form, Input, InputNumber, Select, Switch } from 'antd';
import React, { forwardRef, useEffect, useImperativeHandle, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';

const providerTypeDisplayName = [
{ key: 'openai', label: 'llmProvider.providerTypes.openai' },
{ key: 'qwen', label: 'llmProvider.providerTypes.qwen' },
{ key: 'moonshot', label: 'llmProvider.providerTypes.moonshot' },
];

const agreementList = [
{ label: "Openai/v1", value: "openai/v1" },
const protocolList = [
{ label: "openai/v1", value: "openai/v1" },
];

const ProviderForm: React.FC = forwardRef((props: { value: any }, ref) => {
Expand Down Expand Up @@ -91,31 +89,6 @@ const ProviderForm: React.FC = forwardRef((props: { value: any }, ref) => {
},
}));


const getModelMapping = (text) => {
try {
const lines = text.split('\n');
const result = {};

lines.forEach(line => {
const [key, value] = line.split('=');
result[key.trim()] = value.trim();
});

return result;
} catch (err) {
return {}
}
};

// const getModelText = (text) => {
// try {
// return Object.entries(text).map(([key, value]) => `${key}=${value}`).join('\n');
// } catch (err) {
// return JSON.stringify(err)
// }
// };

return (
<Form
form={form}
Expand All @@ -134,6 +107,7 @@ const ProviderForm: React.FC = forwardRef((props: { value: any }, ref) => {
]}
>
<Select
disabled={props.value}
placeholder={t('llmProvider.providerForm.placeholder.type')}
>
{
Expand Down Expand Up @@ -174,16 +148,15 @@ const ProviderForm: React.FC = forwardRef((props: { value: any }, ref) => {

{/* 协议 */}
<Form.Item
label={t('llmProvider.providerForm.label.agreement')}
label={t('llmProvider.providerForm.label.protocol')}
required
name="protocol"
initialValue={agreementList[0].value}
initialValue={protocolList[0].value}
>
<Select
allowClear
placeholder={t('llmProvider.providerForm.rules.agreement')}
placeholder={t('llmProvider.providerForm.rules.protocol')}
>
{agreementList.map(item => (
{protocolList.map(item => (
<Select.Option value={item.value}>
{item.label}
</Select.Option>
Expand All @@ -208,6 +181,7 @@ const ProviderForm: React.FC = forwardRef((props: { value: any }, ref) => {
label={index === 0 ? t('llmProvider.columns.tokens') : ''}
required={false}
key={field.key}
style={{ marginBottom: '0.5rem' }}
>
<Form.Item
{...field}
Expand All @@ -216,14 +190,13 @@ const ProviderForm: React.FC = forwardRef((props: { value: any }, ref) => {
{
required: true,
whitespace: false,
message: "请输入认证令牌",
message: t('llmProvider.providerForm.rules.tokenRequired'),
},
]}
noStyle
>
<Input
style={{ width: '94%' }}
placeholder={t('llmProvider.providerForm.placeholder.tokens')}
/>
</Form.Item>
{/* 删除按钮 */}
Expand Down
18 changes: 3 additions & 15 deletions frontend/src/pages/ai/components/RouteForm/Components.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import React, { useState, useImperativeHandle } from "react";
import { Form, Button, Table, InputNumber } from 'antd';
import { RedoOutlined } from '@ant-design/icons';
import { history } from 'ice';
import { CustomComponentHandles } from '@/interfaces/service-source';
import { useTranslation } from 'react-i18next';
import { Button, Form } from 'antd';

// 刷新按钮
const RedoOutlinedBtn = (props) => {
Expand All @@ -27,19 +23,11 @@ const RedoOutlinedBtn = (props) => {
// 跳转按钮
const HistoryButton = (props) => {
const { text = '', path = '' } = props;

return (
<Button
type="link"
style={{ padding: 0 }}
onClick={() => history?.push(path)}
>
{text}
</Button>
<a href={path} target="_blank">{text}</a>
)
};

export {
RedoOutlinedBtn,
HistoryButton,
HistoryButton, RedoOutlinedBtn,
};
Loading

0 comments on commit 563e3b2

Please sign in to comment.