Thanks so much! I'm still new to JavaScript and putting together a separate XLM file is a bit above my head. I'll talk to tech. It would be better to have more control over it. Thank you for the script. I'll try it. Here's what I (and ChatGPT) came up with:
// Step 1: Capture the learner's SMART goal from the Storyline variable
var player = GetPlayer();
var userGoal = player.GetVar("GoalText"); // Replace 'GoalText' with the actual variable name in Storyline
// Step 2: OpenAI API setup
const apiKey = 'myKey'; // Replace this with your OpenAI API key once you have it
const apiUrl = 'https://api.openai.com/v1/chat/completions';
// Step 3: Prepare the data to send to OpenAI
const data = {
model: "gpt-4", // Model can be gpt-3.5-turbo or gpt-4 depending on your API access
messages: [
{
role: "system",
content: "You are an assistant that helps users write SMART goals. Provide feedback on Specific, Measurable, Achievable, Relevant, and Time-bound aspects of the goal. Please be succinct and ensure you can answer fully with the 500 max_limit tokens. Include a concise summary of your conclusions with a rating score of 1-5, with 5 being the highest quality."
},
{
role: "user",
content: `Here is the SMART goal: "${userGoal}". Please analyze and provide feedback on it.`
}
],
max_tokens: 500, // Limit the response length to avoid using too many tokens
temperature: 0.7 // Adjusts the creativity of the response (0.7 is a good balance)
};
// Step 4: Send the API request to OpenAI
fetch(apiUrl, {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.then(response => response.json())
.then(data => {
// Step 5: Handle the response and set it to a Storyline variable
if (data && data.choices && data.choices.length > 0) {
var feedback = data.choices[0].message.content.trim(); // Extract feedback from the response
player.SetVar("AI_Feedback", feedback); // Store the feedback in a Storyline variable
} else {
player.SetVar("AI_Feedback", "No valid feedback received."); // In case no feedback is returned
}
})
.catch(error => {
console.error("Error:", error);
player.SetVar("AI_Feedback", "There was an error connecting to the AI service.");
});
It's geared towards mentoring about a specific topic. I'd like to embed a chatbot that users can access on any page of the course and ask questions about the content. That's a much different animal.