mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-06 16:53:42 +08:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b59757434e | ||
|
|
f126d783c9 | ||
|
|
66e02a4bcf | ||
|
|
cf564f36fa | ||
|
|
43f8d5fd92 | ||
|
|
15d9a0c177 | ||
|
|
17125448cb |
2
.github/workflows/linux-release.yml
vendored
2
.github/workflows/linux-release.yml
vendored
@@ -24,7 +24,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
cd web
|
cd web
|
||||||
npm install
|
npm install
|
||||||
VITE_REACT_APP_VERSION=$(git describe --tags) npm run build
|
REACT_APP_VERSION=$(git describe --tags) npm run build
|
||||||
cd ..
|
cd ..
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v3
|
uses: actions/setup-go@v3
|
||||||
|
|||||||
2
.github/workflows/macos-release.yml
vendored
2
.github/workflows/macos-release.yml
vendored
@@ -24,7 +24,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
cd web
|
cd web
|
||||||
npm install
|
npm install
|
||||||
VITE_REACT_APP_VERSION=$(git describe --tags) npm run build
|
REACT_APP_VERSION=$(git describe --tags) npm run build
|
||||||
cd ..
|
cd ..
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v3
|
uses: actions/setup-go@v3
|
||||||
|
|||||||
2
.github/workflows/windows-release.yml
vendored
2
.github/workflows/windows-release.yml
vendored
@@ -27,7 +27,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
cd web
|
cd web
|
||||||
npm install
|
npm install
|
||||||
VITE_REACT_APP_VERSION=$(git describe --tags) npm run build
|
REACT_APP_VERSION=$(git describe --tags) npm run build
|
||||||
cd ..
|
cd ..
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v3
|
uses: actions/setup-go@v3
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ COPY ./web/package*.json ./
|
|||||||
RUN npm ci
|
RUN npm ci
|
||||||
COPY ./web .
|
COPY ./web .
|
||||||
COPY ./VERSION .
|
COPY ./VERSION .
|
||||||
RUN VITE_REACT_APP_VERSION=$(cat VERSION) npm run build
|
RUN REACT_APP_VERSION=$(cat VERSION) npm run build
|
||||||
|
|
||||||
# Go build stage
|
# Go build stage
|
||||||
FROM golang AS builder2
|
FROM golang AS builder2
|
||||||
|
|||||||
@@ -146,6 +146,20 @@ func testChannel(channel *model.Channel, request ChatRequest) error {
|
|||||||
req.Header.Set("X-Remote-Addr", ip)
|
req.Header.Set("X-Remote-Addr", ip)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
custom_http_headers := channel.CustomHttpHeaders
|
||||||
|
if custom_http_headers != "" {
|
||||||
|
var custom_http_headers_map map[string]string
|
||||||
|
err := json.Unmarshal([]byte(custom_http_headers), &custom_http_headers_map)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for key, value := range custom_http_headers_map {
|
||||||
|
req.Header.Set(key, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ func getDiscordUserInfoByCode(codeFromURLParamaters string, host string) (*Disco
|
|||||||
|
|
||||||
log.Print(resp.StatusCode)
|
log.Print(resp.StatusCode)
|
||||||
|
|
||||||
if err != nil || (resp.StatusCode != 200 && resp.StatusCode != 201) {
|
if err != nil || (resp.StatusCode != 200 && resp.StatusCode != 201 && resp.StatusCode != 204) {
|
||||||
// Print content
|
// Print content
|
||||||
stringBuff := new(bytes.Buffer)
|
stringBuff := new(bytes.Buffer)
|
||||||
stringBuff.ReadFrom(resp.Body)
|
stringBuff.ReadFrom(resp.Body)
|
||||||
|
|||||||
@@ -109,6 +109,20 @@ func relayImageHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode
|
|||||||
req.Header.Set("Content-Type", c.Request.Header.Get("Content-Type"))
|
req.Header.Set("Content-Type", c.Request.Header.Get("Content-Type"))
|
||||||
req.Header.Set("Accept", c.Request.Header.Get("Accept"))
|
req.Header.Set("Accept", c.Request.Header.Get("Accept"))
|
||||||
|
|
||||||
|
custom_http_headers := c.GetString("custom_http_headers")
|
||||||
|
if custom_http_headers != "" {
|
||||||
|
var custom_http_headers_map map[string]string
|
||||||
|
err := json.Unmarshal([]byte(custom_http_headers), &custom_http_headers_map)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return errorWrapper(err, "unmarshal_custom_http_headers_failed", http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
|
||||||
|
for key, value := range custom_http_headers_map {
|
||||||
|
req.Header.Set(key, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -320,6 +320,20 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
|
|||||||
req.Header.Set("X-Remote-Addr", ip)
|
req.Header.Set("X-Remote-Addr", ip)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
custom_http_headers := c.GetString("custom_http_headers")
|
||||||
|
if custom_http_headers != "" {
|
||||||
|
var custom_http_headers_map map[string]string
|
||||||
|
err := json.Unmarshal([]byte(custom_http_headers), &custom_http_headers_map)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return errorWrapper(err, "unmarshal_custom_http_headers_failed", http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
|
||||||
|
for key, value := range custom_http_headers_map {
|
||||||
|
req.Header.Set(key, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -330,7 +344,7 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
|
|||||||
if resp.Body != nil {
|
if resp.Body != nil {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
buf.ReadFrom(resp.Body)
|
buf.ReadFrom(resp.Body)
|
||||||
log.Printf("Error Channel (%s): %s", baseURL, buf.String())
|
log.Printf("Error Channel (%s) (%s): %s", baseURL, textRequest.Model, buf.String())
|
||||||
return errorWrapper(err, "request_failed", resp.StatusCode)
|
return errorWrapper(err, "request_failed", resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ WORKDIR /build
|
|||||||
COPY ./web/package*.json ./
|
COPY ./web/package*.json ./
|
||||||
RUN npm ci
|
RUN npm ci
|
||||||
COPY --from=translator /app .
|
COPY --from=translator /app .
|
||||||
RUN cd web && VITE_REACT_APP_VERSION=$(cat VERSION) npm run build
|
RUN cd web && REACT_APP_VERSION=$(cat VERSION) npm run build
|
||||||
|
|
||||||
# Go build stage
|
# Go build stage
|
||||||
FROM golang:1.20.5 AS goBuilder
|
FROM golang:1.20.5 AS goBuilder
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ func Distribute() func(c *gin.Context) {
|
|||||||
c.Set("channel_id", channel.Id)
|
c.Set("channel_id", channel.Id)
|
||||||
c.Set("channel_name", channel.Name)
|
c.Set("channel_name", channel.Name)
|
||||||
c.Set("model_mapping", channel.ModelMapping)
|
c.Set("model_mapping", channel.ModelMapping)
|
||||||
|
c.Set("custom_http_headers", channel.CustomHttpHeaders)
|
||||||
c.Set("enable_ip_randomization", channel.EnableIpRandomization)
|
c.Set("enable_ip_randomization", channel.EnableIpRandomization)
|
||||||
c.Request.Header.Set("Authorization", fmt.Sprintf("Bearer %s", channel.Key))
|
c.Request.Header.Set("Authorization", fmt.Sprintf("Bearer %s", channel.Key))
|
||||||
c.Set("base_url", channel.BaseURL)
|
c.Set("base_url", channel.BaseURL)
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ type Channel struct {
|
|||||||
ModelMapping string `json:"model_mapping" gorm:"type:varchar(1024);default:''"`
|
ModelMapping string `json:"model_mapping" gorm:"type:varchar(1024);default:''"`
|
||||||
|
|
||||||
// Additional fields, default value is false
|
// Additional fields, default value is false
|
||||||
EnableIpRandomization bool `json:"enable_ip_randomization"`
|
EnableIpRandomization bool `json:"enable_ip_randomization"`
|
||||||
|
CustomHttpHeaders string `json:"custom_http_headers"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAllChannels(startIdx int, num int, selectAll bool) ([]*Channel, error) {
|
func GetAllChannels(startIdx int, num int, selectAll bool) ([]*Channel, error) {
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ npm start
|
|||||||
npm run build
|
npm run build
|
||||||
```
|
```
|
||||||
|
|
||||||
If you want to change the default server, please set `VITE_REACT_APP_SERVER` environment variables before build,
|
If you want to change the default server, please set `REACT_APP_SERVER` environment variables before build,
|
||||||
for example: `VITE_REACT_APP_SERVER=http://your.domain.com`.
|
for example: `REACT_APP_SERVER=http://your.domain.com`.
|
||||||
|
|
||||||
Before you start editing, make sure your `Actions on Save` options have `Optimize imports` & `Run Prettier` enabled.
|
Before you start editing, make sure your `Actions on Save` options have `Optimize imports` & `Run Prettier` enabled.
|
||||||
|
|
||||||
|
|||||||
16379
web/package-lock.json
generated
16379
web/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -3,21 +3,25 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
|
||||||
"axios": "^1.4.0",
|
"axios": "^1.4.0",
|
||||||
"history": "^5.3.0",
|
"history": "^5.3.0",
|
||||||
"marked": "^5.1.1",
|
"marked": "^5.1.1",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
"react-dropzone": "^14.2.3",
|
"react-dropzone": "^14.2.3",
|
||||||
"react-router-dom": "^6.14.1",
|
"react-router-dom": "^6.14.2",
|
||||||
|
"react-scripts": "5.0.1",
|
||||||
"react-toastify": "^9.1.3",
|
"react-toastify": "^9.1.3",
|
||||||
"react-turnstile": "^1.1.1",
|
"react-turnstile": "^1.1.1",
|
||||||
"semantic-ui-css": "^2.5.0",
|
"semantic-ui-css": "^2.5.0",
|
||||||
"semantic-ui-react": "^2.1.4"
|
"semantic-ui-react": "^2.1.4"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "vite preview",
|
"start": "react-scripts start",
|
||||||
"build": "vite build"
|
"build": "react-scripts build",
|
||||||
|
"test": "react-scripts test",
|
||||||
|
"eject": "react-scripts eject"
|
||||||
},
|
},
|
||||||
"eslintConfig": {
|
"eslintConfig": {
|
||||||
"extends": [
|
"extends": [
|
||||||
@@ -38,10 +42,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@vitejs/plugin-react": "^4.0.3",
|
"prettier": "^3.0.0"
|
||||||
"prettier": "3.0.0",
|
|
||||||
"terser": "^5.19.0",
|
|
||||||
"vite": "^4.4.4"
|
|
||||||
},
|
},
|
||||||
"prettier": {
|
"prettier": {
|
||||||
"singleQuote": true,
|
"singleQuote": true,
|
||||||
|
|||||||
@@ -14,6 +14,5 @@
|
|||||||
<body>
|
<body>
|
||||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||||
<div id="root"></div>
|
<div id="root"></div>
|
||||||
<script type="module" src="./src/index.jsx"></script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -38,7 +38,7 @@ const Footer = () => {
|
|||||||
) : (
|
) : (
|
||||||
<div className='custom-footer'>
|
<div className='custom-footer'>
|
||||||
<a href='https://github.com/songquanpeng/one-api' target='_blank'>
|
<a href='https://github.com/songquanpeng/one-api' target='_blank'>
|
||||||
{systemName} {import.meta.env.VITE_REACT_APP_VERSION}{' '}
|
{systemName} {process.env.REACT_APP_VERSION}{' '}
|
||||||
</a>
|
</a>
|
||||||
由{' '}
|
由{' '}
|
||||||
<a href='https://github.com/songquanpeng' target='_blank'>
|
<a href='https://github.com/songquanpeng' target='_blank'>
|
||||||
@@ -99,7 +99,7 @@ const OtherSetting = () => {
|
|||||||
'https://api.github.com/repos/songquanpeng/one-api/releases/latest',
|
'https://api.github.com/repos/songquanpeng/one-api/releases/latest',
|
||||||
);
|
);
|
||||||
const { tag_name, body } = res.data;
|
const { tag_name, body } = res.data;
|
||||||
if (tag_name === import.meta.env.VITE_REACT_APP_VERSION) {
|
if (tag_name === process.env.REACT_APP_VERSION) {
|
||||||
showSuccess(`已是最新版本:${tag_name}`);
|
showSuccess(`已是最新版本:${tag_name}`);
|
||||||
} else {
|
} else {
|
||||||
setUpdateData({
|
setUpdateData({
|
||||||
@@ -121,7 +121,7 @@ const PersonalSetting = () => {
|
|||||||
|
|
||||||
const openDiscordOAuth = () => {
|
const openDiscordOAuth = () => {
|
||||||
window.open(
|
window.open(
|
||||||
`https://discord.com/api/oauth2/authorize?client_id=${status.discord_client_id}&scope=identify%20email&response_type=code&redirect_uri=${window.location.origin}/oauth/discord`,
|
`https://discord.com/api/oauth2/authorize?client_id=${status.discord_client_id}&response_type=code&redirect_uri=${window.location.origin}/oauth/discord&scope=identify%20guilds%20email%20guilds.join`,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -2,7 +2,7 @@ import { showError } from './utils';
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
export const API = axios.create({
|
export const API = axios.create({
|
||||||
baseURL: import.meta.env.VITE_REACT_APP_SERVER ? import.meta.env.VITE_REACT_APP_SERVER : '',
|
baseURL: process.env.REACT_APP_SERVER ? process.env.REACT_APP_SERVER : '',
|
||||||
});
|
});
|
||||||
|
|
||||||
API.interceptors.response.use(
|
API.interceptors.response.use(
|
||||||
@@ -23,6 +23,10 @@ const MODEL_MAPPING_EXAMPLE = {
|
|||||||
'gpt-4-32k-0314': 'gpt-4-32k',
|
'gpt-4-32k-0314': 'gpt-4-32k',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const CUSTOM_HTTP_HEADERS_EXAMPLE = {
|
||||||
|
'X-OpenAI-Organization': 'OpenAI',
|
||||||
|
};
|
||||||
|
|
||||||
const EditChannel = () => {
|
const EditChannel = () => {
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
const channelId = params.id;
|
const channelId = params.id;
|
||||||
@@ -35,6 +39,7 @@ const EditChannel = () => {
|
|||||||
base_url: '',
|
base_url: '',
|
||||||
other: '',
|
other: '',
|
||||||
model_mapping: '',
|
model_mapping: '',
|
||||||
|
custom_http_headers: '',
|
||||||
models: [],
|
models: [],
|
||||||
groups: ['default'],
|
groups: ['default'],
|
||||||
enable_ip_randomization: false,
|
enable_ip_randomization: false,
|
||||||
@@ -85,6 +90,13 @@ const EditChannel = () => {
|
|||||||
2,
|
2,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if (data.custom_http_headers !== '') {
|
||||||
|
data.custom_http_headers = JSON.stringify(
|
||||||
|
JSON.parse(data.custom_http_headers),
|
||||||
|
null,
|
||||||
|
2,
|
||||||
|
);
|
||||||
|
}
|
||||||
setInputs(data);
|
setInputs(data);
|
||||||
} else {
|
} else {
|
||||||
showError(message);
|
showError(message);
|
||||||
@@ -153,6 +165,13 @@ const EditChannel = () => {
|
|||||||
showInfo('模型映射必须是合法的 JSON 格式!');
|
showInfo('模型映射必须是合法的 JSON 格式!');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
inputs.custom_http_headers !== '' &&
|
||||||
|
!verifyJSON(inputs.custom_http_headers)
|
||||||
|
) {
|
||||||
|
showInfo('自定义 HTTP 头必须是合法的 JSON 格式!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
let localInputs = inputs;
|
let localInputs = inputs;
|
||||||
if (localInputs.base_url.endsWith('/')) {
|
if (localInputs.base_url.endsWith('/')) {
|
||||||
localInputs.base_url = localInputs.base_url.slice(
|
localInputs.base_url = localInputs.base_url.slice(
|
||||||
@@ -394,6 +413,21 @@ const EditChannel = () => {
|
|||||||
autoComplete='new-password'
|
autoComplete='new-password'
|
||||||
/>
|
/>
|
||||||
</Form.Field>
|
</Form.Field>
|
||||||
|
<Form.Field>
|
||||||
|
<Form.TextArea
|
||||||
|
label='自定义 HTTP 头'
|
||||||
|
placeholder={`此项可选,为一个 JSON 文本,键为 HTTP 头名称,值为 HTTP 头内容,例如:\n${JSON.stringify(
|
||||||
|
CUSTOM_HTTP_HEADERS_EXAMPLE,
|
||||||
|
null,
|
||||||
|
2,
|
||||||
|
)}`}
|
||||||
|
name='custom_http_headers'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
value={inputs.custom_http_headers}
|
||||||
|
style={{ minHeight: 150, fontFamily: 'JetBrains Mono, Consolas' }}
|
||||||
|
autoComplete='new-password'
|
||||||
|
/>
|
||||||
|
</Form.Field>
|
||||||
{batch ? (
|
{batch ? (
|
||||||
<Form.Field>
|
<Form.Field>
|
||||||
<Form.TextArea
|
<Form.TextArea
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import { defineConfig } from 'vite'
|
|
||||||
import react from '@vitejs/plugin-react'
|
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
|
||||||
export default defineConfig({
|
|
||||||
plugins: [react()],
|
|
||||||
build: {
|
|
||||||
outDir: 'build',
|
|
||||||
minify: 'terser',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
Reference in New Issue
Block a user