Created
December 4, 2022 20:55
-
-
Save versvs/51f5d26d1f019788d8caa4b340e77ea6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import openai | |
import telegram | |
# Configura la API de ChatGPT | |
openai.api_key = "TU_API_KEY" | |
# Configura el bot de telegram | |
bot = telegram.Bot(token="TU_TOKEN_BOT") | |
# Esta función se ejecutará cuando el usuario envíe un mensaje al bot | |
def handle_message(message): | |
# Obtén el texto del mensaje | |
text = message.text | |
# Utiliza ChatGPT para generar una respuesta | |
response = openai.Completion.create( | |
engine="text-davinci-002", | |
prompt=text, | |
max_tokens=1024, | |
n=1, | |
stop=None | |
) | |
# Obtén la respuesta generada por ChatGPT | |
response_text = response["choices"][0]["text"] | |
# Envía la respuesta al usuario | |
bot.send_message(chat_id=message.chat.id, text=response_text) | |
# Establece el manejador de mensajes | |
bot.set_update_handler(handle_message) | |
# Inicia el bot | |
bot.poll() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment