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

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


以下是一個簡單的接入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 問答演示</h2>
        <input type="text" id="questionInput" placeholder="輸入您的問題...">
        <button onclick="askDeepSeek()">提問</button>
        <div id="result"></div>
    </div>

    <script>
        // 替換為您的實際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('請輸入問題');
                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ù)實際模型修改
                        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 = `錯誤:${data.error.message}`;
                }
            } catch (error) {
                resultDiv.innerHTML = `請求失。${error.message}`;
            }
        }
    </script>
</body>
</html>



重要說明:

  1. 需要替換的內(nèi)容:

  •  YOUR_DEEPSEEK_API_KEY 替換為您實際的API密鑰


api密鑰訪問,以下網(wǎng)址進(jìn)行獲取https://www.deepseek.com,打開網(wǎng)址選擇”api開放平臺“
如下圖所示






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