新功能: - 创建AI聊天助手组件(AIChatWidget) - 支持文字+图片多模态对话 - 集成Gemini AI API - 支持图片编辑和内容生成 - 实时对话历史管理 - 优雅的UI设计,支持黑夜模式 技术实现: - 后端API代理Gemini API(/api/ai-chat) - 支持最多5张图片上传 - 流式响应处理 - 对话历史管理 - Base64图片处理 配置: - 在.env中添加Gemini API配置 - GEMINI_API_KEY - GEMINI_API_BASE_URL - GEMINI_MODEL 替换原弹幕功能,提供更强大的AI助手体验!
52 lines
1.2 KiB
Python
Executable File
52 lines
1.2 KiB
Python
Executable File
# coding : utf-8
|
|
from collections import OrderedDict
|
|
|
|
try:
|
|
from urllib import urlencode
|
|
except:
|
|
from urllib.parse import urlencode
|
|
|
|
|
|
class Request(object):
|
|
def __init__(self):
|
|
self.schema = ''
|
|
self.method = ''
|
|
self.host = ''
|
|
self.path = ''
|
|
self.headers = OrderedDict()
|
|
self.query = OrderedDict()
|
|
self.body = ''
|
|
self.form = dict()
|
|
self.connection_timeout = 0
|
|
self.socket_timeout = 0
|
|
|
|
def set_shema(self, schema):
|
|
self.schema = schema
|
|
|
|
def set_method(self, method):
|
|
self.method = method
|
|
|
|
def set_host(self, host):
|
|
self.host = host
|
|
|
|
def set_path(self, path):
|
|
self.path = path
|
|
|
|
def set_headers(self, headers):
|
|
self.headers = headers
|
|
|
|
def set_query(self, query):
|
|
self.query = query
|
|
|
|
def set_body(self, body):
|
|
self.body = body
|
|
|
|
def set_connection_timeout(self, connection_timeout):
|
|
self.connection_timeout = connection_timeout
|
|
|
|
def set_socket_timeout(self, socket_timeout):
|
|
self.socket_timeout = socket_timeout
|
|
|
|
def build(self, doseq=0):
|
|
return self.schema + '://' + self.host + self.path + '?' + urlencode(self.query, doseq)
|