mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-02 03:55:55 +00:00
perf: move label file to data dir
This commit is contained in:
80
.github/workflows/test-pr.yml
vendored
80
.github/workflows/test-pr.yml
vendored
@@ -1,80 +0,0 @@
|
|||||||
name: Test Pull Request
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
types: [ready_for_review]
|
|
||||||
paths:
|
|
||||||
# 任何py文件改动都会触发
|
|
||||||
- '**.py'
|
|
||||||
pull_request_review:
|
|
||||||
types: [submitted]
|
|
||||||
issue_comment:
|
|
||||||
types: [created]
|
|
||||||
# 允许手动触发
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
perform-test:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
# 如果事件为pull_request_review且review状态为approved,则执行
|
|
||||||
if: >
|
|
||||||
github.event_name == 'pull_request' ||
|
|
||||||
(github.event_name == 'pull_request_review' && github.event.review.state == 'APPROVED') ||
|
|
||||||
github.event_name == 'workflow_dispatch' ||
|
|
||||||
(github.event_name == 'issue_comment' && github.event.issue.pull_request != '' && contains(github.event.comment.body, '/test') && github.event.comment.user.login == 'RockChinQ')
|
|
||||||
steps:
|
|
||||||
# 签出测试工程仓库代码
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
# 仓库地址
|
|
||||||
repository: RockChinQ/qcg-tester
|
|
||||||
# 仓库路径
|
|
||||||
path: qcg-tester
|
|
||||||
- name: Setup Python
|
|
||||||
uses: actions/setup-python@v2
|
|
||||||
with:
|
|
||||||
python-version: '3.10'
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: |
|
|
||||||
cd qcg-tester
|
|
||||||
python -m pip install --upgrade pip
|
|
||||||
pip install -r requirements.txt
|
|
||||||
|
|
||||||
- name: Get PR details
|
|
||||||
id: get-pr
|
|
||||||
if: github.event_name == 'issue_comment'
|
|
||||||
uses: octokit/request-action@v2.x
|
|
||||||
with:
|
|
||||||
route: GET /repos/${{ github.repository }}/pulls/${{ github.event.issue.number }}
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Set PR source branch as env variable
|
|
||||||
if: github.event_name == 'issue_comment'
|
|
||||||
run: |
|
|
||||||
PR_SOURCE_BRANCH=$(echo '${{ steps.get-pr.outputs.data }}' | jq -r '.head.ref')
|
|
||||||
echo "BRANCH=$PR_SOURCE_BRANCH" >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: Set PR Branch as bash env
|
|
||||||
if: github.event_name != 'issue_comment'
|
|
||||||
run: |
|
|
||||||
echo "BRANCH=${{ github.head_ref }}" >> $GITHUB_ENV
|
|
||||||
- name: Set OpenAI API Key from Secrets
|
|
||||||
run: |
|
|
||||||
echo "OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}" >> $GITHUB_ENV
|
|
||||||
- name: Set OpenAI Reverse Proxy URL from Secrets
|
|
||||||
run: |
|
|
||||||
echo "OPENAI_REVERSE_PROXY=${{ secrets.OPENAI_REVERSE_PROXY }}" >> $GITHUB_ENV
|
|
||||||
- name: Run test
|
|
||||||
run: |
|
|
||||||
cd qcg-tester
|
|
||||||
python main.py
|
|
||||||
|
|
||||||
- name: Upload coverage reports to Codecov
|
|
||||||
run: |
|
|
||||||
cd qcg-tester/resource/QChatGPT
|
|
||||||
curl -Os https://uploader.codecov.io/latest/linux/codecov
|
|
||||||
chmod +x codecov
|
|
||||||
./codecov -t ${{ secrets.CODECOV_TOKEN }}
|
|
||||||
6
.gitignore
vendored
6
.gitignore
vendored
@@ -2,7 +2,6 @@
|
|||||||
.idea/
|
.idea/
|
||||||
__pycache__/
|
__pycache__/
|
||||||
database.db
|
database.db
|
||||||
qchatgpt.log
|
|
||||||
langbot.log
|
langbot.log
|
||||||
/banlist.py
|
/banlist.py
|
||||||
/plugins/
|
/plugins/
|
||||||
@@ -17,8 +16,7 @@ scenario/
|
|||||||
!scenario/default-template.json
|
!scenario/default-template.json
|
||||||
override.json
|
override.json
|
||||||
cookies.json
|
cookies.json
|
||||||
res/announcement_saved
|
data/labels/announcement_saved.json
|
||||||
res/announcement_saved.json
|
|
||||||
cmdpriv.json
|
cmdpriv.json
|
||||||
tips.py
|
tips.py
|
||||||
.venv
|
.venv
|
||||||
@@ -32,7 +30,7 @@ claude.json
|
|||||||
bard.json
|
bard.json
|
||||||
/*yaml
|
/*yaml
|
||||||
!/docker-compose.yaml
|
!/docker-compose.yaml
|
||||||
res/instance_id.json
|
data/labels/instance_id.json
|
||||||
.DS_Store
|
.DS_Store
|
||||||
/data
|
/data
|
||||||
botpy.log*
|
botpy.log*
|
||||||
|
|||||||
@@ -13,14 +13,14 @@ identifier = {
|
|||||||
'instance_create_ts': 0,
|
'instance_create_ts': 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
HOST_ID_FILE = os.path.expanduser('~/.qchatgpt/host_id.json')
|
HOST_ID_FILE = os.path.expanduser('~/.langbot/host_id.json')
|
||||||
INSTANCE_ID_FILE = 'res/instance_id.json'
|
INSTANCE_ID_FILE = 'data/labels/instance_id.json'
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
global identifier
|
global identifier
|
||||||
|
|
||||||
if not os.path.exists(os.path.expanduser('~/.qchatgpt')):
|
if not os.path.exists(os.path.expanduser('~/.langbot')):
|
||||||
os.mkdir(os.path.expanduser('~/.qchatgpt'))
|
os.mkdir(os.path.expanduser('~/.langbot'))
|
||||||
|
|
||||||
if not os.path.exists(HOST_ID_FILE):
|
if not os.path.exists(HOST_ID_FILE):
|
||||||
new_host_id = 'host_'+str(uuid.uuid4())
|
new_host_id = 'host_'+str(uuid.uuid4())
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ required_paths = [
|
|||||||
"data/scenario",
|
"data/scenario",
|
||||||
"data/logs",
|
"data/logs",
|
||||||
"data/config",
|
"data/config",
|
||||||
|
"data/labels",
|
||||||
"plugins"
|
"plugins"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ class ChatMessageHandler(handler.MessageHandler):
|
|||||||
await self.ap.ctr_mgr.usage.post_query_record(
|
await self.ap.ctr_mgr.usage.post_query_record(
|
||||||
session_type=query.session.launcher_type.value,
|
session_type=query.session.launcher_type.value,
|
||||||
session_id=str(query.session.launcher_id),
|
session_id=str(query.session.launcher_id),
|
||||||
query_ability_provider="QChatGPT.Chat",
|
query_ability_provider="LangBot.Chat",
|
||||||
usage=text_length,
|
usage=text_length,
|
||||||
model_name=query.use_model.name,
|
model_name=query.use_model.name,
|
||||||
response_seconds=int(time.time() - start_time),
|
response_seconds=int(time.time() - start_time),
|
||||||
|
|||||||
@@ -127,16 +127,16 @@ class APIHost:
|
|||||||
Returns:
|
Returns:
|
||||||
bool: 是否满足要求, False时为无法获取版本号,True时为满足要求,报错为不满足要求
|
bool: 是否满足要求, False时为无法获取版本号,True时为满足要求,报错为不满足要求
|
||||||
"""
|
"""
|
||||||
qchatgpt_version = ""
|
langbot_version = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
qchatgpt_version = self.ap.ver_mgr.get_current_version() # 从updater模块获取版本号
|
langbot_version = self.ap.ver_mgr.get_current_version() # 从updater模块获取版本号
|
||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if self.ap.ver_mgr.compare_version_str(qchatgpt_version, ge) < 0 or \
|
if self.ap.ver_mgr.compare_version_str(langbot_version, ge) < 0 or \
|
||||||
(self.ap.ver_mgr.compare_version_str(qchatgpt_version, le) > 0):
|
(self.ap.ver_mgr.compare_version_str(langbot_version, le) > 0):
|
||||||
raise Exception("LangBot 版本不满足要求,某些功能(可能是由插件提供的)无法正常使用。(要求版本:{}-{},但当前版本:{})".format(ge, le, qchatgpt_version))
|
raise Exception("LangBot 版本不满足要求,某些功能(可能是由插件提供的)无法正常使用。(要求版本:{}-{},但当前版本:{})".format(ge, le, langbot_version))
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
@@ -62,11 +62,11 @@ class AnnouncementManager:
|
|||||||
async def fetch_saved(
|
async def fetch_saved(
|
||||||
self
|
self
|
||||||
) -> list[Announcement]:
|
) -> list[Announcement]:
|
||||||
if not os.path.exists("res/announcement_saved.json"):
|
if not os.path.exists("data/labels/announcement_saved.json"):
|
||||||
with open("res/announcement_saved.json", "w", encoding="utf-8") as f:
|
with open("data/labels/announcement_saved.json", "w", encoding="utf-8") as f:
|
||||||
f.write("[]")
|
f.write("[]")
|
||||||
|
|
||||||
with open("res/announcement_saved.json", "r", encoding="utf-8") as f:
|
with open("data/labels/announcement_saved.json", "r", encoding="utf-8") as f:
|
||||||
content = f.read()
|
content = f.read()
|
||||||
|
|
||||||
if not content:
|
if not content:
|
||||||
@@ -79,7 +79,7 @@ class AnnouncementManager:
|
|||||||
content: list[Announcement]
|
content: list[Announcement]
|
||||||
):
|
):
|
||||||
|
|
||||||
with open("res/announcement_saved.json", "w", encoding="utf-8") as f:
|
with open("data/labels/announcement_saved.json", "w", encoding="utf-8") as f:
|
||||||
f.write(json.dumps([
|
f.write(json.dumps([
|
||||||
item.to_dict() for item in content
|
item.to_dict() for item in content
|
||||||
], indent=4, ensure_ascii=False))
|
], indent=4, ensure_ascii=False))
|
||||||
|
|||||||
Reference in New Issue
Block a user