@bot.slashcommand( name='refinetext', description='Refine input text by iterating with…
- User
@bot.slash_command( name='refine_text', description='Refine input text by iterating with an external AI service.' ) async def refine_text(ctx: discord.ApplicationContext, input_text: str):
Defer response if operation takes a long time
await ctx.defer()
Create a thread from the current channel with the provided name
thread = await ctx.channel.create_thread(name=input_text[:100], type=discord.ChannelType.public_thread) await ctx.followup.send(f'Thread "{input_text[:100]}" created!')
Initialize the message to be refined
message_to_refine = input_text
Loop to refine the text 5 times
for i in range(5): await thread.send(f"Refining: Iteration {i+1}")
headers = { 'Origin': 'https://gptcall.net/', 'Referer': 'https://gptcall.net/' } body = { "model": "gpt-3.5-turbo", "messages": [ { "role": "system", "content": "You are RefineGPT. RefineGPT takes an input and if it is an action needed to be done process the action. If it is a completed action then refine the action to be better. AI Image Prompt Examples: A highly photorealistic image of a off road race track, complete with precise replicas of the world’s most iconic heavy noun, captured at the moment of a sharp turn, with smoke and sparks flying from under the wheels and the noun drifting around the bend. The image captures the excitement of the moment, with happy and noisy fans cheering and waving in the background. If asked to make one generate a image in that style with lots of keywords like 8k, 16k, realisitc, appened to the end. Do not assume the user is making an image. Don't assume the user is talking to you always think it is needing you to refine the response." }, { "role": "user", "content": message_to_refine } # Add more messages if needed ] } # Send the request to the external AI service response = requests.post( "https://reverse.mubi.tech/v1/chat/completions", json=body, headers=headers ) # Parse the response and refine the message if response.status_code == 200: response_data = response.json() message_to_refine = response_data['choices'][0]['message']['content'] # Display the refined message await thread.send(f"Refined text (Iteration {i+1}): {message_to_refine}") else: await thread.send("An error occurred while contacting the AI service. Please try again later.") break # Exit if there's an errorMake this so it remembers the past messages in the refiment process.
- Assistant