Skip to content

Commit 38067df

Browse files
committed
feat: nexe bundle
- add bundle workflow (base node@18) - add ci
1 parent 4f47162 commit 38067df

File tree

9 files changed

+4042
-494
lines changed

9 files changed

+4042
-494
lines changed

.github/workflows/release.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Manual Release
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
build-and-release:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v3
12+
13+
- name: Setup Node.js
14+
uses: actions/setup-node@v3
15+
with:
16+
node-version: "18"
17+
18+
- name: Install dependencies
19+
run: |
20+
npm install -g pnpm
21+
pnpm install
22+
23+
- name: Build and package
24+
run: |
25+
chmod +x ./scripts/build.sh
26+
./scripts/build.sh
27+
28+
- name: Upload Release Assets
29+
uses: xresloader/upload-to-github-release@v1
30+
env:
31+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
with:
33+
file: "gaoas_*.zip"

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,6 @@ dist
131131

132132
# local config file
133133
genai.config.json
134+
135+
/output
136+
/gaoas_*.zip

README.md

Lines changed: 81 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,87 @@
1-
# generative-ai-openai-api-server
2-
converts Gemini API to OpenAI API format.
3-
4-
# release
5-
WIP
6-
7-
# Why dont using `/v1beta/openai/`?
8-
首先,其实 google 提供了兼容 open api 的接口,其实简单使用的话,完全可以用 `/v1beta/openai/` 即可。
9-
但是, `/v1beta/openai/` 有几个问题:
10-
1. 很多接口不支持,包括 `/v1/models`
11-
2. 很多参数不支持,包括 `"frequency_penalty", "presence_penalty", "stop"`,并且,不支持的时候是报错,而不是忽略它...
12-
3. 缺少 gemini api 的高级功能设定,比如 `上下文缓存` `安全设置`
13-
14-
所以,我开发这个简单的服务用来处理这些问题。
15-
16-
# usage
17-
18-
0. 下载 release bin 文件
19-
1. 修改创建配置文件 (genai.config.json)
20-
2. 运行,即可 默认端口为 4949
21-
22-
## configure
23-
本系统使用json配置文件,配置一个简单的json即可,下面是一个示例
24-
```json
25-
{
26-
"api_key": "sk-xxx",
27-
"server": {
28-
"port": 4949
29-
}
30-
}
31-
```
1+
# Generative AI OpenAI API Server
2+
3+
A lightweight server that translates Gemini API calls into OpenAI API-compatible format.
4+
5+
## Features
6+
This project provides an alternative to using Google's `/v1beta/openai/` endpoint by addressing its limitations, offering enhanced functionality, and extending support for key features.
7+
8+
### Why not use `/v1beta/openai/` directly?
9+
While Google does provide a partially OpenAI-compatible API, there are significant limitations:
10+
1. **Unsupported Endpoints**: Many endpoints, such as `/v1/models`, are not available.
11+
2. **Limited Parameters**: Important parameters like `"frequency_penalty"`, `"presence_penalty"`, and `"stop"` are not supported. When unsupported parameters are included, the API throws an error instead of gracefully ignoring them.
12+
3. **Missing Advanced Features**: Features like context caching and advanced safety configurations from Gemini API are absent.
13+
14+
This server addresses these issues by acting as a middleware between your application and the Gemini API.
15+
3216

