Hey friends!
Newbie to all of this here. I’m writing a test script to accept a prompt, then output results in a text box. However the results I’m getting seem to just be fragments of conversations, instead of actual results.
Example:
Prompt = “Can you make me a simple meal plan for a vegan for 2 days?”
Result = “I am a vegan and I want to lose weight. I am not sure what to eat. Can you tell me what to eat and what not to eat? I am a vegan and I want to lose weight. I am not sure what to eat. Can you tell me what to eat and what”
I guess using ChatGPT, I’d expect an output of an actual meal plan…but maybe I’m completely misunderstanding everything. Any advice? My simple test code is down below. Thank you!
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ChatGPT Example</title>
</head>
<body>
<h1>ChatGPT Example</h1>
<label for="prompt">Enter a prompt:</label>
<input type="text" id="prompt" name="prompt">
<button onclick="getResponse()">Ask ChatGPT</button>
<br>
<label for="response">Response:</label>
<textarea id="response" name="response" rows="5" cols="40"></textarea>
<script>
const API_ENDPOINT = 'https://api.openai.com/v1/engines/davinci/completions';
const API_KEY = 'REDACTED';
function getResponse() {
const prompt = document.getElementById('prompt').value;
const data = {
prompt: prompt,
max_tokens: 64,
temperature: 0.5,
n: 1,
stop: null,
};
fetch(API_ENDPOINT, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${API_KEY}`,
},
body: JSON.stringify(data),
}).then(response => response.json()).then(response => {
const text = response.choices[0].text;
document.getElementById('response').value = text;
}).catch(error => {
console.log(error);
});
}
</script>
</body>
</html>```