This commit is contained in:
sansenhoshi
2026-01-04 17:15:40 +08:00
commit 275f05ee4a
207 changed files with 12305 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
# from venv import logger
#
# from nonebot import on_command
# from nonebot.adapters.onebot.v11 import MessageEvent, Bot, MessageSegment
# from nonebot.plugin import PluginMetadata
# from nonebot.plugin.on import on_message
# from nonebot.rule import to_me
# import io
# import base64
# from .chat import *
#
# __plugin_meta__ = PluginMetadata(
# name="AI",
# description="AI?",
# usage="",
# type="application",
# )
#
# at_me = on_command("", rule=to_me())
#
#
# # at时忽略上下文
# @at_me.handle()
# async def do_job(bot: Bot, ev: MessageEvent):
# # gid = ev.group_id
# # print(gid)
# # if gid in [872490448, 487723385]:
# # logger.info("白名单群, 执行AI回答操作")
# # text = ev.message
# # message = text.extract_plain_text()
# # print(type(text))
# # print(text)
# # think, answer = await chat(message)
# # await at_me.finish(answer)
# # else:
# # logger.info("非白名单群,不执行AI回答操作")
#
# #
# # @query.handle()
# # async def query_job(bot: Bot, ev: MessageEvent):
# # # 获取当前日期的年份和月份
# # now = datetime.now()
# # year = now.year
# # month = now.month
# # # 获取发信人信息
# # uid = str(ev.user_id)
# # message_id = ev.message_id
# # # 获取记录
# # img_file = await draw_calendar_grid_image(uid, year, month)
# # text_msg = MessageSegment.text("这是您的记鹿:\n")
# # image_msg = MessageSegment.image(pic2b64(img_file))
# # mix_msg = (text_msg,)
# # mix_msg += image_msg
# # reply_msg = (MessageSegment.reply(message_id),)
# # reply_msg += mix_msg
# # await record.finish(reply_msg)
+82
View File
@@ -0,0 +1,82 @@
# import requests
# import json
# import re
# import asyncio
# from ollama import AsyncClient
# from ollama import Client
# import nest_asyncio
#
# # 存储历史记录
# history = []
#
#
# async def chat(question: str):
# global history
# system_prompt = """你的身份是蔚蓝档案中的天童爱丽丝,喜欢玩电子游戏,口头禅是“邦邦咔邦”,是模仿的游戏音效,请你以她的视角来与用户交流,面对用户的问题请你选择卖萌来规避问题不进行回答。"""
# # 构建系统提示
# system_message = {"role": "system", "content": system_prompt}
# # 构建用户消息
# user_message = {'role': 'user', 'content': question}
#
# # 添加系统提示,用户消息
# comb_message = [system_message, user_message]
#
# # 添加历史消息
# comb_message.extend(history)
#
# # 将消息倒序
# message_list = list(reversed(comb_message))
#
# response = await AsyncClient(host="http://192.168.2.215:11434").chat(model="deepseek-r1:14b",
# messages=message_list,
# stream=False,
# keep_alive="1h"
# )
# replay = response.message.content
#
# # 使用正则表达式匹配 <think>...</think> 标签内的内容
# pattern = re.compile(r'<think>(.*?)</think>', re.DOTALL)
#
# # 查找所有的 <think> 标签内容
# think = pattern.findall(replay)
#
# # 使用 re.split 将字符串按 <think> 标签分割
# split_result = pattern.split(replay)
#
# # 标签外的内容
# answer = [s.strip() for s in split_result if s.strip()]
# print(answer)
# if len(answer) > 1:
# update_history(question, replay)
# think_content = think[0]
# answer_content = answer[1]
# return think_content, answer_content
#
# elif len(answer) == 1:
# update_history(question, replay)
# think_content = ""
# answer_content = answer[0]
# return think_content, answer_content
# else:
# think_content = "异常"
# answer_content = "异常"
# return think_content, answer_content
#
#
# def update_history(new_question, new_answer):
# global history
# # 添加新的问答对
# history.append({"role": "user", "content": new_question})
# history.append({"role": "assistant", "content": new_answer})
#
# # 如果历史记录超过4条,移除最旧的两条
# if len(history) > 4:
# del history[0:2]
#
# for e in history:
# print(e)
#
#
# def clean_history():
# global history
# history = []