File size: 471 Bytes
2f43169
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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)