接入deepseek的html代碼下載
發(fā)布時(shí)間:2025-02-13 11:58 [ 我要自學(xué)網(wǎng)原創(chuàng) ] 發(fā)布人: samohu 閱讀: 557

最近deepseek火遍全球。有人會(huì)想到如果是直接做一個(gè)簡(jiǎn)單的h5頁(yè)面就可以進(jìn)行提問(wèn),不需要deepseek訪問(wèn)網(wǎng)站或app,如何做到呢?以下是展示的效果和代碼


以下是一個(gè)簡(jiǎn)單的接入DeepSeek服務(wù)的HTML代碼示例,包含基礎(chǔ)的API調(diào)用和界面交互:

<!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>



重要說(shuō)明:

  1. 需要替換的內(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)“
如下圖所示






HTML基礎(chǔ)視頻教程
我要自學(xué)網(wǎng)商城 ¥30 元
進(jìn)入購(gòu)買(mǎi)
文章評(píng)論
0 條評(píng)論 按熱度排序 按時(shí)間排序 /350
添加表情
遵守中華人民共和國(guó)的各項(xiàng)道德法規(guī),
承擔(dān)因您的行為而導(dǎo)致的法律責(zé)任,
本站有權(quán)保留或刪除有爭(zhēng)議評(píng)論。
參與本評(píng)論即表明您已經(jīng)閱讀并接受
上述條款。
V
特惠充值
聯(lián)系客服
APP下載
官方微信
返回頂部
分類選擇:
電腦辦公 平面設(shè)計(jì) 室內(nèi)設(shè)計(jì) 室外設(shè)計(jì) 機(jī)械設(shè)計(jì) 工業(yè)自動(dòng)化 影視動(dòng)畫(huà) 程序開(kāi)發(fā) 網(wǎng)頁(yè)設(shè)計(jì) 會(huì)計(jì)課程 興趣成長(zhǎng) AIGC