Comments (2)
Hi @michaelfeil ,
I understand that your goal is to reverse proxy multiple service addresses (such as api.openai.com
and localhost:8080
) to the same port. This can be easily achieved by making a few code modifications. For example, you can add another route in openai_forward/app.py
:
from sparrow.api import create_app
from .openai import Openai
app = create_app(title="openai_forward", version="1.0")
def add_route(obj: Openai):
app.add_route(
obj.ROUTE_PREFIX + "/{api_path:path}",
obj.reverse_proxy,
methods=["GET", "POST", "PUT", "DELETE", "OPTIONS", "HEAD", "PATCH", "TRACE"],
)
openai = Openai()
openai.BASE_URL = "https://api.openai.com"
openai.ROUTE_PREFIX = "/openai"
add_route(openai)
localai = Openai()
localai.BASE_URL = "http://localhost:8080"
localai.ROUTE_PREFIX = "/localai"
add_route(localai)
Then, remove the @classmethod
decorator for the _reverse_proxy
class method in openai_forward/base.py
, otherwise, the modification to BASE_URL will not take effect.
After making these changes, you will be able to access the content of api.openai.com under the /openai
route, such as openai/audio/translations
, and access all content from the service http://localhost:8080
under the /localai
route, such as /localai/v1/completions
.
In the future, it's worth considering making ROUTE_PREFIX
and BASE_URL
configurable for multiple target.
from openai-forward.
Now we can specify multiple targets through configuration, like this:
https://github.com/beidongjiedeguang/openai-forward/blob/e7d09ce3cb647e41af5d3a0c5039fe5659a08d34/.env.example#L6-L10
from openai-forward.
Related Issues (20)
- 您好,这是什么问题? HOT 2
- 如果我想二次转发,我应该配置哪里? HOT 5
- Feat: Supports the latest `/v1/chat/completion` routing HOT 2
- Feat: Convert local model output to OpenAI API format
- 429 Too Many Requests HOT 1
- Update docs HOT 3
- 现在cf render vercel 部署后访问都是404 HOT 1
- 使用gpt4,不使用流式返回,提交长文本之后,会返回(504 Gateway Time-out),代码把httpx超时和转发的超时都设置成120也不管用 HOT 34
- 能否实现按照 model 进行区分 HOT 5
- 请问可否在启动命令中增加port和webui port的设置 HOT 8
- 根据Forward key限制模型访问未生效 HOT 3
- Render部署失败 HOT 3
- 想知道什么样的服务器做中转速度才能快呢,能添加一些测试服务器是否适合的功能吗. HOT 2
- 没办法实现流式 HOT 1
- pip安装的0.7.2启动失败 HOT 3
- env中部分配置不生效
- webui 无法保存设置 HOT 2
- 经常模型奇妙的崩溃 HOT 2
- Feat: Azure OpenAI support HOT 4
- Fail to deploy on Render for the newest version HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openai-forward.