Open_AI_o1_Hackathon / utils /openai_utils.py
Ashar086's picture
Create utils/openai_utils.py
2f43169 verified
raw
history blame
471 Bytes
import openai
# Set your OpenAI API key
openai.api_key = "your-openai-api-key"
def call_openai(prompt, max_tokens=150):
response = openai.Completion.create(
model="text-davinci-003",
prompt=prompt,
max_tokens=max_tokens
)
return response['choices'][0]['text']
def get_ai_explanation(question):
prompt = f"Explain the following machine learning concept in simple terms: {question}"
return call_openai(prompt, max_tokens=150)