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

Find and replace

Find-and-replace टूल दशकों से मौजूद हैं, लेकिन वे अक्सर सिर्फ़ बिल्कुल मिलते-जुलते शब्दों या वाक्यांशों को पहचानने और बदलने तक सीमित रहते हैं. आपको कारों पर चर्चा करता हुआ एक टेक्स्ट-ब्लॉक दिया गया है, और आप एक chat completion मॉडल का उपयोग करके उसी टेक्स्ट को प्लेन्स पर चर्चा करने के लिए अपडेट करेंगे, जहाँ ज़रूरत हो वहाँ सामग्री को उचित रूप से बदलते हुए.

चेतावनी: अगर आप कम समय में बहुत सारी रिक्वेस्ट भेजते हैं या बहुत ज़्यादा टोकन इस्तेमाल करते हैं, तो आप अपने rate limit से टकरा सकते हैं और openai.error.RateLimitError दिख सकता है. अगर यह त्रुटि दिखे, तो कृपया एक मिनट रुकें ताकि आपका कोटा रीसेट हो जाए; उसके बाद आप फिर से रिक्वेस्ट भेजना शुरू कर पाएँगे.

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

OpenAI API के साथ काम करना

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

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

  • Chat Completions endpoint को एक रिक्वेस्ट बनाएँ; अधिकतम 100 टोकन का उपयोग करें.
  • API से टेक्स्ट रेस्पॉन्स निकालें और उसे प्रिंट करें.

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

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

client = OpenAI(api_key="")

prompt="""Replace car with plane and adjust phrase:
A car is a vehicle that is typically powered by an internal combustion engine or an electric motor. It has four wheels, and is designed to carry passengers and/or cargo on roads or highways. Cars have become a ubiquitous part of modern society, and are used for a wide variety of purposes, such as commuting, travel, and transportation of goods. Cars are often associated with freedom, independence, and mobility."""

# Create a request to the Chat Completions endpoint
response = client.chat.completions.create(
  model="gpt-4o-mini",
  messages=[{"role": "user", "____": ____}],
  ____
)

# Extract and print the response text
print(response.choices[0].____.____)
कोड संपादित करें और चलाएँ