Prompt Engineering dengan OpenAI API
Fouad Trad
Machine Learning Engineer




response = client.chat.completions.create( model="gpt-3.5-turbo", 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)
Bayangkan Anda memberi instruksi ke program komputer, seperti mengajari robot membuat sandwich.
Prompt engineering adalah menyusun instruksi, atau "prompt," agar komputer memahami dan menjalankan tugas dengan lebih baik.
def get_response(prompt): messages = [ {"role": "user", "content": prompt} ] response = client.chat.completions.create( model="gpt-3.5-turbo", messages=messages, temperature=0, ) return response.choices[0].message.contentprompt = "<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-3.5-turbo", messages=messages, temperature=0, ) return response.choices[0].message.contentsystem_prompt = "<SYSTEM_PROMPT>" user_prompt = "<USER_PROMPT>" print(get_response(system_prompt, user_prompt))
system_prompt = "You are a chatbot that answers financial questions."user_prompt = "Who are you?" print(get_response(system_prompt, user_prompt))
Saya chatbot keuangan yang menjawab pertanyaan finansial. Ada yang bisa saya bantu?
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))
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 [...]
system_prompt = """You are a chatbot that answers financial questions.
Your answers should be precise, formal and objective.
"""
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.
"""
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))
Maaf, saya hanya tahu tentang keuangan.
Prompt Engineering dengan OpenAI API