跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[OpenAI] 推荐个迁移 openai api 比较便捷的方式

发表于

用的一个开源 api 网关 higress ,可以对接基本国内所有的模型厂商

以通义千问为例,先启动网关:

# 创建一个工作目录
mkdir higress; cd higress
# 启动 higress ,配置文件会写到工作目录下
docker run -d --rm --name higress-ai -v ${PWD}:/data \
        -p 8001:8001 -p 8080:8080 \
        -e CONFIG_TEMPLATE=ai-proxy -e DEFAULT_AI_SERVICE=qwen \
        -e DASHSCOPE_API_KEY=这里填通义千问 APIKey \
        higress-registry.cn-hangzhou.cr.aliyuncs.com/higress/all-in-one:1.4.1

然后代码里调整下 base url 就行了:

from openai import OpenAI

client = OpenAI(
    api_key="your-api-key",
    base_url="http://127.0.0.1:8080/v1"
)

# 不需要修改模型,higress 做了等价映射
stream = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "你是谁"}],
    stream=True,
)

for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content)

还能进这个 api 网关的控制台: http://127.0.0.1:8001

可以看到默认的模型映射规则,自己可以调整:

O1CN012JG9QC1qw4hK8IWIq_%21%216000000005

插件配置还可以开启联网搜索:

provider:
  type: qwen
  apiTokens:
  - "通义千问 API Key"
  modelMapping:
  # 映射配置省略
  ...
  # 开启联网搜索
  qwenEnableSearch: true

用 lobechat 对接的效果:

O1CN01qgEgJH1kXu69PksxR_%21%216000000004

对接 lobechat 参考的这个: https://github.com/alibaba/higress/issues/1023

Featured Replies

No posts to show

创建帐户或登录来提出意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.