1 Star 0 Fork 0

rmrb1111/chatgpt-proxy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
functiongraph.py 832 Bytes
一键复制 编辑 原始数据 按行查看 历史
# -*- coding:utf-8 -*-
"""
desc: 华为云FunctionGraph访问chatgpt开放API
author: SixSeven
"""
import json
import requests
def handler(event, context):
return {
"status": 200,
"result": chatgpt_api(event)
}
def chatgpt_api(request_dict: dict):
try:
if "headers" not in request_dict:
return "The key \"headers\" is required."
if "body" not in request_dict:
return "The key \"body\" is required."
headers = request_dict["headers"]
body = request_dict["body"]
response = requests.post('https://api.openai.com/v1/chat/completions', headers=headers, data=json.dumps(body))
if response.ok:
return response.text
else:
response.raise_for_status()
except Exception as e:
return str(e)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/rmrb1111/chatgpt-proxy.git
git@gitee.com:rmrb1111/chatgpt-proxy.git
rmrb1111
chatgpt-proxy
chatgpt-proxy
main

搜索帮助