最近deepseek火遍全球。有人會(huì)想到如果是直接做一個(gè)簡(jiǎn)單的h5頁(yè)面就可以進(jìn)行提問(wèn),不需要deepseek訪問(wèn)網(wǎng)站或app,如何做到呢?以下是展示的效果和代碼
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>DeepSeek接入示例</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
.container {
border: 1px solid #e0e0e0;
border-radius: 8px;
padding: 20px;
margin-top: 20px;
}
input, button {
padding: 10px;
margin: 5px;
border-radius: 4px;
}
input {
width: 70%;
border: 1px solid #ddd;
}
button {
background-color: #007bff;
color: white;
border: none;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
#result {
margin-top: 20px;
padding: 15px;
border: 1px solid #eee;
border-radius: 4px;
min-height: 100px;
}
.loading {
color: #666;
font-style: italic;
}
</style>
</head>
<body>
<div class="container">
<h2>DeepSeek 問(wèn)答演示</h2>
<input type="text" id="questionInput" placeholder="輸入您的問(wèn)題...">
<button onclick="askDeepSeek()">提問(wèn)</button>
<div id="result"></div>
</div>
<script>
// 替換為您的實(shí)際API密鑰
const API_KEY = 'YOUR_DEEPSEEK_API_KEY';
const API_URL = 'https://api.deepseek.com/v1/chat/completions'; // 假設(shè)的API地址
async function askDeepSeek() {
const question = document.getElementById('questionInput').value;
const resultDiv = document.getElementById('result');
if (!question) {
alert('請(qǐng)輸入問(wèn)題');
return;
}
resultDiv.innerHTML = '<div class="loading">思考中...</div>';
try {
const response = await fetch(API_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${API_KEY}`
},
body: JSON.stringify({
model: "deepseek-chat", // 根據(jù)實(shí)際模型修改
messages: [{
role: "user",
content: question
}]
})
});
const data = await response.json();
if (response.ok) {
const answer = data.choices[0].message.content;
resultDiv.innerHTML = `<strong>答案:</strong>${answer}`;
} else {
resultDiv.innerHTML = `錯(cuò)誤:${data.error.message}`;
}
} catch (error) {
resultDiv.innerHTML = `請(qǐng)求失。${error.message}`;
}
}
</script>
</body>
</html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>DeepSeek接入示例</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
.container {
border: 1px solid #e0e0e0;
border-radius: 8px;
padding: 20px;
margin-top: 20px;
}
input, button {
padding: 10px;
margin: 5px;
border-radius: 4px;
}
input {
width: 70%;
border: 1px solid #ddd;
}
button {
background-color: #007bff;
color: white;
border: none;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
#result {
margin-top: 20px;
padding: 15px;
border: 1px solid #eee;
border-radius: 4px;
min-height: 100px;
}
.loading {
color: #666;
font-style: italic;
}
</style>
</head>
<body>
<div class="container">
<h2>DeepSeek 問(wèn)答演示</h2>
<input type="text" id="questionInput" placeholder="輸入您的問(wèn)題...">
<button onclick="askDeepSeek()">提問(wèn)</button>
<div id="result"></div>
</div>
<script>
// 替換為您的實(shí)際API密鑰
const API_KEY = 'YOUR_DEEPSEEK_API_KEY';
const API_URL = 'https://api.deepseek.com/v1/chat/completions'; // 假設(shè)的API地址
async function askDeepSeek() {
const question = document.getElementById('questionInput').value;
const resultDiv = document.getElementById('result');
if (!question) {
alert('請(qǐng)輸入問(wèn)題');
return;
}
resultDiv.innerHTML = '<div class="loading">思考中...</div>';
try {
const response = await fetch(API_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${API_KEY}`
},
body: JSON.stringify({
model: "deepseek-chat", // 根據(jù)實(shí)際模型修改
messages: [{
role: "user",
content: question
}]
})
});
const data = await response.json();
if (response.ok) {
const answer = data.choices[0].message.content;
resultDiv.innerHTML = `<strong>答案:</strong>${answer}`;
} else {
resultDiv.innerHTML = `錯(cuò)誤:${data.error.message}`;
}
} catch (error) {
resultDiv.innerHTML = `請(qǐng)求失。${error.message}`;
}
}
</script>
</body>
</html>
重要說(shuō)明:
-
需要替換的內(nèi)容:
-
將
YOUR_DEEPSEEK_API_KEY
替換為您實(shí)際的API密鑰
api密鑰訪問(wèn),以下網(wǎng)址進(jìn)行獲取https://www.deepseek.com,打開(kāi)網(wǎng)址選擇”api開(kāi)放平臺(tái)“
如下圖所示


承擔(dān)因您的行為而導(dǎo)致的法律責(zé)任,
本站有權(quán)保留或刪除有爭(zhēng)議評(píng)論。
參與本評(píng)論即表明您已經(jīng)閱讀并接受
上述條款。