टेक्स्ट का सारांश और संपादन

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

James Chapman

Curriculum Manager, DataCamp

रिकैप...

  • प्रश्न-उत्तर
response = client.chat.completions.create(
  model="gpt-4o-mini",
  messages=[{"role": "user", "content": "How many days are in October?"}]
)

print(response.choices[0].message.content)
October has 31 days.
OpenAI API के साथ काम करना

टेक्स्ट संपादन

  • उदाहरण: नाम, सर्वनाम, और जॉब टाइटल अपडेट करना

$$

prompt = """
Update name to Maarten, pronouns to he/him, and job title to Senior Content Developer
in the following text:

Joanne is a Content Developer at DataCamp. Her favorite programming language is R,
which she uses for her statistical analyses.
"""
OpenAI API के साथ काम करना

टेक्स्ट संपादन

response = client.chat.completions.create(
    model="gpt-4o-mini",

messages=[{"role": "user", "content": prompt}]
) print(response.choices[0].message.content)
Maarten is a Senior Content Developer at DataCamp. His favorite programming language
is R, which he uses for his statistical analyses.
OpenAI API के साथ काम करना

टेक्स्ट सारांशण

  • उदाहरण: कस्टमर चैट ट्रांसक्रिप्ट्स का सारांश

कस्टमर सपोर्ट टीम

text = """
Customer: Hi, I'm trying to log into 
my account, but it keeps saying 
my password is incorrect. I'm sure 
I'm entering the right one.  

Support: I'm sorry to hear that! 
Have you tried resetting your password?  
...
"""
OpenAI API के साथ काम करना

टेक्स्ट सारांशण

prompt = f"""Summarize the customer support chat 
             in three concise key points: {text}"""


response = client.chat.completions.create( model="gpt-4o-mini", messages=[{"role": "user", "content": prompt}] ) print(response.choices[0].message.content)
1. Customer couldn't log in due to a password issue and missing reset link.  
2. Support resent the reset email after confirming it was sent.  
3. Customer resolved the issue by using Google sign-in.
OpenAI API के साथ काम करना

रिस्पॉन्स की लंबाई नियंत्रित करना

  • max_completion_tokens = 5
response = client.chat.completions.create(
  model="gpt-4o-mini",
  messages=[{"role": "user", 
  "content": "Write a haiku about AI."}],
  max_completion_tokens=5
)

AI so powerful
Computers
  • max_completion_tokens = 30
response = client.chat.completions.create(
  model="gpt-4o-mini",
  messages=[{"role": "user", 
  "content": "Write a haiku about AI."}],
  max_completion_tokens=30
)

A machine mind thinks
Logic dictates its choices
Mankind ponders anew
OpenAI API के साथ काम करना

टोकन समझना

$$

  • टोकन: टेक्स्ट की इकाइयाँ, जो AI को समझने और व्याख्या में मदद करती हैं

$$

वाक्य, "How can the OpenAI API deliver business value?" जिसमें हर टोकन अलग रंग में हाइलाइट है.

1 https://platform.openai.com/tokenizer
OpenAI API के साथ काम करना

लागत की गणना

 

  • उपयोग लागत model और tokens की संख्या पर निर्भर करती है 💰

    • मॉडल्स की कीमत cost/tokens के हिसाब से होती है
    • इनपुट और आउटपुट टोकन की लागत अलग हो सकती है
  • max_completion_tokens बढ़ाने से लागत बढ़ती है 📈

Screenshot 2025-03-05 at 11.46.54.png

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

लागत की गणना

prompt = f"""Summarize the customer support chat 
             in three concise key points: {text}"""

max_completion_tokens = 500

response = client.chat.completions.create(
  model="gpt-4o-mini",
  messages=[{"role": "user", "content": prompt}], 
  max_completion_tokens=max_completion_tokens
  )

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

लागत की गणना

# Define price per token
input_token_price = 0.15 / 1_000_000
output_token_price = 0.6 / 1_000_000

# Extract token usage input_tokens = response.usage.prompt_tokens
output_tokens = max_completion_tokens
# Calculate cost cost = (input_tokens * input_token_price + output_tokens * output_token_price) print(f"Estimated cost: ${cost}")
Estimated cost: $0.00124
1 https://openai.com/pricing
OpenAI API के साथ काम करना

अभ्यास करते हैं!

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

Preparing Video For Download...