chatgpt安装

当前位置: 主页 > chatgpt安装

深度揭秘(赓续怎么读)赓续精神血脉,传承红色基因,(续)chatgpt怎么构建web页面聊天,

时间:2023-04-24 21:58:25|栏目:chatgpt安装|点击:

是不是把chatgpt加装到他们笔记本电脑上一则该文早已听完,没想的好友能先看完,第一集接著讲把chatgpt加装好了,不该在旧版本框闲聊,我做了两个单纯的网页web闲聊操作方式如下表所示:

1) 具体来说你要在却是别的产品目录的配置文档里头增建两个重新命名为templates配置文档,和两个app.txt文档格式,

关上app.txt黏贴下列标识符留存:

from flask import Flask, render_template, request, jsonify

from generate_response import generate_response

app = Flask(__name__)

@app.route(/, methods=[GET, POST])

def index():

if request.method == POST:

user_input = request.form[user_input]

generated_response = generate_response(user_input)

# 将聚合的积极响应传达给后端

return jsonify(response=generated_response)

return render_template(index.html)

if __name__ == __main__:

app.run(debug=True)

接着把app.txt文档前缀换成.py,变为app.py

2)再在app.py同产品目录下增建两个generate_response.py文档,老规矩,先建成文档格式txt格式,黏贴下列标识符后,前缀再换成 .py

import openai

openai.api_key = "用你的OpenAI API密钥替换这里"

def generate_response(user_input):

prompt = f"与用户闲聊: {user_input}"

response = openai.Completion.create(

engine="text-davinci-002",

prompt=prompt,

max_tokens=3000,

n=1,

stop=None,

temperature=0.3,

top_p=0.5, # 采样概率阈值

)

message = response.choices[0].text.strip()

return message

3) 关上templates配置文档,接着增建两个index.txt文档格式文档,关上后黏贴下列标识符留存:

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta http-equiv="X-UA-Compatible" content="IE=edge">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>AI Chatbot</title>

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">

<style>

body {

display: flex;

flex-direction: column;

min-height: 100vh;

background-color: #f8f9fa;

}

#chat-container {

flex: 1;

padding: 20px;

display: flex;

flex-direction: column;

justify-content: flex-end;

}

#chat-history {

border: 1px solid #ced4da;

border-radius: 5px;

padding: 15px;

background-color: #ffffff;

max-height: 400px;

overflow-y: auto;

margin-bottom: 20px;

}

#chat-form {

display: flex;

flex-direction: row;

}

#user_input {

flex: 1;

border-radius: 5px;

border: 1px solid #ced4da;

padding: 5px;

margin-right: 10px;

}

</style>

</head>

<body>

<div class="container">

<div id="chat-container">

<div id="chat-history"></div>

<form id="chat-form">

<input id="user_input" type="text" name="user_input" placeholder="Type your message here" autocomplete="off">

<button class="btn btn-primary" type="submit">Send</button>

</form>

</div>

</div>

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

<script>

$(document).ready(function() {

$("#chat-form").on("submit", function(event) {

event.preventDefault();

const user_input = $("#user_input").val();

// 将用户提问添加到闲聊记录中

const userMessage = `<p>You: ${user_input}</p>`;

$("#chat-history").append(userMessage);

$.ajax({

type: "POST",

url: "/",

data: {user_input: user_input},

success: function(response) {

// 将聚合的积极响应添加到闲聊记录中

const newMessage = `<p>AI: ${response.response}</p>`;

$("#chat-history").append(newMessage);

}

});

$("#user_input").val(""); // 清空输入框

});

});

</script>

</body>

</html>

接着把index.txt文档格式文档前缀换成 .py 变为index.html

接着运行先用旧版本关上根产品目录,命令:cd C:\Users\777\AppData\Roaming\Python\Python37(划线部分换成你他们的相应路径),回车;

之后再输入命令:Python app.py, 出现下面图片的情况就说明你又成功了,

接着在浏览器关上:http://127.0.0.1:5000 看看浏览去是不是出来了的闲聊框,我只是做了两个单纯闲聊网页,当然你也能他们再设计两个他们喜欢的风格,好!我看看效果:

恭喜你!你又成功了!!!!!!就是这个单纯粗暴!!!

上一篇:学到了吗(今年投资啥)今年投资怎么样,投资者提问:今年chatgpt AI 火爆,给AI+游戏产业也带来了巨大变...,

栏    目:chatgpt安装

下一篇:真没想到(利用ChatGPT写代码)利用ChatGPT写小说,利用chatgpt处理Excel,

本文标题:深度揭秘(赓续怎么读)赓续精神血脉,传承红色基因,(续)chatgpt怎么构建web页面聊天,

本文地址:http://www.shopify123.cn/chatgptanzhuang/4120.html

| |

/uploads/allimg/20230913/1-230913232SH48.jpg

联系QQ:1303712368 | 邮箱:fy669088

Copyright © 2002-2024 ChatGPT-Sora-人工智能AI 版权所有桂ICP备2021004354号-4