Today was all about working with APIs. I learned how to integrate AI services into applications using APIs. I used the OpenAI API to generate text completions and the Google Cloud Vision API for image analysis.
This hands-on experience showed me how powerful pre-built AI services can be, allowing developers to add AI capabilities to their applications without building models from scratch.
import openai
# Set up your API key
openai.api_key = 'your-api-key-here'
def generate_text(prompt):
response = openai.Completion.create(
engine="text-davinci-002",
prompt=prompt,
max_tokens=100
)
return response.choices[0].text.strip()
# Example usage
prompt = "Write a short story about a robot learning to paint:"
generated_text = generate_text(prompt)
print(generated_text)
Top comments (0)