33-
完整可配置参数如下:
34-
```ts
35-
type Params = {
36-
api_key: string;
37-
server?: {
38-
port?: number;
39-
};
40-
no_docs?: boolean;
41-
retry?: {
42-
enabled?: boolean;
43-
retries?: number;
44-
factor?: number;
45-
minTimeout?: number;
46-
maxTimeout?: number;
47-
};
48-
debug?: {
49-
stream?: {
50-
log?: boolean;
51-
};
52-
};
53-
}
17+
## Getting Started
18+
19+
### Prerequisites
20+
- Download the latest release binary.
21+
22+
### Steps to Use
23+
1. Create a configuration file (`genai.config.json`).
24+
2. Run the server. The default port is `4949`.
25+
26+
#### Custom Config
5427
```
28+
main.exe -c my_owner.config.json
29+
```
30+
31+
## Configuration
5532

56-
# support endpoints
33+
The server uses a JSON-based configuration file. Below is a basic example:
34+
```json
35+
{
36+
"api_key": "sk-xxx",
37+
"server": {
38+
"port": 4949
39+
}
40+
}
41+
```
42+
43+
### Full Configuration Options
44+
Here is a complete list of configurable parameters:
45+
```ts
46+
type Params = {
47+
api_key: string;
48+
server?: {
49+
port?: number;
50+
};
51+
no_docs?: boolean;
52+
retry?: {
53+
enabled?: boolean;
54+
retries?: number;
55+
factor?: number;
56+
minTimeout?: number;
57+
maxTimeout?: number;
58+
};
59+
debug?: {
60+
stream?: {
61+
log?: boolean;
62+
};
63+
};
64+
};
65+
```
66+
67+
68+
## Supported Endpoints
69+
70+
The server currently supports the following endpoints:
71+
- **`/v1/models`**: Retrieve available model list.
72+
- **`/v1/embeddings`**: Generate vector embeddings for input text.
73+
- **`/v1/chat/completions`**: Chat-based text completions.
74+
75+
> **Note**: `/v1/completions` is not supported because Gemini models do not support completion functionality, and Google's PaLM model (which does) is likely to be deprecated.
76+
77+
78+
## Building the Project
79+
80+
```
81+
pnpm run build:ci
82+
```
5783

58-
- `/v1/models`: 获取模型列表
59-
- `/v1/embeddings`: 文本向量化
60-
- `/v1/chat/completions`: chat文本补全
61-
- ~~`/v1/completions`~~ (难以支持,因为 gemini 系列模型都不支持 completion)
6284

63-
# How to build?
64-
WIP
85+
## License
6586

66-
# LICENSE
67-
MIT
87+
This project is licensed under the **MIT License**.

package.json

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,47 @@
11
{
22
"scripts": {
3-
"dev": "tsx src/main.ts"
3+
"dev": "tsx src/main.ts",
4+
"build:ci": "bash ./scripts/build.sh",
5+
"build": "rollup -c rollup.config.mjs",
6+
"build:windows": "bash ./scripts/build-bin.sh ./output/windows/main.exe windows-x64",
7+
"build:linux": "bash ./scripts/build-bin.sh ./output/linux/main.linux linux-x64",
8+
"build:mac": "bash ./scripts/build-bin.sh ./output/mac/main.mac mac-x64"
49
},
510
"dependencies": {
6-
"@fastify/cors": "^10.0.1",
7-
"@fastify/swagger": "^9.4.0",
8-
"@fastify/swagger-ui": "^5.1.0",
11+
"@fastify/cors": "^8.5.0",
12+
"@fastify/swagger": "^8.15.0",
13+
"@fastify/swagger-ui": "^2.1.0",
914
"@google/generative-ai": "^0.21.0",
10-
"@types/node": "^22.10.1",
1115
"async-retry": "^1.3.3",
1216
"commander": "^12.1.0",
1317
"dotenv": "^16.4.5",
14-
"fastify": "^5.1.0",
18+
"esbuild-plugin-copy": "^2.1.1",
19+
"fastify": "^4.29.0",
1520
"fastify-type-provider-zod": "^4.0.2",
1621
"file-type": "^19.6.0",
1722
"file-type-cjs": "^1.0.7",
23+
"magic-string": "^0.30.14",
1824
"node-fetch": "^3.3.2",
1925
"proxy-agent": "^6.4.0",
26+
"rollup-plugin-copy": "^3.5.0",
27+
"rollup-plugin-esbuild": "^6.1.1",
28+
"rollup-plugin-typescript-paths": "^1.5.0",
29+
"undici": "^5.28.4",
30+
"zod": "^3.23.8"
31+
},
32+
"devDependencies": {
33+
"@babel/preset-env": "^7.26.0",
34+
"@rollup/plugin-commonjs": "^28.0.1",
35+
"@rollup/plugin-json": "^6.1.0",
36+
"@rollup/plugin-node-resolve": "^15.3.0",
37+
"@rollup/plugin-replace": "^6.0.1",
38+
"@rollup/plugin-typescript": "^12.1.1",
39+
"@types/node": "^22.10.1",
40+
"esbuild": "^0.24.0",
41+
"nexe": "4.0.0-rc.6",
42+
"rollup": "^4.28.0",
2043
"tslib": "^2.8.1",
2144
"tsx": "^4.19.2",
22-
"typescript": "^5.7.2",
23-
"undici": "^7.0.0",
24-
"zod": "^3.23.8"
45+
"typescript": "^5.7.2"
2546
}
2647
}

0 commit comments

Comments
 (0)