chatgpt.pyimport openai
from PIL import Image
import requests
class AI:
def __init__(self):
# 可以不需要指定api_base,用默认的就好了,前提是网络通,默认需要翻墙
self.api_base = "https://XXX/api/v1"
self.api_key = "sk-XXX"
def chat(self,prompt,msg):
openai.api_base = self.api_base
openai.api_key = self.api_key
chat_completion = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages = [
# 系统消息,它有助于设置助手的行为
{"role": "system", "content": prompt},
# 用户消息,输入你的问题吧
{"role": "user", "content": msg
...
继续阅读
(19)