#Problem with API and telegram.
51 messages · Page 1 of 1 (latest)
Can you share the full request and the response?
Any requests, the only response is "id"
Tomorrow will send code
kk, yeah would help to see the code and response
import json
import os
import openai
import telebot
from telebot import types
bot = telebot.TeleBot("KEY")
@bot.message_handler(content_types=["text"])
def get_text_messages(message):
json_message = json.loads(json.dumps(str(message)))
#print(type(message))
#print(type(json_message))
start_sequence = "\nAI:"
restart_sequence = "\nHuman: "
openai.api_key = os.getenv("KEY")
openai.api_key = ("KEY")
response = openai.Completion.create(
model="text-davinci-003",
prompt= json_message,
temperature=0.9,
max_tokens=150,
top_p=1,
frequency_penalty=0,
presence_penalty=0.6,
stop=[" Human:", " AI:"]
)
bot.send_message(message.chat.id, response)
bot.polling(none_stop=True, interval=0)
response:
you need to locate to the text in the response
In javascript it’s response.data.choices[0].text
instead of just a ‘response’
so i need to put in instead of "response" in send function?
but its python
it’s similar, but i don’t know how to write in python
why not ask chatgpt to convert this to python

response.choices[0].text.strip()
try this
replace this to the response in bot send messages
im getting muted for not speaking english
I think it will work
now diferent
Emm since the knowledge base of chatGPT is cut by 2021, some of its knowledge might be outdated
console version is working
whyyyy
bot.send_message(message.chat.id, str(response)
@lean zinc @royal belfry any ideas?
hello
you need to modify your prompt
prompt should be something like this if you are making a chat bot:
The following is a conversation between Human and AI.
Human: hello
AI: hi there
Human:
then add your message after the Human:
then, add a AI: after that
Finally the prompt is:
The following is a conversation between Human and AI.
Human: Hello
AI: hi there
Human: (your message)
AI:
please note that the use of api is much different from chatgpt, it cannot store your message and don’t know wha to do if you do not give it an exact instruction