← 开源
KenyonY

openai-forward

🚀 大语言模型高效转发服务 · An efficient forwarding service designed for LLMs. · OpenAI API Reverse Proxy

InfrastructureGatewayPython
在 GitHub 打开
增长势头
+024 小时新增 Star0.0%
986
Star
308
Fork
+-1
本周
4
贡献者
创建于 2023-03-28 · 更新于 2026-10-14 · 今日第 12221 名
主要开发者
KenyonYnbloglimboinf

KenyonY/openai-forward 排名第 12,221,有 986 个星标。

同类别比较

KenyonY/openai-forward 排名第 12,221,此处有 8 个同类条目;senstella/parakeet-mlx 排名第 12,220。

同类别比较
名称排名指标
keras-team/keras-hub12,174
语言:
Python
星标数:
994
分叉数:
371
简介:
Pretrained model hub for Keras 3.
fencesandbox/fence12,184
语言:
Go
星标数:
992
分叉数:
44
简介:
Lightweight, container-free sandbox for running commands with network and filesystem restrictions
xing61/zzz-api12,208
星标数:
990
分叉数:
83
简介:
企业级稳定的OpenAI、Claude、Gemini等的API接口-For企业和开发者。OpenAI的api proxy,支持ChatGPT的API调用,支持Anthropic claude的官方接口形式,支持Google gemini的官方接口形式,支持:gpt-5,sora。不需要openai Key, 不需要买openai的账号,不需要美元的银行卡,通通不用的,直接调用就行,稳定好用!!智增增
senstella/parakeet-mlx12,220
语言:
Python
星标数:
987
分叉数:
62
简介:
An implementation of the Nvidia's Parakeet models for Apple Silicon using MLX.
Nya-Foundation/NyaProxy12,222
语言:
Python
星标数:
986
分叉数:
20
简介:
NyaProxy acts like a smart, central manager for accessing various online services (APIs) – think AI tools (like OpenAI, Gemini, Anthropic), image generators, or almost any web service that uses access keys. It helps you use these services more reliably, efficiently, and securely.
codeproject/CodeProject.AI-Server12,225
语言:
C#
星标数:
986
分叉数:
235
简介:
CodeProject.AI Server is a self contained service that software developers can include in, and distribute with, their applications in order to augment their apps with the power of AI.
anibali/docker-pytorch12,230
语言:
Dockerfile
星标数:
985
分叉数:
221
简介:
A Docker image for PyTorch
h2oai/sparkling-water12,247
语言:
Scala
星标数:
982
分叉数:
357
简介:
Sparkling Water provides H2O functionality inside Spark cluster
关键参数与规格
关键参数与规格
参数值
语言Python
类别Infrastructure
子类别Gateway
星标数986
分叉数308
贡献者4
创建日期2023-03-28
更新日期2026-10-14
1 天星标数0
7 天星标数-1
排名12,221
上次排名18,829
排名变化6,608
7 天星标排名17,391
上次 7 天星标排名17,372
7 天星标排名变化-19
总星标排名11,267
上次总星标排名11,257
总星标排名变化-10
国家China
README 摘录

