<!DOCTYPE html>
<html>
<head>
    <title>ChatGPT-3.5-16k: 使用OpenAI API进行对话</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f2f2f2;
            margin: 0;
            padding: 20px;
        }
<pre><code>    .container {
        max-width: 800px;
        margin: 0 auto;
    }

    .title {
        color: #333;
        text-align: center;
        margin-bottom: 20px;
    }

    .subtitle {
        color: #333;
        margin-bottom: 10px;
        text-align: center;
    }

    .conversation {
        background-color: #fff;
        border: 1px solid #ccc;
        border-radius: 3px;
        padding: 10px;
        margin-bottom: 20px;
        max-height: 200px;
        overflow-y: auto;
    }

    form {
        margin-bottom: 20px;
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    label {
        display: block;
        margin-bottom: 5px;
        font-weight: bold;
    }

    input[type=&quot;text&quot;],
    input[type=&quot;number&quot;] {
        padding: 5px;
        border: 1px solid #ccc;
        border-radius: 3px;
        width: 250px;
    }

    input[type=&quot;submit&quot;] {
        padding: 8px 15px;
        background-color: #4CAF50;
        color: #fff;
        border: none;
        border-radius: 3px;
        cursor: pointer;
    }

    input[type=&quot;submit&quot;]:hover {
        background-color: #45a049;
    }

    .api-key-form,
    .user-input-form {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 20px;
    }

    .user-input-form input[type=&quot;text&quot;] {
        flex-grow: 1;
        margin-right: 10px;
    }

    .button-group {
        display: flex;
        align-items: center;
    }

    .clear-button {
        background-color: #ff5f5f;
        padding: 8px 15px;
        color: #fff;
        border: none;
        border-radius: 3px;
        cursor: pointer;
    }

    .clear-button:hover {
        background-color: #ff4242;
    }
&lt;/style&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdnjs.cloudflare.com/ajax/libs/bulma/0.9.3/css/bulma.min.css&quot;&gt;
</code></pre>
</head>
<body>
    <section class="section">
        <div class="container">
            <h1 class="title">ChatGPT-3.5-16k: 使用OpenAI API进行对话</h1>
<pre><code>        {% if result %}
            &lt;p&gt;{{ result }}&lt;/p&gt;
        {% endif %}

        &lt;form method=&quot;post&quot; action=&quot;/&quot; class=&quot;api-key-form&quot;&gt;
            &lt;input type=&quot;hidden&quot; name=&quot;action&quot; value=&quot;set_api_key&quot;&gt;
            &lt;div class=&quot;field&quot;&gt;
                &lt;label class=&quot;label&quot; for=&quot;api_key&quot;&gt;OpenAI API密钥:&lt;/label&gt;
                &lt;div class=&quot;control&quot;&gt;
                    &lt;input class=&quot;input&quot; type=&quot;text&quot; id=&quot;api_key&quot; name=&quot;api_key&quot; required&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class=&quot;field&quot;&gt;
                &lt;label class=&quot;label&quot; for=&quot;assistant_message&quot;&gt;角色:&lt;/label&gt;
                &lt;div class=&quot;control&quot;&gt;
                    &lt;input class=&quot;input&quot; type=&quot;text&quot; id=&quot;assistant_message&quot; name=&quot;assistant_message&quot; required&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class=&quot;field&quot;&gt;
                &lt;div class=&quot;control&quot;&gt;
                    &lt;button class=&quot;button is-primary&quot; type=&quot;submit&quot;&gt;设置API密钥和角色&lt;/button&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/form&gt;

        &lt;h2 class=&quot;subtitle&quot;&gt;对话:&lt;/h2&gt;
        &lt;div class=&quot;conversation&quot;&gt;
            {% for message in conversation %}
                &lt;p&gt;{{ message }}&lt;/p&gt;
            {% endfor %}
        &lt;/div&gt;

        &lt;form method=&quot;post&quot; action=&quot;/&quot; class=&quot;user-input-form&quot;&gt;
            &lt;input type=&quot;hidden&quot; name=&quot;action&quot; value=&quot;send_message&quot;&gt;
            &lt;div class=&quot;field&quot;&gt;
                &lt;label class=&quot;label&quot; for=&quot;user_input&quot;&gt;用户输入:&lt;/label&gt;
                &lt;div class=&quot;control&quot;&gt;
                    &lt;input class=&quot;input&quot; type=&quot;text&quot; id=&quot;user_input&quot; name=&quot;user_input&quot; required&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class=&quot;field&quot;&gt;
                &lt;label class=&quot;label&quot; for=&quot;max_tokens&quot;&gt;max_tokens:&lt;/label&gt;
                &lt;div class=&quot;control&quot;&gt;
                    &lt;input class=&quot;input&quot; type=&quot;number&quot; id=&quot;max_tokens&quot; name=&quot;max_tokens&quot; value=&quot;100&quot; required&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class=&quot;field&quot;&gt;
                &lt;label class=&quot;label&quot; for=&quot;temperature&quot;&gt;temperature:&lt;/label&gt;
                &lt;div class=&quot;control&quot;&gt;
                    &lt;input class=&quot;input&quot; type=&quot;number&quot; id=&quot;temperature&quot; name=&quot;temperature&quot; step=&quot;0.01&quot; value=&quot;0.5&quot; required&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class=&quot;field is-grouped&quot;&gt;
                &lt;div class=&quot;button-group&quot;&gt;
                    &lt;div class=&quot;control&quot;&gt;
                        &lt;button class=&quot;button is-primary&quot; type=&quot;submit&quot;&gt;发送&lt;/button&gt;
                    &lt;/div&gt;
                    &lt;div class=&quot;control&quot;&gt;
                        &lt;button class=&quot;button is-danger clear-button&quot; type=&quot;button&quot; onclick=&quot;clearConversation()&quot;&gt;清除对话&lt;/button&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/form&gt;
    &lt;/div&gt;
&lt;/section&gt;

&lt;script&gt;
    function clearConversation() {
        if (confirm('确定要清除对话吗?')) {
            document.querySelector('.conversation').innerHTML = '';
        }
    }
&lt;/script&gt;
</code></pre>
</body>
</html>
ChatGPT-3.5-16k: 使用OpenAI API进行对话

原文地址: https://www.cveoy.top/t/topic/lW4g 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录