Bir MCP Sunucu İstemi Tanımlama
Bir LLM'in dönüşüm isteklerini nasıl ele alacağını ve ne zaman netleştirme isteyeceğini (ör. eksik tutar veya para birimi kodları) bilmesi için döviz dönüştürücü MCP sunucuna yeniden kullanılabilir bir istem ekliyorsun. Bu, kullanıcıların üzerine binen istem yükünü azaltır ve asistanı daha güvenilir kılar.
Bir MCP sunucu örneği zaten oluşturuldu. @mcp.prompt() dekoratörünü ve kullanıcının isteğini ekleyerek istem şablonunu döndüren bir fonksiyonu kullanarak bir istem ekle.
Bu egzersiz, kursun bir parçasıdır
Model Context Protocol (MCP) Giriş
Egzersiz talimatları
- Bir fonksiyonu
@mcp.prompt()ile dekore et ve başlığı"Currency Conversion"olarak ayarla. currency_request: stralan ve istem şablonunu kullanıcının isteğiyle birlikte döndüren bir fonksiyon tanımla.- İstem fonksiyonunu örnek bir istekle çağır ve çalıştığını doğrulamak için sonucu yazdır.
Uygulamalı etkileşimli egzersiz
Bu egzersizi bu örnek kodu tamamlayarak deneyin.
# Define a prompt for currency conversion
____
def ____(currency_request: str) -> str:
return f"""You are a currency conversion assistant.
Your task is to:
1. Extract the amount and source currency from the user's natural language input.
2. Identify the target currency.
3. Use the conversion tool to convert the amount.
Rules:
- If the amount or currencies are ambiguous or missing, ask the user for clarification.
- Use only supported currency codes (e.g., USD, EUR, GBP).
User's currency conversion request: {currency_request}"""
# Test the prompt function
print(____("100 USD to EUR"))