|
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 | + |
32 | 16 |
|
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 |
54 | 27 | ```
|
| 28 | +main.exe -c my_owner.config.json |
| 29 | +``` |
| 30 | + |
| 31 | +## Configuration |
55 | 32 |
|
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 | +``` |
57 | 83 |
|
58 |
| -- `/v1/models`: 获取模型列表 |
59 |
| -- `/v1/embeddings`: 文本向量化 |
60 |
| -- `/v1/chat/completions`: chat文本补全 |
61 |
| -- ~~`/v1/completions`~~ (难以支持,因为 gemini 系列模型都不支持 completion) |
62 | 84 |
|
63 |
| -# How to build? |
64 |
| -WIP |
| 85 | +## License |
65 | 86 |
|
66 |
| -# LICENSE |
67 |
| -MIT |
| 87 | +This project is licensed under the **MIT License**. |
0 commit comments