Closed Sui-Xing closed 1 year ago
I've solved this problem, need to add code to delay sending message to discord when poe is connected, it's because it takes too long to create poe connection/proxy, especially when using proxy to connect poe. Below is the modified code.
@bot.tree.command(name='create', description='prompt a language model (gpt-4, claude etc...)')
@app_commands.describe(prompt='prompt', model='model')
async def say(interaction: discord.Interaction, prompt: str, model: str = 'gpt-4'):
try:
print(interaction.user.name, prompt, model)
await interaction.response.defer(ephemeral=True, thinking=True)
base = f'*model*: `{model}`\n'
system = 'system: your response will be rendered in a discord message, include language hints when returning code like: ```py ...```, and use * or ** or > to create highlights ||\n prompt: '
token = random.choice(open('tokens.txt', 'r').read().splitlines())
client = poe.Client(token.split(':')[0],proxy="http://127.0.0.1:7890")
print("token.split(':')[0]:",token.split(':')[0])
await interaction.followup.send(base)
base += '\n'
completion = client.send_message(models[model],
system + prompt, with_chat_break=True)
for token in completion:
print("token",token)
base += token['text_new']
base = base.replace('Discord Message:', '')
await interaction.edit_original_response(content=base)
except Exception as e:
await interaction.response.send_message(f'an error occured: {e}')
bot.run(token)
I have an problem when input "/create" command in discord channel