Files
Fay/core/authorize_tb.py
xszyou 11e115b228 fay自然进化
1. 增加清除记忆功能;
2. 增加克隆性格功能;
3. 增加认知模型(专属的记忆逻辑、反思逻辑);
4. 修复自动播报bug;
5. fay_url配置响修正;
6. 修复流式输出前置换行问题;
7. 修复没有用户聊天记录前端反复添加默认用户问题;
8. 更新dockerfile;
9. 重构util.py代码。
1. Fay ai编程指南:https://qqk9ntwbcit.feishu.cn/wiki/FKFywXWaeiBH28k4Q67c3eF7njC
2.Fay认知模型:https://qqk9ntwbcit.feishu.cn/wiki/BSW3wSsMdikiHUkiCJYcSp2lnio
2025-04-02 23:31:46 +08:00

65 lines
1.9 KiB
Python

import sqlite3
import time
import threading
import functools
def synchronized(func):
@functools.wraps(func)
def wrapper(self, *args, **kwargs):
with self.lock:
return func(self, *args, **kwargs)
return wrapper
class Authorize_Tb:
def __init__(self) -> None:
self.lock = threading.Lock()
#初始化
def init_tb(self):
conn = sqlite3.connect('memory/fay.db')
c = conn.cursor()
c.execute('''
CREATE TABLE IF NOT EXISTS T_Authorize
(id INTEGER PRIMARY KEY autoincrement,
userid char(100),
accesstoken TEXT,
expirestime BigInt,
createtime Int);
''')
conn.commit()
conn.close()
#添加
@synchronized
def add(self,userid,accesstoken,expirestime):
self.init_tb()
conn = sqlite3.connect("memory/fay.db")
cur = conn.cursor()
cur.execute("insert into T_Authorize (userid,accesstoken,expirestime,createtime) values (?,?,?,?)",(userid,accesstoken,expirestime,int(time.time())))
conn.commit()
conn.close()
return cur.lastrowid
#查询
@synchronized
def find_by_userid(self,userid):
self.init_tb()
conn = sqlite3.connect("memory/fay.db")
cur = conn.cursor()
cur.execute("select accesstoken,expirestime from T_Authorize where userid = ? order by id desc limit 1",(userid,))
info = cur.fetchone()
conn.close()
return info
# 更新token
@synchronized
def update_by_userid(self, userid, new_accesstoken, new_expirestime):
self.init_tb()
conn = sqlite3.connect("memory/fay.db")
cur = conn.cursor()
cur.execute("UPDATE T_Authorize SET accesstoken = ?, expirestime = ? WHERE userid = ?",
(new_accesstoken, new_expirestime, userid))
conn.commit()
conn.close()