By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Chatgpt Teacher Reports


New Coder
I've been trialling using chatgpt to make a simple program to create reports for teachers. I enter my report and leave a @ for the name and the software replaces it with an alternative name. There is also room for additional sentences underneath. The report can then be sent to chatgpt to be reworded. Unfortunately, I'm getting a 404 error when it's reworded. Any ideas?

<!DOCTYPE html>
  <title>Student Report</title>
  <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    const API_URL = 'https://api.openai.com/v1/completions';
    const API_KEY = ''; // Replace with your actual API key

    async function updateReport() {
      var studentName = document.getElementById('studentName').value;

      // Update report text
      var reportTextElement = document.getElementById('reportText');
      var reportText = reportTextElement.innerHTML;
      var updatedReportText = reportText.replace(/@/g, studentName);
      reportTextElement.innerHTML = updatedReportText;

      // Update report comments
      var reportCommentsElement = document.getElementById('reportComments');
      var reportComments = reportCommentsElement.value;
      var updatedReportComments = reportComments.replace(/@/g, studentName);
      reportCommentsElement.value = updatedReportComments;

      // Update word count
      var wordCount = updatedReportComments.trim().split(/\s+/).length;
      document.getElementById('wordCount').innerHTML = "Word Count: " + wordCount;

    async function rewordReport() {
      var reportText = document.getElementById('reportText').innerText;

      // Send request to ChatGPT API for rewording
      var response = await axios.post(API_URL, {
        messages: [{ role: 'system', content: 'You are a student.' }, { role: 'user', content: reportText }],
        max_tokens: 50,
        temperature: 0.8
      }, {
        headers: {
          'Authorization': 'Bearer ' + API_KEY,
          'Content-Type': 'application/json'

      var rewordedReport = response.data.choices[0].message.content;

      var rewordedReportElement = document.getElementById('rewordedReport');
      rewordedReportElement.innerHTML = rewordedReport;

    function addOptionalSentence() {
      var sentence = document.getElementById('optionalSentence').value;
      var reportCommentsElement = document.getElementById('reportComments');
      var currentComments = reportCommentsElement.value;
      var updatedComments = currentComments + ' ' + sentence;
      reportCommentsElement.value = updatedComments;

    function createOptionalSentenceInput() {
      var optionalSentencesContainer = document.getElementById('optionalSentencesContainer');
      var inputContainer = document.createElement('div');
      var sentenceInput = document.createElement('input');
      sentenceInput.type = 'text';
      sentenceInput.className = 'optional-sentence-input';
      sentenceInput.placeholder = 'Enter optional sentence';
      var addButton = document.createElement('button');
      addButton.innerText = 'Add Sentence';
      addButton.className = 'add-sentence-button';
      addButton.onclick = addOptionalSentence;
  <script src="https://cdn.jsdelivr.net/npm/@grammarly/extension/dist/extension.js"></script>
    .optional-sentence-input {
      width: 400px;
  <h1>Student Report</h1>

    <p id="reportText">This report is about the student @. Please review the student's performance.</p>

    <label for="studentName">Student Name: </label>
    <input type="text" id="studentName" />
    <button onclick="updateReport()">Refresh</button>

    <label for="reportComments">Report Comments:</label><br>
    <textarea id="reportComments" rows="4" cols="50" data-gramm_editor="false"></textarea>

    <p id="wordCount"></p>

    <button onclick="rewordReport()">Reword Report</button>

    <h3>Original Report:</h3>
    <p id="reportText"></p>

    <h3>Reworded Report:</h3>
    <p id="rewordedReport"></p>

    <h3>Optional Sentences:</h3>
    <div id="optionalSentencesContainer">
        <input type="text" class="optional-sentence-input" placeholder="Enter optional sentence">
        <button class="add-sentence-button" onclick="addOptionalSentence()">Add Sentence</button>
    <button onclick="createOptionalSentenceInput()">Add Sentence Box</button>

    const grammarly = new Grammarly(window);
Ensure that your API key is correctly provided and that you are using the correct API endpoint. I'll provide you with a modified version of your rewordReport function that includes the logic for making the API request using Axios:

async function rewordReport() {
var reportText = document.getElementById('reportText').innerText;

try {
const response = await axios.post(API_URL, {
model: 'text-davinci-002', // You can change the model based on your preference
prompt: reportText,
temperature: 0.7, // Adjust temperature as needed
max_tokens: 150, // Adjust max_tokens as needed
}, {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${API_KEY}`,

var rewordedReport = response.data.choices[0].text;

// Update the report text with the reworded version
document.getElementById('reportText').innerText = rewordedReport;

} catch (error) {
console.error('Error rewording report:', error);

// Handle the error here, e.g., display an error message to the user

Make sure to replace 'Your-API-Key' with your actual OpenAI GPT-3 API key. Also, ensure that the model, temperature, and max_tokens parameters are set according to your preferences.
Additionally, make sure that your API key has the necessary permissions to make requests to the GPT-3 API. If the issue persists, double-check your API key and ensure that your internet connection is stable.

New Threads

Latest posts

Buy us a coffee!

Top Bottom