plugin-ai-api 1.0.15 → 1.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/286.01c0e3c5fff3cccb.js +10 -0
- package/dist/client/302.fc3a3491b4ec2dfd.js +10 -0
- package/dist/client/562.17a0a299d2e5152c.js +10 -0
- package/dist/client/757.a01403fb7a1bea01.js +10 -0
- package/dist/client/902.92e1daaf1ab16ebf.js +10 -0
- package/dist/client/97.72979a11a067a7c9.js +10 -0
- package/dist/client/index.js +1 -1
- package/dist/client-v2/302.d27fe4ea9b0b3bf5.js +10 -0
- package/dist/client-v2/562.fb2948ee6402de95.js +10 -0
- package/dist/client-v2/757.a117ce1cf7119cea.js +10 -0
- package/dist/client-v2/902.9054d990ddc223ac.js +10 -0
- package/dist/client-v2/952.94100128b7757f56.js +10 -0
- package/dist/client-v2/97.29c663318eebbd57.js +10 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/constants.js +36 -0
- package/dist/externalVersion.js +9 -10
- package/dist/locale/en-US.json +105 -10
- package/dist/locale/vi-VN.json +105 -0
- package/dist/locale/zh-CN.json +105 -10
- package/dist/server/billing.js +331 -0
- package/dist/server/collections/ai-api-config.js +18 -0
- package/dist/server/collections/ai-api-model-metadata.js +83 -0
- package/dist/server/collections/ai-api-model-prices.js +55 -0
- package/dist/server/collections/ai-api-usage-records.js +9 -0
- package/dist/server/collections/ai-api-user-quota-buckets.js +54 -0
- package/dist/server/collections/ai-api-user-quota-policies.js +62 -0
- package/dist/server/plugin.js +36 -3
- package/dist/server/resource/ai-api-config.js +25 -0
- package/dist/server/resource/ai-api-usage-monitor.js +86 -0
- package/dist/server/routes/agent-completions.js +62 -51
- package/dist/server/routes/auth.js +11 -1
- package/dist/server/routes/chat-completions.js +157 -6
- package/dist/server/routes/completions.js +20 -3
- package/dist/server/routes/models.js +78 -20
- package/dist/server/routes/router.js +108 -23
- package/dist/server/usage.js +19 -2
- package/dist/server/utils/app-observability.js +110 -0
- package/dist/server/utils/streaming.js +15 -1
- package/dist/server/validation.js +120 -0
- package/dist/swagger.js +32 -1
- package/package.json +1 -1
- package/src/client/components/AiApiRolePermissions.tsx +11 -169
- package/src/client/locale.ts +11 -21
- package/src/client/plugin.tsx +82 -48
- package/src/client-v2/__tests__/settings-registration.test.tsx +58 -0
- package/src/client-v2/components/AiApiRolePermissions.tsx +173 -0
- package/src/client-v2/locale.ts +21 -0
- package/src/client-v2/pages/GeneralPage.tsx +183 -0
- package/src/client-v2/pages/ModelMetadataPage.tsx +280 -0
- package/src/client-v2/pages/ModelPricingPage.tsx +285 -0
- package/src/client-v2/pages/RolePermissionsTab.tsx +14 -0
- package/src/client-v2/pages/UsagePage.tsx +248 -0
- package/src/client-v2/pages/UserQuotasPage.tsx +258 -0
- package/src/client-v2/pages/api.ts +16 -0
- package/src/client-v2/plugin.tsx +62 -4
- package/src/constants.ts +21 -0
- package/src/locale/en-US.json +105 -10
- package/src/locale/vi-VN.json +105 -0
- package/src/locale/zh-CN.json +105 -10
- package/src/server/__tests__/app-observability.test.ts +98 -0
- package/src/server/__tests__/billing-quota.test.ts +134 -0
- package/src/server/__tests__/billing.test.ts +33 -0
- package/src/server/__tests__/models.test.ts +74 -0
- package/src/server/__tests__/request-body.test.ts +310 -0
- package/src/server/__tests__/streaming-observability.test.ts +51 -0
- package/src/server/__tests__/usage-monitor.test.ts +63 -0
- package/src/server/__tests__/usage-route.test.ts +4 -0
- package/src/server/billing.ts +387 -0
- package/src/server/collections/ai-api-config.ts +69 -51
- package/src/server/collections/ai-api-model-metadata.ts +72 -0
- package/src/server/collections/ai-api-model-prices.ts +25 -0
- package/src/server/collections/ai-api-usage-records.ts +9 -0
- package/src/server/collections/ai-api-user-quota-buckets.ts +24 -0
- package/src/server/collections/ai-api-user-quota-policies.ts +32 -0
- package/src/server/plugin.ts +47 -5
- package/src/server/resource/ai-api-config.ts +105 -74
- package/src/server/resource/ai-api-usage-monitor.ts +74 -0
- package/src/server/routes/agent-completions.ts +77 -62
- package/src/server/routes/auth.ts +14 -1
- package/src/server/routes/chat-completions.ts +275 -6
- package/src/server/routes/completions.ts +27 -4
- package/src/server/routes/models.ts +290 -195
- package/src/server/routes/router.ts +152 -27
- package/src/server/usage.ts +19 -1
- package/src/server/utils/app-observability.ts +105 -0
- package/src/server/utils/streaming.ts +13 -1
- package/src/server/validation.ts +89 -0
- package/src/swagger.ts +38 -1
- package/dist/client/778.5c452944cb747975.js +0 -10
- package/dist/client/950.83390c5f1d5a97fb.js +0 -10
- package/dist/client-v2/950.42b30b5cc9e32b8f.js +0 -10
- package/src/client/AiApiConfigPage.tsx +0 -309
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
"use strict";(self.webpackChunkplugin_ai_api_client_v2=self.webpackChunkplugin_ai_api_client_v2||[]).push([["950"],{693:function(e,t,n){n.r(t),n.d(t,{AiApiConfigPage:function(){return y}});var a=n(155),r=n.n(a),l=n(59),o=n(485);function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,a=Array(t);n<t;n++)a[n]=e[n];return a}function c(e,t,n,a,r,l,o){try{var i=e[l](o),c=i.value}catch(e){n(e);return}i.done?t(c):Promise.resolve(c).then(a,r)}function u(e){return function(){var t=this,n=arguments;return new Promise(function(a,r){var l=e.apply(t,n);function o(e){c(l,a,r,o,i,"next",e)}function i(e){c(l,a,r,o,i,"throw",e)}o(void 0)})}}function s(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,a,r=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var l=[],o=!0,i=!1;try{for(r=r.call(e);!(o=(n=r.next()).done)&&(l.push(n.value),!t||l.length!==t);o=!0);}catch(e){i=!0,a=e}finally{try{o||null==r.return||r.return()}finally{if(i)throw a}}return l}}(e,t)||function(e,t){if(e){if("string"==typeof e)return i(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return i(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function m(e,t){var n,a,r,l={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:c(0)}),i(o,"throw",{value:c(1)}),i(o,"return",{value:c(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function c(i){return function(c){var u=[i,c];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(l=0)),l;)try{if(n=1,a&&(r=2&u[0]?a.return:u[0]?a.throw||((r=a.return)&&r.call(a),0):a.next)&&!(r=r.call(a,u[1])).done)return r;switch(a=0,r&&(u=[2&u[0],r.value]),u[0]){case 0:case 1:r=u;break;case 4:return l.label++,{value:u[1],done:!1};case 5:l.label++,a=u[1],u=[0];continue;case 7:u=l.ops.pop(),l.trys.pop();continue;default:if(!(r=(r=l.trys).length>0&&r[r.length-1])&&(6===u[0]||2===u[0])){l=0;continue}if(3===u[0]&&(!r||u[1]>r[0]&&u[1]<r[3])){l.label=u[1];break}if(6===u[0]&&l.label<r[1]){l.label=r[1],r=u;break}if(r&&l.label<r[2]){l.label=r[2],l.ops.push(u);break}r[2]&&l.ops.pop(),l.trys.pop();continue}u=t.call(e,l)}catch(e){u=[6,e],a=0}finally{n=r=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}var p=l.Typography.Title,d=l.Typography.Text,f=l.Typography.Paragraph;function y(){var e=(0,o.useApp)().apiClient,t=s(l.Form.useForm(),1)[0],n=s((0,a.useState)(!0),2),i=n[0],c=n[1],y=s((0,a.useState)(!1),2),v=y[0],h=y[1],b=s((0,a.useState)([]),2),g=b[0],E=b[1],A=s((0,a.useState)([]),2),S=A[0],w=A[1],I=s((0,a.useState)(""),2),L=I[0],k=I[1];(0,a.useEffect)(function(){C(),k("".concat(window.location.origin,"/api/ai-llm/v1"))},[]);var C=function(){return u(function(){var n,a,r,l,o,i,u;return m(this,function(s){switch(s.label){case 0:c(!0),s.label=1;case 1:return s.trys.push([1,5,6,7]),[4,e.request({url:"aiApiConfig:get"})];case 2:return(o=null==(l=s.sent())||null==(n=l.data)?void 0:n.data)&&t.setFieldsValue({mode:o.mode||"llm",defaultAiEmployee:o.defaultAiEmployee||void 0,defaultLlmService:o.defaultLlmService||void 0,enabledLlmServices:o.enabledLlmServices||[],rateLimitPerMinute:o.rateLimitPerMinute||60}),[4,e.request({url:"aiEmployees:list",params:{paginate:!1}})];case 3:return E(((null==(i=s.sent())||null==(a=i.data)?void 0:a.data)||[]).map(function(e){return{username:e.username,nickname:e.nickname||e.username}})),[4,e.request({url:"ai:listLLMServices"})];case 4:return w(((null==(u=s.sent())||null==(r=u.data)?void 0:r.data)||[]).map(function(e){return{name:e.name,title:e.title||e.name,provider:e.provider,enabled:!1!==e.enabled}})),[3,7];case 5:return console.error("Failed to load config:",s.sent()),[3,7];case 6:return c(!1),[7];case 7:return[2]}})})()};return i?r().createElement("div",{style:{display:"flex",justifyContent:"center",padding:60}},r().createElement(l.Spin,{size:"large"})):r().createElement("div",{style:{maxWidth:800,margin:"0 auto",padding:"24px 0"}},r().createElement(p,{level:3},"AI API Gateway Configuration"),r().createElement(f,{type:"secondary"},"Configure the OpenAI-compatible API endpoint. External applications can connect using the base URL and a NocoBase API key."),r().createElement(l.Card,{style:{marginBottom:24}},r().createElement(l.Alert,{type:"info",showIcon:!0,message:"API Endpoint",description:r().createElement(l.Space,{direction:"vertical",size:4},r().createElement(d,null,"Base URL:"," ",r().createElement(d,{code:!0,copyable:!0},L)),r().createElement(d,{type:"secondary"},"Use this as the base URL in any OpenAI-compatible client (Cursor, Continue.dev, n8n, etc.)")),style:{marginBottom:16}}),r().createElement(l.Alert,{type:"warning",showIcon:!0,message:"Authentication",description:r().createElement(d,null,"Clients must include a NocoBase API key as a Bearer token:",r().createElement("br",null),r().createElement(d,{code:!0},"Authorization: Bearer ","<your-nocobase-api-key>"),r().createElement("br",null),r().createElement(d,{type:"secondary"},"API keys can be created in Settings → API keys."))})),r().createElement(l.Card,{title:"Configuration"},r().createElement(l.Form,{form:t,layout:"vertical",onFinish:function(){return u(function(){var n;return m(this,function(a){switch(a.label){case 0:h(!0),a.label=1;case 1:return a.trys.push([1,3,4,5]),n=t.getFieldsValue(),[4,e.request({url:"aiApiConfig:save",method:"post",data:n})];case 2:return a.sent(),l.message.success("Configuration saved"),[3,5];case 3:return a.sent(),l.message.error("Failed to save configuration"),[3,5];case 4:return h(!1),[7];case 5:return[2]}})})()},initialValues:{mode:"llm"}},r().createElement(l.Form.Item,{name:"mode",label:"API Mode",tooltip:"LLM Proxy: Direct access to the LLM model. Agent: Full AI Employee with tools, knowledge base, and agent capabilities."},r().createElement(l.Radio.Group,null,r().createElement(l.Radio.Button,{value:"llm"},"LLM Proxy"),r().createElement(l.Radio.Button,{value:"agent"},"AI Employee Agent"))),r().createElement(l.Form.Item,{name:"defaultAiEmployee",label:"Default AI Employee",tooltip:"The AI Employee whose system prompt will be injected into chat completions (when client doesn't provide a system message)"},r().createElement(l.Select,{allowClear:!0,placeholder:"Select an AI Employee (optional)",options:g.map(function(e){return{label:"".concat(e.nickname," (").concat(e.username,")"),value:e.username}})})),r().createElement(l.Form.Item,{name:"defaultLlmService",label:"Default LLM Service",tooltip:"The LLM service used when clients send only a model name (e.g. 'gpt-4o') without a service prefix. This is the main service that powers the API.",rules:[{required:!0,message:"Please select a default LLM service"}]},r().createElement(l.Select,{allowClear:!0,placeholder:"Select an LLM Service",options:S.map(function(e){return{label:"".concat(e.title," (").concat(e.provider,")"),value:e.name}})})),r().createElement(l.Form.Item,{name:"enabledLlmServices",label:"Enabled LLM Services",tooltip:"Only these services will be exposed via the API. Leave empty to expose all enabled services."},r().createElement(l.Select,{mode:"multiple",allowClear:!0,placeholder:"All enabled services (default)",options:S.map(function(e){return{label:"".concat(e.title," (").concat(e.provider,")"),value:e.name}})})),r().createElement(l.Form.Item,{name:"rateLimitPerMinute",label:"Rate Limit (requests/minute)",tooltip:"Maximum API requests per user per minute. Set 0 for unlimited."},r().createElement(l.InputNumber,{min:0,max:1e4,style:{width:200}})),r().createElement(l.Form.Item,null,r().createElement(l.Button,{type:"primary",htmlType:"submit",loading:v},"Save Configuration")))),r().createElement(l.Card,{title:"Quick Start",style:{marginTop:24}},r().createElement(p,{level:5},"cURL Example"),r().createElement(f,null,r().createElement("pre",{style:{background:"#1a1a2e",color:"#e0e0e0",padding:16,borderRadius:8,fontSize:13,overflow:"auto"}},"curl ".concat(L,'/chat/completions \\\n -H "Authorization: Bearer <your-api-key>" \\\n -H "Content-Type: application/json" \\\n -d \'{\n "model": "<service-name>/<model-id>",\n "messages": [\n {"role": "user", "content": "Hello!"}\n ]\n }\''))),r().createElement(p,{level:5},"Python (OpenAI SDK)"),r().createElement(f,null,r().createElement("pre",{style:{background:"#1a1a2e",color:"#e0e0e0",padding:16,borderRadius:8,fontSize:13,overflow:"auto"}},'from openai import OpenAI\n\nclient = OpenAI(\n base_url="'.concat(L,'",\n api_key="<your-nocobase-api-key>"\n)\n\nresponse = client.chat.completions.create(\n model="<service-name>/<model-id>",\n messages=[{"role": "user", "content": "Hello!"}]\n)'))),r().createElement(p,{level:5},"List Available Models"),r().createElement(f,null,r().createElement("pre",{style:{background:"#1a1a2e",color:"#e0e0e0",padding:16,borderRadius:8,fontSize:13,overflow:"auto"}},"curl ".concat(L,'/models \\\n -H "Authorization: Bearer <your-api-key>"')))))}t.default=y}}]);
|
|
@@ -1,309 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import React, { useEffect, useState } from 'react';
|
|
11
|
-
import { Card, Form, Select, InputNumber, Button, message, Typography, Space, Alert, Divider, Spin, Radio } from 'antd';
|
|
12
|
-
import { useApp } from '@nocobase/client-v2';
|
|
13
|
-
|
|
14
|
-
const { Title, Text, Paragraph } = Typography;
|
|
15
|
-
|
|
16
|
-
interface AiApiConfig {
|
|
17
|
-
mode: string;
|
|
18
|
-
defaultAiEmployee: string;
|
|
19
|
-
defaultLlmService: string;
|
|
20
|
-
enabledLlmServices: string[];
|
|
21
|
-
rateLimitPerMinute: number;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
interface AiEmployee {
|
|
25
|
-
username: string;
|
|
26
|
-
nickname: string;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
interface LlmService {
|
|
30
|
-
name: string;
|
|
31
|
-
title: string;
|
|
32
|
-
provider: string;
|
|
33
|
-
enabled: boolean;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function AiApiConfigPage() {
|
|
37
|
-
const api = useApp().apiClient;
|
|
38
|
-
const [form] = Form.useForm();
|
|
39
|
-
const [loading, setLoading] = useState(true);
|
|
40
|
-
const [saving, setSaving] = useState(false);
|
|
41
|
-
const [employees, setEmployees] = useState<AiEmployee[]>([]);
|
|
42
|
-
const [services, setServices] = useState<LlmService[]>([]);
|
|
43
|
-
const [baseUrl, setBaseUrl] = useState('');
|
|
44
|
-
|
|
45
|
-
useEffect(() => {
|
|
46
|
-
loadData();
|
|
47
|
-
setBaseUrl(`${window.location.origin}/api/ai-llm/v1`);
|
|
48
|
-
}, []);
|
|
49
|
-
|
|
50
|
-
const loadData = async () => {
|
|
51
|
-
setLoading(true);
|
|
52
|
-
try {
|
|
53
|
-
// Load config
|
|
54
|
-
const configRes = await api.request({ url: 'aiApiConfig:get' });
|
|
55
|
-
const config = configRes?.data?.data;
|
|
56
|
-
if (config) {
|
|
57
|
-
form.setFieldsValue({
|
|
58
|
-
mode: config.mode || 'llm',
|
|
59
|
-
defaultAiEmployee: config.defaultAiEmployee || undefined,
|
|
60
|
-
defaultLlmService: config.defaultLlmService || undefined,
|
|
61
|
-
enabledLlmServices: config.enabledLlmServices || [],
|
|
62
|
-
rateLimitPerMinute: config.rateLimitPerMinute || 60,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Load AI employees
|
|
67
|
-
const empRes = await api.request({
|
|
68
|
-
url: 'aiEmployees:list',
|
|
69
|
-
params: { paginate: false },
|
|
70
|
-
});
|
|
71
|
-
setEmployees(
|
|
72
|
-
(empRes?.data?.data || []).map((e: any) => ({
|
|
73
|
-
username: e.username,
|
|
74
|
-
nickname: e.nickname || e.username,
|
|
75
|
-
})),
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
// Load LLM services
|
|
79
|
-
const svcRes = await api.request({
|
|
80
|
-
url: 'ai:listLLMServices',
|
|
81
|
-
});
|
|
82
|
-
setServices(
|
|
83
|
-
(svcRes?.data?.data || []).map((s: any) => ({
|
|
84
|
-
name: s.name,
|
|
85
|
-
title: s.title || s.name,
|
|
86
|
-
provider: s.provider,
|
|
87
|
-
enabled: s.enabled !== false,
|
|
88
|
-
})),
|
|
89
|
-
);
|
|
90
|
-
} catch (err) {
|
|
91
|
-
console.error('Failed to load config:', err);
|
|
92
|
-
} finally {
|
|
93
|
-
setLoading(false);
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const handleSave = async () => {
|
|
98
|
-
setSaving(true);
|
|
99
|
-
try {
|
|
100
|
-
const values = form.getFieldsValue();
|
|
101
|
-
await api.request({
|
|
102
|
-
url: 'aiApiConfig:save',
|
|
103
|
-
method: 'post',
|
|
104
|
-
data: values,
|
|
105
|
-
});
|
|
106
|
-
message.success('Configuration saved');
|
|
107
|
-
} catch (err) {
|
|
108
|
-
message.error('Failed to save configuration');
|
|
109
|
-
} finally {
|
|
110
|
-
setSaving(false);
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
if (loading) {
|
|
115
|
-
return (
|
|
116
|
-
<div style={{ display: 'flex', justifyContent: 'center', padding: 60 }}>
|
|
117
|
-
<Spin size="large" />
|
|
118
|
-
</div>
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return (
|
|
123
|
-
<div style={{ maxWidth: 800, margin: '0 auto', padding: '24px 0' }}>
|
|
124
|
-
<Title level={3}>AI API Gateway Configuration</Title>
|
|
125
|
-
<Paragraph type="secondary">
|
|
126
|
-
Configure the OpenAI-compatible API endpoint. External applications can connect using the base URL and a
|
|
127
|
-
NocoBase API key.
|
|
128
|
-
</Paragraph>
|
|
129
|
-
|
|
130
|
-
<Card style={{ marginBottom: 24 }}>
|
|
131
|
-
<Alert
|
|
132
|
-
type="info"
|
|
133
|
-
showIcon
|
|
134
|
-
message="API Endpoint"
|
|
135
|
-
description={
|
|
136
|
-
<Space direction="vertical" size={4}>
|
|
137
|
-
<Text>
|
|
138
|
-
Base URL:{' '}
|
|
139
|
-
<Text code copyable>
|
|
140
|
-
{baseUrl}
|
|
141
|
-
</Text>
|
|
142
|
-
</Text>
|
|
143
|
-
<Text type="secondary">
|
|
144
|
-
Use this as the base URL in any OpenAI-compatible client (Cursor, Continue.dev, n8n, etc.)
|
|
145
|
-
</Text>
|
|
146
|
-
</Space>
|
|
147
|
-
}
|
|
148
|
-
style={{ marginBottom: 16 }}
|
|
149
|
-
/>
|
|
150
|
-
|
|
151
|
-
<Alert
|
|
152
|
-
type="warning"
|
|
153
|
-
showIcon
|
|
154
|
-
message="Authentication"
|
|
155
|
-
description={
|
|
156
|
-
<Text>
|
|
157
|
-
Clients must include a NocoBase API key as a Bearer token:
|
|
158
|
-
<br />
|
|
159
|
-
<Text code>Authorization: Bearer {'<your-nocobase-api-key>'}</Text>
|
|
160
|
-
<br />
|
|
161
|
-
<Text type="secondary">API keys can be created in Settings → API keys.</Text>
|
|
162
|
-
</Text>
|
|
163
|
-
}
|
|
164
|
-
/>
|
|
165
|
-
</Card>
|
|
166
|
-
|
|
167
|
-
<Card title="Configuration">
|
|
168
|
-
<Form form={form} layout="vertical" onFinish={handleSave} initialValues={{ mode: 'llm' }}>
|
|
169
|
-
<Form.Item
|
|
170
|
-
name="mode"
|
|
171
|
-
label="API Mode"
|
|
172
|
-
tooltip="LLM Proxy: Direct access to the LLM model. Agent: Full AI Employee with tools, knowledge base, and agent capabilities."
|
|
173
|
-
>
|
|
174
|
-
<Radio.Group>
|
|
175
|
-
<Radio.Button value="llm">LLM Proxy</Radio.Button>
|
|
176
|
-
<Radio.Button value="agent">AI Employee Agent</Radio.Button>
|
|
177
|
-
</Radio.Group>
|
|
178
|
-
</Form.Item>
|
|
179
|
-
|
|
180
|
-
<Form.Item
|
|
181
|
-
name="defaultAiEmployee"
|
|
182
|
-
label="Default AI Employee"
|
|
183
|
-
tooltip="The AI Employee whose system prompt will be injected into chat completions (when client doesn't provide a system message)"
|
|
184
|
-
>
|
|
185
|
-
<Select
|
|
186
|
-
allowClear
|
|
187
|
-
placeholder="Select an AI Employee (optional)"
|
|
188
|
-
options={employees.map((e) => ({
|
|
189
|
-
label: `${e.nickname} (${e.username})`,
|
|
190
|
-
value: e.username,
|
|
191
|
-
}))}
|
|
192
|
-
/>
|
|
193
|
-
</Form.Item>
|
|
194
|
-
|
|
195
|
-
<Form.Item
|
|
196
|
-
name="defaultLlmService"
|
|
197
|
-
label="Default LLM Service"
|
|
198
|
-
tooltip="The LLM service used when clients send only a model name (e.g. 'gpt-4o') without a service prefix. This is the main service that powers the API."
|
|
199
|
-
rules={[{ required: true, message: 'Please select a default LLM service' }]}
|
|
200
|
-
>
|
|
201
|
-
<Select
|
|
202
|
-
allowClear
|
|
203
|
-
placeholder="Select an LLM Service"
|
|
204
|
-
options={services.map((s) => ({
|
|
205
|
-
label: `${s.title} (${s.provider})`,
|
|
206
|
-
value: s.name,
|
|
207
|
-
}))}
|
|
208
|
-
/>
|
|
209
|
-
</Form.Item>
|
|
210
|
-
|
|
211
|
-
<Form.Item
|
|
212
|
-
name="enabledLlmServices"
|
|
213
|
-
label="Enabled LLM Services"
|
|
214
|
-
tooltip="Only these services will be exposed via the API. Leave empty to expose all enabled services."
|
|
215
|
-
>
|
|
216
|
-
<Select
|
|
217
|
-
mode="multiple"
|
|
218
|
-
allowClear
|
|
219
|
-
placeholder="All enabled services (default)"
|
|
220
|
-
options={services.map((s) => ({
|
|
221
|
-
label: `${s.title} (${s.provider})`,
|
|
222
|
-
value: s.name,
|
|
223
|
-
}))}
|
|
224
|
-
/>
|
|
225
|
-
</Form.Item>
|
|
226
|
-
|
|
227
|
-
<Form.Item
|
|
228
|
-
name="rateLimitPerMinute"
|
|
229
|
-
label="Rate Limit (requests/minute)"
|
|
230
|
-
tooltip="Maximum API requests per user per minute. Set 0 for unlimited."
|
|
231
|
-
>
|
|
232
|
-
<InputNumber min={0} max={10000} style={{ width: 200 }} />
|
|
233
|
-
</Form.Item>
|
|
234
|
-
|
|
235
|
-
<Form.Item>
|
|
236
|
-
<Button type="primary" htmlType="submit" loading={saving}>
|
|
237
|
-
Save Configuration
|
|
238
|
-
</Button>
|
|
239
|
-
</Form.Item>
|
|
240
|
-
</Form>
|
|
241
|
-
</Card>
|
|
242
|
-
|
|
243
|
-
<Card title="Quick Start" style={{ marginTop: 24 }}>
|
|
244
|
-
<Title level={5}>cURL Example</Title>
|
|
245
|
-
<Paragraph>
|
|
246
|
-
<pre
|
|
247
|
-
style={{
|
|
248
|
-
background: '#1a1a2e',
|
|
249
|
-
color: '#e0e0e0',
|
|
250
|
-
padding: 16,
|
|
251
|
-
borderRadius: 8,
|
|
252
|
-
fontSize: 13,
|
|
253
|
-
overflow: 'auto',
|
|
254
|
-
}}
|
|
255
|
-
>{`curl ${baseUrl}/chat/completions \\
|
|
256
|
-
-H "Authorization: Bearer <your-api-key>" \\
|
|
257
|
-
-H "Content-Type: application/json" \\
|
|
258
|
-
-d '{
|
|
259
|
-
"model": "<service-name>/<model-id>",
|
|
260
|
-
"messages": [
|
|
261
|
-
{"role": "user", "content": "Hello!"}
|
|
262
|
-
]
|
|
263
|
-
}'`}</pre>
|
|
264
|
-
</Paragraph>
|
|
265
|
-
|
|
266
|
-
<Title level={5}>Python (OpenAI SDK)</Title>
|
|
267
|
-
<Paragraph>
|
|
268
|
-
<pre
|
|
269
|
-
style={{
|
|
270
|
-
background: '#1a1a2e',
|
|
271
|
-
color: '#e0e0e0',
|
|
272
|
-
padding: 16,
|
|
273
|
-
borderRadius: 8,
|
|
274
|
-
fontSize: 13,
|
|
275
|
-
overflow: 'auto',
|
|
276
|
-
}}
|
|
277
|
-
>{`from openai import OpenAI
|
|
278
|
-
|
|
279
|
-
client = OpenAI(
|
|
280
|
-
base_url="${baseUrl}",
|
|
281
|
-
api_key="<your-nocobase-api-key>"
|
|
282
|
-
)
|
|
283
|
-
|
|
284
|
-
response = client.chat.completions.create(
|
|
285
|
-
model="<service-name>/<model-id>",
|
|
286
|
-
messages=[{"role": "user", "content": "Hello!"}]
|
|
287
|
-
)`}</pre>
|
|
288
|
-
</Paragraph>
|
|
289
|
-
|
|
290
|
-
<Title level={5}>List Available Models</Title>
|
|
291
|
-
<Paragraph>
|
|
292
|
-
<pre
|
|
293
|
-
style={{
|
|
294
|
-
background: '#1a1a2e',
|
|
295
|
-
color: '#e0e0e0',
|
|
296
|
-
padding: 16,
|
|
297
|
-
borderRadius: 8,
|
|
298
|
-
fontSize: 13,
|
|
299
|
-
overflow: 'auto',
|
|
300
|
-
}}
|
|
301
|
-
>{`curl ${baseUrl}/models \\
|
|
302
|
-
-H "Authorization: Bearer <your-api-key>"`}</pre>
|
|
303
|
-
</Paragraph>
|
|
304
|
-
</Card>
|
|
305
|
-
</div>
|
|
306
|
-
);
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
export default AiApiConfigPage;
|