WPeace-HcH/WPeChatGPT

建议:openai库优化调用第三方接口和国内接口方法

Opened this issue · 0 comments

主应用代码优化如下:
1、新增了openai_base_url用于调用兼容openai的api接口url
2、建议价以下model只要是兼容openai-api接口的都模型描述

PLUGIN_NAME = 'WPeChatGPT'
PROD_NAME = 'ChatGPT'
MODEL = 'qwen-plus'
# Set your API key here, or put in in the OPENAI_API_KEY environment variable.
openai_api_key = "ENTER_OPEN_API_KEY_HERE"
#支持兼容openai的接口(当前为阿里云百炼)
openai_base_url="https://dashscope.aliyuncs.com/compatible-mode/v1"

# Set your forward-proxy if necessary. (e.g. Clash = http://127.0.0.1:7890)
proxy = ""
# Set reverse-proxy URL if you need. (e.g. Azure OpenAI)
proxy_address = "https://dashscope.aliyuncs.com/compatible-mode/v1"
# Create openai client (python openai package version > 1.2)
if proxy:
    client = openai.OpenAI(http_client=httpx.Client(proxies=proxy, transport=httpx.HTTPTransport(local_address="0.0.0.0")), api_key=openai_api_key)
    print("WPeChatGPT has appointed the forward-proxy.")
elif proxy_address:
    client = openai.OpenAI(base_url=proxy_address, api_key=openai_api_key)
    print("WPeChatGPT has appointed the reverse-proxy.")
else:
   #接口调用openai_base_url
    client = openai.OpenAI(api_key=openai_api_key,base_url=openai_base_url)

成果如下:
image