#How to get a full response from chatgpt in a telegram bot written in python?

11 messages · Page 1 of 1 (latest)

dense flax
#

Good day, gentlemen and ladies! I need help with a telegram chat bot written in python. The problem is that a cropped response comes to my request sent via telegram. This is due to the restriction of tokens on the response. I want the response to continue as if I had asked to continue chatgpt in the laptop or web version. How can i do this? Is there any other way to get a complete answer?

gleaming wren
dense flax
# gleaming wren Can you share your code for the query/request

sure, check this

@bot.message_handler(content_types=['text'])
def handle_all_messages(message):
response = openai.Completion.create(
model="text-davinci-003",
prompt=message.text,
temperature=0.5,
max_tokens=150,
top_p=1.0,
frequency_penalty=0.5,
presence_penalty=0.0,
)
bot.send_message(chat_id=message.from_user.id, text=response['choices'][0]['text'])

bot.polling(non_stop=True)

on the whole, this is a piece of code taken from playground

gleaming wren
# dense flax sure, check this @bot.message_handler(content_types=['text']) def handle_all_m...

Quick note, you can encapsulate code using backticks. Try it next time you send code using three (`) followed directly by the language, in this case, py. Such as this:

@bot.message_handler(content_types=['text'])
def handle_all_messages(message):
    response = openai.Completion.create(
    model="text-davinci-003",
    prompt=message.text,
    temperature=0.5,
    max_tokens=150,
    top_p=1.0,
    frequency_penalty=0.5,
    presence_penalty=0.0,
    )
    bot.send_message(chat_id=message.from_user.id, text=response['choices'][0]['text'])


bot.polling(non_stop=True)```
#

Your max tokens are only 150, which is going to cut off a LOT. Try increasing it to about 400. This will increase the cost but it won't cut off as much.

#

My own bot is at 800.

dense flax
#

yes, I experimented with the value of the tokens. And suppose I do not have enough maximum value?

gleaming wren
#

Correct. 150 tokens is only about 120ish words in English. Once you get past that, it will cut off.

#

The only way to keep that would be to feed previous responses back to the API

#

You could theoretically feed 3850 tokens worth of previous chats to Davinci-003.

#

This is likely how ChatGPT is able to "recall" conversations to a certain extent.