“client”未定义,client.completions.create

问题描述 投票:0回答:1
import telebot
import openai
 
bot = telebot.TeleBot("0")
openai.api_key = "0"
 
@bot.message_handler(content_types=['text'])
def lalala(message):
    print(message.chat.title, message.chat.username)
    if message.chat.id == -1002097745017:
    #print(message.text)
        if "@0" in message.text:
            message.text = (message.text).replace("@0 ", "")
            #print(message.text)
            response = client.completions.create(model="gpt-3.5-turbo-0613", prompt=message.text, max_tokens=1000)
            full_response = response['choices'][0]['text']  # Use the text property of the first element of the choices list to access the full response
            lines = full_response.splitlines()  # Split the response into individual lines
            for line in lines:  # Iterate over the lines
                try:
                    #print(line)
                    bot.send_message(message.chat.id, line)  # Send each line back to the user as a separate message
                except Exception as e:
                    print(e)
    else:
        bot.send_message(message.chat.id, "work only - tg.com/123123")
 
bot.polling(none_stop=True, interval=0)

response = client.completions.create(model =“gpt-3.5-turbo-0613”,prompt = message.text,max_tokens = 1000)NameError:名称“client”未定义

改变

response = client.completions.create(model="gpt-3.5-turbo-0613", prompt=message.text, max_tokens=1000)

response = openai.Completion.create(model="text-davinci-003", prompt=message.text, max_tokens=1000)

结果:

这是一个聊天模型,v1/completions 端点不支持。您的意思是使用 v1/chat/completions 吗?

python telegram openai-api chatgpt-api
1个回答
0
投票

您尝试了多种组合,但没有找到正确的组合。

以下应该有效:

response = openai.completions.create(model="gpt-3.5-turbo-instruct", prompt=message.text, max_tokens=1000)
© www.soinside.com 2019 - 2024. All rights reserved.