PromptGenerator / app.py
LinyaJulya's picture
Add application file
b4154da
raw
history blame
5.01 kB
import gradio as gr
import os
import openai
def chatbot_response(prompt_topic):
openai.api_key = "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"
response = openai.ChatCompletion.create(
model="gpt-4",
messages=[
{
"role": "system",
"content": "You are a prompt engineer. You are responsible for crafting high-quality prompts that drive precise and meaningful responses from language models like ChatGPT. You understand the nuances of language, context, and user needs and engineer prompts that help people solve problems.\n\nWhen responding, please follow this structure: \n- Prompt Name\n- Description\n- Prompt Template\n- Instructions\n- Examples"
},
{
"role": "user",
"content": "Create a prompt template for: writing an automatic prompt with ChatGPT."
},
{
"role": "assistant",
"content": "Prompt Name: Automatic Prompt Template\n\nDescription: This allows people to create automatic prompts just from a few inputs.\n\nPrompt Template: You are an expert in [DOMAIN] and [SUB-DOMAIN] specializing in [SPECIFIC SKILL OR FOCUS]. You have helped many people before me to [PAST TASK RELATED TO THE DOMAIN]. Your task is now to [NEW TASK RELATED TO DOMAIN] from scratch. To better understand what I want and need, you should always answer by including a question that helps you better understand the context and my needs. Do you understand?\n\nInstructions: \n1. Identify Your Domain: This is the broader category of your expertise (e.g., sales, financial audit, brand strategy).\n\n2. Specify the Sub-Domain: Narrow down your domain to a more specific area of expertise (e.g., customer relations, internal audit, brand launches).\n\n3. Determine the Specific Skill or Focus: Highlight a particular skill or task you excel at within the sub-domain (e.g., customer acquisition, auditing financial statements, launching successful brands).\n\n4. Recall a Past Task: Think of a task or achievement related to your domain that you have previously accomplished (e.g., developed strategies, audited financial statements, launched brands).\n\n5. Define the New Task: Describe what you want the AI to help with, related to your domain (e.g., develop strategies, audit a statement, create a brand strategy plan).\n\n6. Fill in the Template: Replace the placeholders in the template with the information from steps 1-5:\n ◦ Replace [DOMAIN] with your identified domain.\n ◦ Replace [SUB-DOMAIN] with your specified sub-domain.\n ◦ Replace [SPECIFIC SKILL OR FOCUS] with your determined skill or focus.\n ◦ Replace [PAST TASK RELATED TO THE DOMAIN] with your recalled past task.\n ◦ Replace [NEW TASK RELATED TO DOMAIN] with your defined new task.\n\n7. Input to ChatGPT: Once you've filled in the template, provide it to ChatGPT to receive expertise and insights based on the role and task you've described.\n\nExamples: \nExample 1:\n\"You are an expert in healthcare and pediatrics specializing in child nutrition. You have helped many people before me to advise on balanced diets for children. Your task is now to create a nutritious meal plan for a toddler from scratch. To better understand what I want and need, you should always answer by including a question that helps you better understand the context and my needs. Did you understand?\"\n\nExample 2:\n\"You are an expert in technology and software development specializing in mobile app creation. You have helped many people before me to develop innovative mobile applications. Your task is now to design a prototype for a fitness tracking app from scratch. To better understand what I want and need, you should always answer by including a question that helps you better understand the context and my needs. Did you understand?\"\n\nExample 3:\n\"You are an expert in agriculture and crop management specializing in organic farming. You have helped many people before me to establish organic farms. Your task is now to propose sustainable farming techniques for corn cultivation from scratch. To better understand what I want and need, you should always answer by including a question that helps you better understand the context and my needs. Did you understand?\""
},
{
"role": "user",
"content": f"Create a prompt template for: {prompt_topic}"
}
],
temperature=0.7,
max_tokens=4352,
top_p=1,
frequency_penalty=0,
presence_penalty=0.6,
stop=[" Human:", " AI:"]
)
return response.choices[0].message['content']
with gr.Blocks() as demo:
name = gr.Textbox(label="What do you need a prompt for?", placeholder="I need a prompt for...")
output = gr.Textbox(label="Result")
greet_btn = gr.Button("Generate")
greet_btn.click(fn=chatbot_response, inputs=name, outputs=output, api_name="greet")
demo.launch(share=True)