添加评论机器人与教师端脚本发布。

This commit is contained in:
2024-06-08 15:32:57 +08:00
parent 1c9972c389
commit c98a5ffeba
7 changed files with 98 additions and 24 deletions
+50 -4
View File
@@ -13,11 +13,41 @@ from django.shortcuts import render
from server.taskform import TaskForm
from django.utils import timezone
from server.models import Task,StudentandTercher,MindUser,Liuyan
from server.models import Task,StudentandTercher,MindUser,Liuyan,Jiaoben
from server.serializers import *
import json
import asyncio
from zhipuai import ZhipuAI
def gml_chat(messages):
print("--------------------")
print(messages)
client = ZhipuAI(api_key="92a0e4868cda21d22fe6fd0f4c0bf6fb.oZ4IE9PPDOhsLKPp")
response = client.chat.completions.create(
model="glm-3-turbo",
# messages=[
# {
# "role": "user",
# "content": prompt
# }
# ],
messages =[{
"role": "user",
"content": "你现在是一个学习站点的评论分析机器人,我接下来讲给你用户的评论内容,给出一个1-100分的打分分值并且返回你对它评论的情感分析以及内容分析以及揣测用户的想法,给我相应的返回结果即可。用户评论内容是:" + messages
}],
top_p=0.7,
temperature=0.95,
max_tokens=1024,
stream=True,
)
content = ""
for trunk in response:
# print(trunk.choices[0].delta)
content = content + trunk.choices[0].delta.content
return content
class AuthBackend(ModelBackend):
"""
@@ -153,6 +183,22 @@ def post_task(request):
else:
return render(request, 'html/dashboard.html')
def jiaoben(request):
if request.user.type_t_or_s == 1:
if request.method == 'POST':
jiaoben = request.POST.get("jiaoben")
print(jiaoben)
jiaoben = Jiaoben(jiaoben=jiaoben)
jiaoben.save()
# rengwu = Task(title=title, description=description, publish_time=start_time, deadline=end_time,publisher=request.user)
# rengwu.save()
return http.JsonResponse({'code': CODE_SUCCESS, 'msg': '发布成功'})
else:
return render(request, 'html/post_task.html')
else:
return render(request, 'html/dashboard.html')
def post_kecheng(request):
if request.user.type_t_or_s == 1:
if request.method == 'POST':
@@ -210,12 +256,12 @@ def comment_control(request): # 提交评论的处理函数
pid = request.POST.get('pid')
id = MindUser.objects.get(username=request.user.username).id
author_id = id # 获取当前用户的ID
gpt_content = gml_chat(str(comment_content))
Comment.objects.create(comment_content=comment_content, pre_comment_id=pid, pinglun_id=article_id,
user_id=author_id) # 将提交的数据保存到数据库中
user_id=author_id,gpt_content=gpt_content) # 将提交的数据保存到数据库中
article = list(
Comment.objects.values('id', 'comment_content', 'pre_comment_id', 'pinglun_id', 'user_id',
'comment_time')) # 以键值对的形式取出评论对象,并且转化为列表list类型
'comment_time','gpt_content')) # 以键值对的形式取出评论对象,并且转化为列表list类型
return JsonResponse(article, safe=False) # JsonResponse返回JSON字符串,自动序列化,如果不是字典类型,则需要添加safe参数为False