Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ REACT_APP_SENTRY_DSN=''
REACT_APP_SENTRY_ENV='local'
PUBLIC_URL='http://localhost:3011'
ASSETS_URL='http://localhost:3011'
REACT_APP_GEMINI_API_KEY=''
REACT_APP_GOOGLE_TAG_MANAGER_ID=''
REACT_APP_API_ENDPOINT='http://localhost:3009'
REACT_APP_PLAUSIBLE_DATA_DOMAIN=''
Expand Down
53 changes: 53 additions & 0 deletions src/utils/aiClient.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* List available Gemini models for the given API key.
* @param {string} apiKey - Your Gemini API key
* @returns {Promise<Object>} The response from the ListModels endpoint
*/
export async function listGeminiModels(apiKey) {
const url = "https://generativelanguage.googleapis.com/v1beta/models";
const response = await fetch(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
"x-goog-api-key": apiKey,
},
});
if (!response.ok) {
throw new Error(
`ListModels failed: ${response.status} ${response.statusText}`,
);
}
return response.json();
}
// src/utils/aiClient.js

// Helper utility to connect to Gemini (Google AI) and send a request. Easily swappable for other models.
export async function sendGeminiRequest({
prompt,
apiKey,
model = "gemini-2.5-pro",
options = {},
}) {
const url = `https://generativelanguage.googleapis.com/v1beta/models/${model}:generateContent`;
const body = {
contents: [{ parts: [{ text: prompt }] }],
...options,
};
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-goog-api-key": apiKey,
},
body: JSON.stringify(body),
});
if (!response.ok) {
throw new Error(
`AI request failed: ${response.status} ${response.statusText}`,
);
}
const data = await response.json();
return data;
}

// To switch models, just change the 'model' argument or the API URL logic above.
15 changes: 15 additions & 0 deletions src/utils/prompts/propose_solution_prompt.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
You are an expert computer science teacher and will be given a student task and piece of student python code written in response to the task.

You will return a correct solution to the task based on the student's code in the form of a git diff, making as few changes to the student code as possible.

Don't change the whitespace unless necessary for the code to run.

You will also provide an explanation of why the student needs to make the changes to fulfil the task. The explanation must not be longer than 30 words.

Task:

{{task}}

Student code:

{{student_code}}
Loading