चैटबॉट डेवलपमेंट के लिए प्रॉम्प्ट इंजीनियरिंग

OpenAI API के साथ Prompt Engineering

Fouad Trad

Machine Learning Engineer

चैटबॉट्स के लिए प्रॉम्प्ट इंजीनियरिंग की ज़रूरत

  • यूज़र के सवालों का अनुमान लगाना मुश्किल
  • प्रभावी जवाब सुनिश्चित करना चुनौतीपूर्ण
  • प्रॉम्प्ट इंजीनियरिंग चैटबॉट के व्यवहार को निर्देश देती है

मोबाइल फोन पर चैटबॉट दिखाने वाली छवि.

OpenAI API के साथ Prompt Engineering

OpenAI API के साथ चैटबॉट प्रॉम्प्ट इंजीनियरिंग

संदेश की तीन भूमिकाएँ और उनके बीच संचार दिखाने वाली छवि.

  • हर संदेश की एक निर्धारित भूमिका होती है
OpenAI API के साथ Prompt Engineering

OpenAI API के साथ चैटबॉट प्रॉम्प्ट इंजीनियरिंग

संदेश की तीन भूमिकाएँ और उनके बीच संचार दिखाने वाली छवि, यूज़र और असिस्टेंट की इंटरैक्शन पर हाइलाइट.

  • हर संदेश की एक निर्धारित भूमिका होती है
  • फोकस यूज़र प्रॉम्प्ट्स पर रहा है
OpenAI API के साथ Prompt Engineering

OpenAI API के साथ चैटबॉट प्रॉम्प्ट इंजीनियरिंग

संदेश की तीन भूमिकाएँ और उनके बीच संचार दिखाने वाली छवि, सिस्टम और असिस्टेंट की इंटरैक्शन पर हाइलाइट.

  • हर संदेश की एक निर्धारित भूमिका होती है
  • फोकस यूज़र प्रॉम्प्ट्स पर रहा है
  • सिस्टम प्रॉम्प्ट्स चैटबॉट के व्यवहार को गाइड करते हैं
OpenAI API के साथ Prompt Engineering

चैटबॉट डेवलपमेंट के लिए चैट कम्प्लीशन्स एंडपॉइंट

  • संदेशों की श्रृंखला को सूची के रूप में मॉडल को भेजता है
response = client.chat.completions.create(
  model="gpt-4o-mini",
  messages=[{"role": "system",
             "content": "You are an expert data scientist that explains complex concepts in simple terms"},

{"role": "user", "content": "What is prompt engineering?"}] )
print(response.choices[0].message.content)
Imagine you're giving instructions to a computer program, like teaching a robot to make a sandwich. 
Prompt engineering is all about crafting those instructions, or "prompts," in a way that helps the 
computer understand and perform the task better.
OpenAI API के साथ Prompt Engineering

चैटबॉट के लिए get_response() बदलना

  • एक प्रॉम्प्ट भेजना
def get_response(prompt):
    messages = [
      {"role": "user", "content": prompt}
    ]
    response = client.chat.completions.create(
        model="gpt-4o-mini",
        messages=messages,
        temperature=0,
    )
    return response.choices[0].message.content

prompt = "<PROMPT>" print(get_response(prompt))
  • दो प्रॉम्प्ट भेजना
def get_response(system_prompt, user_prompt):

messages = [ {"role": "system", "content": system_prompt}, {"role": "user", "content": user_prompt}]
response = client.chat.completions.create( model="gpt-4o-mini", messages=messages, temperature=0, ) return response.choices[0].message.content
system_prompt = "<SYSTEM_PROMPT>" user_prompt = "<USER_PROMPT>" print(get_response(system_prompt, user_prompt))
OpenAI API के साथ Prompt Engineering

सिस्टम मैसेज: उद्देश्य तय करें

system_prompt = "You are a chatbot that answers financial questions."

user_prompt = "Who are you?" print(get_response(system_prompt, user_prompt))
I'm a financial chatbot that answers financial questions. How can I help you?
  • चैटबॉट को डोमेन-सटीक सहायता देने दें
  • उद्देश्य न तय करने पर संदर्भ से बाहर उत्तर आ सकते हैं
OpenAI API के साथ Prompt Engineering

सिस्टम मैसेज: उत्तर दिशा-निर्देश

  • ऑडिएंस, टोन, लंबाई, संरचना निर्दिष्ट करें
system_prompt = """You are a chatbot that answers financial questions. 
Your answers should be precise, formal and objective"""

user_prompt = "What do you think about cryptocurrencies?" print(get_response(system_prompt, user_prompt))
OpenAI API के साथ Prompt Engineering

सिस्टम मैसेज: उत्तर दिशा-निर्देश

Cryptocurrencies are digital or virtual currencies that use cryptography for security and operate on 
decentralized networks based on blockchain technology. 
[...]

Advantages of cryptocurrencies include: - Decentralization: [...] - Security:[...] - Global Accessibility: [...]
However, there are also notable concerns: - Volatility: [...] - Regulatory Uncertainty: [...] - Lack of Consumer Protection: [...]
In summary, cryptocurrencies have the potential to offer various benefits, but their adoption and impact on the financial landscape are still evolving [...]
OpenAI API के साथ Prompt Engineering

सिस्टम मैसेज: व्यवहार मार्गदर्शन

  • प्रश्नों के लिए कंडीशनल प्रॉम्प्ट्स
system_prompt = """You are a chatbot that answers financial questions. 
Your answers should be precise, formal and objective.


"""
OpenAI API के साथ Prompt Engineering

सिस्टम मैसेज: व्यवहार मार्गदर्शन

  • प्रश्नों के लिए कंडीशनल प्रॉम्प्ट्स
system_prompt = """You are a chatbot that answers financial questions. 
Your answers should be precise, formal and objective.
If the question you receive is within the financial field, answer it to the best of your knowledge.

"""
OpenAI API के साथ Prompt Engineering

सिस्टम मैसेज: व्यवहार मार्गदर्शन

  • प्रश्नों के लिए कंडीशनल प्रॉम्प्ट्स
system_prompt = """You are a chatbot that answers financial questions. 
Your answers should be precise, formal and objective.
If the question you receive is within the financial field, answer it to the best of your knowledge.
Otherwise, answer with 'Sorry, I only know about finance.'
"""
user_prompt = "How's the weather today?"

print(get_response(system_prompt, user_prompt))
Sorry, I only know about finance.
OpenAI API के साथ Prompt Engineering

अभ्यास करते हैं!

OpenAI API के साथ Prompt Engineering

Preparing Video For Download...