
如有疑问或者交流问题请加:QQ 2137087126
1:首先注册申请API KEY https://platform.openai.com/
2:代码中填入申请好的KEY 即可使用
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script>
function sendRequest() {
// Get the prompt from the user
var prompt = $("#prompt").val();
// API endpoint for OpenAI
var url = "https://api.openai.com/v1/engines/text-davinci-003/completions";
// API Key for OpenAI
var apiKey = "YOUR API KEY";
// Data to be sent in the request
var data = {
prompt: prompt,
max_tokens: 100,
temperature: 0.5
};
// Headers for the request
var headers = {
"Content-Type": "application/json",
"Authorization": "Bearer " + apiKey
};
// Make the request to the OpenAI API
$.ajax({
type: "POST",
url: url,
data: JSON.stringify(data),
headers: headers,
success: function(response) {
// Get the response from the API
$("#response").html(response.choices[0].text);
}
});
}
</script>
</head>
<body>
<div class="container">
<h1 class="text-center mt-5">OpenAI Chatbot</h1>
<div class="row mt-5">
<div class="col-md-6 offset-md-3">
<div class="form-group">
<input type="text" id="prompt" class="form-control">
</div>
<button class="btn btn-primary btn-block" onclick="sendRequest()">Submit</button>
<div class="form-group mt-3">
<div id="response" class="form-control" style="min-height: 100px;"></div>
</div>
</div>
</div>
</div>
</body>
</html>


