शुरू करेंमुफ़्त में शुरू करें

क्लाइंट से प्रॉम्प्ट प्राप्त करना

अब करेंसी सर्वर से एक विशेष प्रॉम्प्ट यूज़र इनपुट के साथ प्राप्त करें, ताकि टेम्पलेट और यूज़र का रिक्वेस्ट मिलकर तैयार हो जाए. यही वह टेक्स्ट है जिसे आप LLM को देंगे, इससे पहले कि वह तय करे कि कन्वर्ज़न टूल कॉल करना है या नहीं.

यह अभ्यास पाठ्यक्रम का हिस्सा है

Model Context Protocol (MCP) परिचय

पाठ्यक्रम देखें

अभ्यास निर्देश

  • सेशन इनिशियलाइज़ करने के बाद, नाम से प्रॉम्प्ट लाने वाली मेथड कॉल करें. प्रॉम्प्ट का नाम और यूज़र इनपुट वाला arguments dict पास करें.
  • प्रॉम्प्ट रिज़ल्ट में पहली मैसेज की टेक्स्ट सामग्री निकालें और प्रिंट करें.

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client

async def read_prompt(user_input: str = "How much is 50 GBP in euros?", prompt_name: str = "convert_currency_prompt") -> str:
    """Retrieve a prompt from the MCP server with user input."""
    params = StdioServerParameters(command=sys.executable, args=["currency_server.py"])

    async with stdio_client(params) as (reader, writer):
        async with ClientSession(reader, writer) as session:
            await session.initialize()

            # Retrieve the prompt with the user's input
            prompt = await session.____(prompt_name, arguments={"currency_request": user_input})

            # Print the full prompt text (template + user request)
            text = prompt.____[0].____.____
            print(text)
            return text

asyncio.run(read_prompt(user_input="How much is 50 GBP in euros?"))
कोड संपादित करें और चलाएँ