ChatGPTNextWeb / ChatGPT-Next-Web

A cross-platform ChatGPT/Gemini UI (Web / PWA / Linux / Win / MacOS). 一键拥有你自己的跨平台 ChatGPT/Gemini 应用。
https://app.nextchat.dev/
MIT License
76.42k stars 59.11k forks source link

[help] api.theb.ai的一些问题 #2666

Closed lswlc33 closed 1 year ago

lswlc33 commented 1 year ago

最近 theb.ai 开放了api 我使用openai一样的请求格式可以成功请求 下面是一个python例子

url_bai = "https://api.theb.ai/v1/chat/completions"
bai_api = "sk-xxxxxxxxxxxxx"

def res(url, api, ask):
    payload = json.dumps(
    {
        "model": "gpt-3.5-turbo",
        "messages": [{"role": "user", "content": ask}],
        "temperature": 1,
        "max_tokens": 256,
        "top_p": 1,
        "frequency_penalty": 0,
        "presence_penalty": 0,
    }
    )
    headers = {
        "Authorization": "Bearer {}".format(api),
        "Content-Type": "application/json",
    }
    response = requests.request("POST", url, headers=headers, data=payload)
    return response.text

ask = '早上好'
print(res(url_bai,bai_api,ask))

返回内容

{
'choices': [{'finish_reason': 'stop',
              'index': 0,
              'message': {'content': '早上好!有什么我可以帮助您的吗?', 'role': 'assistant'}}],
 'created': 1692513880,
 'id': '5242a7e8fbcf49fb9f423f7e9b068632',
 'model': 'gpt-3.5-turbo',
 'object': 'chat.completion',
 'usage': {'completion_tokens': 20, 'prompt_tokens': 4, 'total_tokens': 24}
}

但是在此项目使用会出现报错 设置: image

报错内容: Access to fetch at 'https://api.theb.ai/v1/chat/completions' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

该如何解决?

Yidadaa commented 1 year ago

字面意思,theb.ai 没有开放 api 跨域访问,请联系对方开放一下。

Issues-translate-bot commented 1 year ago

Bot detected the issue body's language is not English, translate it automatically.


Literally, theb.ai does not open api cross-domain access, please contact the other party to open it.