**简体中文** | **English** 特点 | 部署指南 | 使用指南 | 配置 | 对话日志 [! 其核心功能包括 用户请求速率控制、Token速率限制、智能预测缓存、日志管理和API密钥管理等,旨在提供高效、便捷的模型转发服务。 无论是代理本地

语言模型还是云端语言模型,如 LocalAI 或 OpenAI,都可以由 OpenAI Forward 轻松实现。 得益于 uvicorn, aiohttp, 和 asyncio 等库支持,OpenAI-Forward 实现了出色的异步性能。 0版本后支持通过WebUI进行配置管理 gpt-1106版本已适配 缓存后端切换为高性

能数据库后端:🗲 FlaxKV 主要特性 **全能转发**:可转发几乎所有类型的请求 **性能优先**:出色的异步性能 **缓存AI预测**:对AI预测进行缓存,加速服务访问并节省费用 **用户流量控制**:自定义请求速率与Token速率 **实

时响应日志**:提升LLMs可观察性 **自定义秘钥**:替代原始API密钥 **多目标路由**:转发多个服务地址至同一服务下的不同路由 **黑白名单**:可对指定IP进行黑白名单限制 **自动重试**:确保服务的稳定性,请求失

败时将自动重试 **快速部署**:支持通过pip和docker在本地或云端进行快速部署 **由本项目搭建的代理服务地址:** 原始OpenAI 服务地址 > 开启缓存的服务地址(用户请求结果将被保存一段时间) 注:此处部署的代

理服务仅供个人学习和研究目的使用,勿用于任何商业用途。 部署指南 👉 部署文档 使用指南 快速入门 **安装** **启动服务** 如果读入了根路径的 的配置, 将会看到以下启动信息 代理OpenAI模型: 的默认选项便

是代理 下面以搭建好的服务地址 为例 **Python** 代理本

常见问题

记录了多少星标和分叉?

KenyonY/openai-forward 有 986 个星标和 308 个分叉。

仓库排名是多少?

KenyonY/openai-forward 排名第 12,221。

记录的语言和类别是什么?

KenyonY/openai-forward 有 986 个星标,语言为 Python,类别为 Infrastructure。

哪个仓库排名最接近?

KenyonY/openai-forward 与 senstella/parakeet-mlx 比较,后者排名第 12,220,有 987 个星标。

README

简体中文 | English

[OpenAI Forward](https://github.com/KenyonY/openai-forward)
  

  






[![PyPI version](https://img.shields.io/pypi/v/openai-forward?color=brightgreen&style=flat-square)](https://pypi.org/project/openai-forward/)
[![License](https://img.shields.io/github/license/KenyonY/openai-forward.svg?color=blue&style=flat-square)](https://github.com/KenyonY/openai-forward/blob/main/LICENSE)
[![docker pull](https://img.shields.io/docker/pulls/beidongjiedeguang/openai-forward?style=flat-square&label=docker pulls)](https://hub.docker.com/r/beidongjiedeguang/openai-forward)
[![tests](https://img.shields.io/github/actions/workflow/status/KenyonY/openai-forward/ci.yml?style=flat-square&label=tests)](https://github.com/KenyonY/openai-forward/actions/workflows/ci.yml)
[![pypi downloads](https://img.shields.io/pypi/dm/openai_forward?style=flat-square)](https://pypistats.org/packages/openai-forward)

特点 | 部署指南 | 使用指南 | 配置 | 对话日志

[!IMPORTANT]

在v0.7.0以后在配置方面会有较大调整,并与之前版本不兼容。通过UI配置起来会更加方便,且提供了更强大的配置选项。

OpenAI-Forward 是为大型语言模型实现的高效转发服务。其核心功能包括 用户请求速率控制、Token速率限制、智能预测缓存、日志管理和API密钥管理等,旨在提供高效、便捷的模型转发服务。 无论是代理本地语言模型还是云端语言模型,如 LocalAI 或 OpenAI,都可以由 OpenAI Forward 轻松实现。 得益于 uvicorn, aiohttp, 和 asyncio 等库支持,OpenAI-Forward 实现了出色的异步性能。

News

  • 🎉🎉🎉 v0.7.0版本后支持通过WebUI进行配置管理
  • gpt-1106版本已适配
  • 缓存后端切换为高性能数据库后端:🗲 FlaxKV

主要特性

  • 全能转发:可转发几乎所有类型的请求
  • 性能优先:出色的异步性能
  • 缓存AI预测:对AI预测进行缓存,加速服务访问并节省费用
  • 用户流量控制:自定义请求速率与Token速率
  • 实时响应日志:提升LLMs可观察性
  • 自定义秘钥:替代原始API密钥
  • 多目标路由:转发多个服务地址至同一服务下的不同路由
  • 黑白名单:可对指定IP进行黑白名单限制
  • 自动重试:确保服务的稳定性,请求失败时将自动重试
  • 快速部署:支持通过pip和docker在本地或云端进行快速部署

由本项目搭建的代理服务地址:

注:此处部署的代理服务仅供个人学习和研究目的使用,勿用于任何商业用途。

部署指南

👉 部署文档

使用指南

快速入门

安装

pip install openai-forward 

# 或安装webui版本:
pip install openai-forward[webui]

启动服务

aifd run
# 或启动带webui的服务
aifd run --webui

如果读入了根路径的.env的配置, 将会看到以下启动信息

❯ aifd run
╭────── 🤗 openai-forward is ready to serve!  ───────╮
│                                                    │
│  base url         https://api.openai.com           │
│  route prefix     /                                │
│  api keys         False                            │
│  forward keys     False                            │
│  cache_backend    MEMORY                           │
╰────────────────────────────────────────────────────╯
╭──────────── ⏱️ Rate Limit configuration ───────────╮
│                                                    │
│  backend                memory                     │
│  strategy               moving-window              │
│  global rate limit      100/minute (req)           │
│  /v1/chat/completions   100/2minutes (req)         │
│  /v1/completions        60/minute;600/hour (req)   │
│  /v1/chat/completions   60/second (token)          │
│  /v1/completions        60/second (token)          │
╰────────────────────────────────────────────────────╯
INFO:     Started server process [191471]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)

代理OpenAI模型:

aifd run的默认选项便是代理https://api.openai.com

下面以搭建好的服务地址https://api.openai-forward.com 为例

Python

  from openai import OpenAI  # pip install openai>=1.0.0
  client = OpenAI(
+     base_url="https://api.openai-forward.com/v1", 
      api_key="sk-******"
  )

代理本地模型

  • 适用场景: 与 LocalAI, api-for-open-llm等项目一起使用

  • 如何操作: 以LocalAI为例,如果已在 http://localhost:8080 部署了LocalAI服务,仅需在环境变量或 .env 文件中设置 FORWARD_CONFIG=[{"base_url":"http://localhost:8080","route":"/localai","type":"openai"}]。 然后即可通过访问 http://localhost:8000/localai 使用LocalAI。

(更多)

代理任意云端模型

代理gemini pro

配置环境变量或 .env 文件如下:

FORWARD_CONFIG=[{"base_url":"https://generativelanguage.googleapis.com","route":"/gemini","type":"general"}]

说明:aidf run启动后,即可通过访问 http://localhost:8000/gemini 使用gemini pro。

  • 场景1: 使用通用转发,可对任意来源服务进行转发, 可获得请求速率控制与token速率控制;但通用转发不支持自定义秘钥.

  • 场景2: 可通过 LiteLLM 可以将 众多云模型的 API 格式转换为 openai 的api格式,然后使用openai风格转发

(更多)

配置

执行 aifd run --webui 进入配置页面 (默认服务地址 http://localhost:8001)

你可以在项目的运行目录下创建 .env 文件来定制各项配置。参考配置可见根目录下的 .env.example文件

智能缓存

开启缓存后,将会对指定路由的内容进行缓存,其中转发类型分别为openai与general两者行为略有不同, 使用general转发时,默认会将相同的请求一律使用缓存返回,
使用openai转发时,在开启缓存后,可以通过OpenAI 的extra_body参数来控制缓存的行为,如

Python

  from openai import OpenAI 
  client = OpenAI(
+     base_url="https://smart.openai-forward.com/v1", 
      api_key="sk-******"
  )
  completion = client.chat.completions.create(
    model="gpt-3.5-turbo",
    messages=[
      {"role": "user", "content": "Hello!"}
    ],
+   extra_body={"caching": True}
)

Curl

curl https://smart.openai.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-******" \
  -d '{
    "model": "gpt-3.5-turbo",
    "messages": [{"role": "user", "content": "Hello!"}],
    "caching": true
  }'

自定义秘钥

Click for more details

见.env文件

用例:

  import openai
+ openai.api_base = "https://api.openai-forward.com/v1"
- openai.api_key = "sk-******"
+ openai.api_key = "fk-******"

多目标服务转发

支持转发不同地址的服务至同一端口的不同路由下 用例见 .env.example

对话日志

Click for more details

保存路径在当前目录下的Log/openai/chat/chat.log路径中。
记录格式为

{'messages': [{'role': 'user', 'content': 'hi'}], 'model': 'gpt-3.5-turbo', 'stream': True, 'max_tokens': None, 'n': 1, 'temperature': 1, 'top_p': 1, 'logit_bias': None, 'frequency_penalty': 0, 'presence_penalty': 0, 'stop': None, 'user': None, 'ip': '127.0.0.1', 'uid': '2155fe1580e6aed626aa1ad74c1ce54e', 'datetime': '2023-10-17 15:27:12'}
{'assistant': 'Hello! How can I assist you today?', 'is_tool_calls': False, 'uid': '2155fe1580e6aed626aa1ad74c1ce54e'}

转换为json格式:

aifd convert

得到chat_openai.json:

[
    {
        "datetime": "2023-10-17 15:27:12",
        "ip": "127.0.0.1",
        "model": "gpt-3.5-turbo",
        "temperature": 1,
        "messages": [
            {
                "user": "hi"
            }
        ],
        "tools": null,
        "is_tool_calls": false,
        "assistant": "Hello! How can I assist you today?"
    }
]

贡献

欢迎通过提交拉取请求或在仓库中提出问题来为此项目做出贡献。

许可证

OpenAI-Forward 采用 MIT 许可证。

排名相邻
同类项目