Çift istemli get_response() fonksiyonu oluşturma
Aşağıdaki egzersizler, OpenAI API'sinin chat.completions uç noktasını iki istemle (bir sistem istemi ve bir kullanıcı istemi) çağırmaya dayanır. Buna hazırlanmak için, bu egzersizde iki istemi girdi olarak alan (system_prompt ve user_prompt) ve yanıtı çıktı olarak döndüren çift istemli bir get_response() fonksiyonu oluşturacaksın. Ardından bu fonksiyonu seçtiğin herhangi bir örneğe uygulayacaksın.
OpenAI paketi senin için önceden yüklendi.
Bu egzersiz, kursun bir parçasıdır
OpenAI API ile Prompt Engineering
Egzersiz talimatları
messageslistesinde her mesajın rolünü ve içeriğini ata.- Seçtiğin bir
system_promptveuser_promptvererek fonksiyonu dene.
Uygulamalı etkileşimli egzersiz
Bu egzersizi bu örnek kodu tamamlayarak deneyin.
client = OpenAI(api_key="")
def get_response(system_prompt, user_prompt):
# Assign the role and content for each message
messages = [{"role": ____, "content": ____},
{"role": ____, "content": ____}]
response = client.chat.completions.create(
model="gpt-4o-mini", messages= messages, temperature=0)
return response.choices[0].message.content
# Try the function with a system and user prompts of your choice
response = get_response("____", "____")
print(response)