AI Engineered forYourBusiness
Your
Business
Custom built generative AI software solutions for businesses.
Get a free consultation on your project today.
chatgpt_api.py
ai_response.py
import openai
# Initialize the OpenAI API client
openai.api_key = "your-api-key-here"
# Define a function to call the ChatGPT API
def ask_chatgpt(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=150
)
return response.choices[0].text.strip()
# Example usage
answer = ask_chatgpt("How does generative AI work?")
print(answer)