BaşlayınÜcretsiz başlayın

Query a Foundation Model

Let's use what we learned about the difference between "SYSTEM" and "USER" Chat Message Roles to send different prompts to the AI agent based on the Chat Message role.

Bu egzersiz, kursun bir parçasıdır

Databricks with the Python SDK

Kursa Göz Atın

Egzersiz talimatları

  • Tell the AI Agent to act like a high school computer science teacher when answering queries using the prompt ai_agent_context.
  • Ask the AI agent when to use For loops using the user_prompt.

Uygulamalı etkileşimli egzersiz

Bu egzersizi bu örnek kodu tamamlayarak deneyin.

from databricks.sdk import WorkspaceClient
from databricks.sdk.service.serving import ChatMessage, ChatMessageRole
w = WorkspaceClient()
user_prompt = "What is a For loop and When should I use it?"
ai_agent_context = "You are a high school computer science teacher"
response = w.serving_endpoints.query(
    name="databricks-meta-llama-3-3-70b-instruct",
    messages=[
        ChatMessage( 
          	# Tell the AI Agent to act like a high school computer science teacher when answering queries
            role=ChatMessageRole.SYSTEM, content=____
        ),
        ChatMessage( 
          	# Ask the AI agent when to use For loops
            role=ChatMessageRole.USER, content=____
        ),
    ],
    max_tokens=250)
print(f"RESPONSE:\n{response.choices[0].message.content}")
Kodu Düzenle ve Çalıştır