代码拉取完成,页面将自动刷新
# -*- 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)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。