Change text davinci to chatgpt 3.5

// Handle form submit for essay generation
document.querySelector(‘form#essay1’).addEventListener(‘submit’, 生成作文);

async function submit(e) {

e.preventDefault();

// Get form values
const topic = document.querySelector(‘#topic’).value;
const length = document.querySelector(‘#length’).value;

// Call OpenAI API
let response;
if (length === ‘short’) {
response = await fetch(‘’, {
method: ‘POST’,
headers: {
‘Authorization’: Bearer ${mySecret},
‘Content-Type’: ‘application/json’
},
body: JSON.stringify({
prompt: write a whole complete essay in about 80 word about ${topic},
max_tokens: 4000
})
});
} else if (length === ‘long’) {
response = await fetch(‘’, {
method: ‘POST’,
headers: {
‘Authorization’: Bearer ${mySecret},
‘Content-Type’: ‘application/json’
},
body: JSON.stringify({
prompt: write a whole complete essay at least 120 word about ${topic},
max_tokens: 4000
})
});
}

const data = await response.json();

// Get generated text
const essayText = data.choices[0].text;

// Get word count
const wordCount = essayText.split(’ ').length;

// Update HTML
document.querySelector(‘#essay-count’).innerHTML = ${wordCount} words;
document.querySelector(‘#essay-text’).innerHTML = essayText;

}

It is advisable to include a textual question with code. as far as i can understand you want to change the model to GPT 3.5. Am i correct?

1 Like

The question is in the prompt,this is a website a user type the topic to generate essay.
Yes,i want to change to chatgpt 3.5.

The first part that must be changed is the “prompt”. The new way to send language to the AI with chat completions endpoint is “messages”

prompt: write a whole complete essay at least 120 word about ${topic}

messages: [{"role": "user", "content": "write a whole complete essay in about 80 word about ${topic}"}],

Then the new endpoint must be used elsewhere in the code:

https://api.openai.com/v1/chat/completions

You can read documents about the changes, and best practices for sending multiple messages or a system programming message.

API Reference

2 Likes

To access the “gpt-3.5-turbo” model, you should utilize the following API endpoint: https://api.openai.com/v1/chat/completions.

1 Like