Skip to content

Commit a01ca93

Browse files
binary-huskySakuraPuarerenlifei1994
authored
Merge Latest Frontier (#1991)
* logging sys to loguru: stage 1 complete * import loguru: stage 2 * logging -> loguru: stage 3 * support o1-preview and o1-mini * logging -> loguru stage 4 * update social helper * logging -> loguru: final stage * fix: console output * update translation matrix * fix: loguru argument error with proxy enabled (#1977) * relax llama index version * remove comment * Added some modules to support openrouter (#1975) * Added some modules for supporting openrouter model Added some modules for supporting openrouter model * Update config.py * Update .gitignore * Update bridge_openrouter.py * Not changed actually * Refactor logging in bridge_openrouter.py --------- Co-authored-by: binary-husky <[email protected]> * remove logging extra --------- Co-authored-by: Steven Moder <[email protected]> Co-authored-by: Ren Lifei <[email protected]>
1 parent 597c320 commit a01ca93

File tree

91 files changed

+2560
-744
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+2560
-744
lines changed

check_proxy.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from loguru import logger
12

23
def check_proxy(proxies, return_ip=False):
34
import requests
@@ -19,14 +20,14 @@ def check_proxy(proxies, return_ip=False):
1920
else:
2021
result = f"代理配置 {proxies_https}, 代理数据解析失败:{data}"
2122
if not return_ip:
22-
print(result)
23+
logger.warning(result)
2324
return result
2425
else:
2526
return ip
2627
except:
2728
result = f"代理配置 {proxies_https}, 代理所在地查询超时,代理可能无效"
2829
if not return_ip:
29-
print(result)
30+
logger.warning(result)
3031
return result
3132
else:
3233
return ip
@@ -82,25 +83,25 @@ def patch_and_restart(path):
8283
import sys
8384
import time
8485
import glob
85-
from shared_utils.colorful import print亮黄, print亮绿, print亮红
86+
from shared_utils.colorful import log亮黄, log亮绿, log亮红
8687
# if not using config_private, move origin config.py as config_private.py
8788
if not os.path.exists('config_private.py'):
88-
print亮黄('由于您没有设置config_private.py私密配置,现将您的现有配置移动至config_private.py以防止配置丢失,',
89+
log亮黄('由于您没有设置config_private.py私密配置,现将您的现有配置移动至config_private.py以防止配置丢失,',
8990
'另外您可以随时在history子文件夹下找回旧版的程序。')
9091
shutil.copyfile('config.py', 'config_private.py')
9192
path_new_version = glob.glob(path + '/*-master')[0]
9293
dir_util.copy_tree(path_new_version, './')
93-
print亮绿('代码已经更新,即将更新pip包依赖……')
94-
for i in reversed(range(5)): time.sleep(1); print(i)
94+
log亮绿('代码已经更新,即将更新pip包依赖……')
95+
for i in reversed(range(5)): time.sleep(1); log亮绿(i)
9596
try:
9697
import subprocess
9798
subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-r', 'requirements.txt'])
9899
except:
99-
print亮红('pip包依赖安装出现问题,需要手动安装新增的依赖库 `python -m pip install -r requirements.txt`,然后在用常规的`python main.py`的方式启动。')
100-
print亮绿('更新完成,您可以随时在history子文件夹下找回旧版的程序,5s之后重启')
101-
print亮红('假如重启失败,您可能需要手动安装新增的依赖库 `python -m pip install -r requirements.txt`,然后在用常规的`python main.py`的方式启动。')
102-
print(' ------------------------------ -----------------------------------')
103-
for i in reversed(range(8)): time.sleep(1); print(i)
100+
log亮红('pip包依赖安装出现问题,需要手动安装新增的依赖库 `python -m pip install -r requirements.txt`,然后在用常规的`python main.py`的方式启动。')
101+
log亮绿('更新完成,您可以随时在history子文件夹下找回旧版的程序,5s之后重启')
102+
log亮红('假如重启失败,您可能需要手动安装新增的依赖库 `python -m pip install -r requirements.txt`,然后在用常规的`python main.py`的方式启动。')
103+
log亮绿(' ------------------------------ -----------------------------------')
104+
for i in reversed(range(8)): time.sleep(1); log亮绿(i)
104105
os.execl(sys.executable, sys.executable, *sys.argv)
105106

106107

@@ -135,9 +136,9 @@ def auto_update(raise_error=False):
135136
current_version = f.read()
136137
current_version = json.loads(current_version)['version']
137138
if (remote_version - current_version) >= 0.01-1e-5:
138-
from shared_utils.colorful import print亮黄
139-
print亮黄(f'\n新版本可用。新版本:{remote_version},当前版本:{current_version}{new_feature}')
140-
print('(1)Github更新地址:\nhttps://github.com/binary-husky/chatgpt_academic\n')
139+
from shared_utils.colorful import log亮黄
140+
log亮黄(f'\n新版本可用。新版本:{remote_version},当前版本:{current_version}{new_feature}')
141+
logger.info('(1)Github更新地址:\nhttps://github.com/binary-husky/chatgpt_academic\n')
141142
user_instruction = input('(2)是否一键更新代码(Y+回车=确认,输入其他/无输入+回车=不更新)?')
142143
if user_instruction in ['Y', 'y']:
143144
path = backup_and_download(current_version, remote_version)
@@ -148,9 +149,9 @@ def auto_update(raise_error=False):
148149
if raise_error:
149150
from toolbox import trimmed_format_exc
150151
msg += trimmed_format_exc()
151-
print(msg)
152+
logger.warning(msg)
152153
else:
153-
print('自动更新程序:已禁用')
154+
logger.info('自动更新程序:已禁用')
154155
return
155156
else:
156157
return
@@ -159,10 +160,10 @@ def auto_update(raise_error=False):
159160
if raise_error:
160161
from toolbox import trimmed_format_exc
161162
msg += trimmed_format_exc()
162-
print(msg)
163+
logger.info(msg)
163164

164165
def warm_up_modules():
165-
print('正在执行一些模块的预热 ...')
166+
logger.info('正在执行一些模块的预热 ...')
166167
from toolbox import ProxyNetworkActivate
167168
from request_llms.bridge_all import model_info
168169
with ProxyNetworkActivate("Warmup_Modules"):
@@ -172,7 +173,7 @@ def warm_up_modules():
172173
enc.encode("模块预热", disallowed_special=())
173174

174175
def warm_up_vectordb():
175-
print('正在执行一些模块的预热 ...')
176+
logger.info('正在执行一些模块的预热 ...')
176177
from toolbox import ProxyNetworkActivate
177178
with ProxyNetworkActivate("Warmup_Modules"):
178179
import nltk

config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@
5757
# "yi-34b-chat-0205","yi-34b-chat-200k","yi-large","yi-medium","yi-spark","yi-large-turbo","yi-large-preview",
5858
# ]
5959
# --- --- --- ---
60-
# 此外,您还可以在接入one-api/vllm/ollama时
61-
# 使用"one-api-*","vllm-*","ollama-*"前缀直接使用非标准方式接入的模型,例如
62-
# AVAIL_LLM_MODELS = ["one-api-claude-3-sonnet-20240229(max_token=100000)", "ollama-phi3(max_token=4096)"]
60+
# 此外,您还可以在接入one-api/vllm/ollama/Openroute时
61+
# 使用"one-api-*","vllm-*","ollama-*","openrouter-*"前缀直接使用非标准方式接入的模型,例如
62+
# AVAIL_LLM_MODELS = ["one-api-claude-3-sonnet-20240229(max_token=100000)", "ollama-phi3(max_token=4096)","openrouter-openai/gpt-4o-mini","openrouter-openai/chatgpt-4o-latest"]
6363
# --- --- --- ---
6464

6565

crazy_functional.py

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from toolbox import HotReload # HotReload 的意思是热更新,修改函数插件后,不需要重启程序,代码直接生效
22
from toolbox import trimmed_format_exc
3+
from loguru import logger
34

45

56
def get_crazy_functions():
@@ -429,8 +430,8 @@ def get_crazy_functions():
429430
}
430431
)
431432
except:
432-
print(trimmed_format_exc())
433-
print("Load function plugin failed")
433+
logger.error(trimmed_format_exc())
434+
logger.error("Load function plugin failed")
434435

435436
# try:
436437
# from crazy_functions.联网的ChatGPT import 连接网络回答问题
@@ -460,8 +461,8 @@ def get_crazy_functions():
460461
# }
461462
# )
462463
# except:
463-
# print(trimmed_format_exc())
464-
# print("Load function plugin failed")
464+
# logger.error(trimmed_format_exc())
465+
# logger.error("Load function plugin failed")
465466

466467
try:
467468
from crazy_functions.SourceCode_Analyse import 解析任意code项目
@@ -479,8 +480,8 @@ def get_crazy_functions():
479480
}
480481
)
481482
except:
482-
print(trimmed_format_exc())
483-
print("Load function plugin failed")
483+
logger.error(trimmed_format_exc())
484+
logger.error("Load function plugin failed")
484485

485486
try:
486487
from crazy_functions.询问多个大语言模型 import 同时问询_指定模型
@@ -498,8 +499,8 @@ def get_crazy_functions():
498499
}
499500
)
500501
except:
501-
print(trimmed_format_exc())
502-
print("Load function plugin failed")
502+
logger.error(trimmed_format_exc())
503+
logger.error("Load function plugin failed")
503504

504505

505506

@@ -520,8 +521,8 @@ def get_crazy_functions():
520521
}
521522
)
522523
except:
523-
print(trimmed_format_exc())
524-
print("Load function plugin failed")
524+
logger.error(trimmed_format_exc())
525+
logger.error("Load function plugin failed")
525526

526527
try:
527528
from crazy_functions.数学动画生成manim import 动画生成
@@ -538,8 +539,8 @@ def get_crazy_functions():
538539
}
539540
)
540541
except:
541-
print(trimmed_format_exc())
542-
print("Load function plugin failed")
542+
logger.error(trimmed_format_exc())
543+
logger.error("Load function plugin failed")
543544

544545
try:
545546
from crazy_functions.Markdown_Translate import Markdown翻译指定语言
@@ -557,8 +558,8 @@ def get_crazy_functions():
557558
}
558559
)
559560
except:
560-
print(trimmed_format_exc())
561-
print("Load function plugin failed")
561+
logger.error(trimmed_format_exc())
562+
logger.error("Load function plugin failed")
562563

563564
try:
564565
from crazy_functions.知识库问答 import 知识库文件注入
@@ -576,8 +577,8 @@ def get_crazy_functions():
576577
}
577578
)
578579
except:
579-
print(trimmed_format_exc())
580-
print("Load function plugin failed")
580+
logger.error(trimmed_format_exc())
581+
logger.error("Load function plugin failed")
581582

582583
try:
583584
from crazy_functions.知识库问答 import 读取知识库作答
@@ -595,8 +596,8 @@ def get_crazy_functions():
595596
}
596597
)
597598
except:
598-
print(trimmed_format_exc())
599-
print("Load function plugin failed")
599+
logger.error(trimmed_format_exc())
600+
logger.error("Load function plugin failed")
600601

601602
try:
602603
from crazy_functions.交互功能函数模板 import 交互功能模板函数
@@ -612,8 +613,8 @@ def get_crazy_functions():
612613
}
613614
)
614615
except:
615-
print(trimmed_format_exc())
616-
print("Load function plugin failed")
616+
logger.error(trimmed_format_exc())
617+
logger.error("Load function plugin failed")
617618

618619

619620
try:
@@ -635,8 +636,8 @@ def get_crazy_functions():
635636
}
636637
)
637638
except:
638-
print(trimmed_format_exc())
639-
print("Load function plugin failed")
639+
logger.error(trimmed_format_exc())
640+
logger.error("Load function plugin failed")
640641

641642
try:
642643
from crazy_functions.批量翻译PDF文档_NOUGAT import 批量翻译PDF文档
@@ -652,8 +653,8 @@ def get_crazy_functions():
652653
}
653654
)
654655
except:
655-
print(trimmed_format_exc())
656-
print("Load function plugin failed")
656+
logger.error(trimmed_format_exc())
657+
logger.error("Load function plugin failed")
657658

658659
try:
659660
from crazy_functions.函数动态生成 import 函数动态生成
@@ -669,8 +670,8 @@ def get_crazy_functions():
669670
}
670671
)
671672
except:
672-
print(trimmed_format_exc())
673-
print("Load function plugin failed")
673+
logger.error(trimmed_format_exc())
674+
logger.error("Load function plugin failed")
674675

675676
try:
676677
from crazy_functions.多智能体 import 多智能体终端
@@ -686,8 +687,8 @@ def get_crazy_functions():
686687
}
687688
)
688689
except:
689-
print(trimmed_format_exc())
690-
print("Load function plugin failed")
690+
logger.error(trimmed_format_exc())
691+
logger.error("Load function plugin failed")
691692

692693
try:
693694
from crazy_functions.互动小游戏 import 随机小游戏
@@ -703,8 +704,8 @@ def get_crazy_functions():
703704
}
704705
)
705706
except:
706-
print(trimmed_format_exc())
707-
print("Load function plugin failed")
707+
logger.error(trimmed_format_exc())
708+
logger.error("Load function plugin failed")
708709

709710
# try:
710711
# from crazy_functions.高级功能函数模板 import 测试图表渲染
@@ -717,7 +718,7 @@ def get_crazy_functions():
717718
# }
718719
# })
719720
# except:
720-
# print(trimmed_format_exc())
721+
# logger.error(trimmed_format_exc())
721722
# print('Load function plugin failed')
722723

723724
# try:

crazy_functions/Conversation_To_File.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def 载入对话历史存档(txt, llm_kwargs, plugin_kwargs, chatbot, history, s
171171
system_prompt 给gpt的静默提醒
172172
user_request 当前用户的请求信息(IP地址等)
173173
"""
174-
from .crazy_utils import get_files_from_everything
174+
from crazy_functions.crazy_utils import get_files_from_everything
175175
success, file_manifest, _ = get_files_from_everything(txt, type='.html')
176176

177177
if not success:

crazy_functions/Image_Generate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def gen_image(llm_kwargs, prompt, resolution="1024x1024", model="dall-e-2", qual
3030
if style is not None:
3131
data['style'] = style
3232
response = requests.post(url, headers=headers, json=data, proxies=proxies)
33-
print(response.content)
33+
# logger.info(response.content)
3434
try:
3535
image_url = json.loads(response.content.decode('utf8'))['data'][0]['url']
3636
except:
@@ -76,7 +76,7 @@ def edit_image(llm_kwargs, prompt, image_path, resolution="1024x1024", model="da
7676
}
7777

7878
response = requests.post(url, headers=headers, files=files, proxies=proxies)
79-
print(response.content)
79+
# logger.info(response.content)
8080
try:
8181
image_url = json.loads(response.content.decode('utf8'))['data'][0]['url']
8282
except:

crazy_functions/Latex_Function.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from toolbox import update_ui, trimmed_format_exc, get_conf, get_log_folder, promote_file_to_downloadzone, check_repeat_upload, map_file_to_sha256
22
from toolbox import CatchException, report_exception, update_ui_lastest_msg, zip_result, gen_time_str
33
from functools import partial
4+
from loguru import logger
5+
46
import glob, os, requests, time, json, tarfile
57

68
pj = os.path.join
@@ -178,20 +180,20 @@ def pdf2tex_project(pdf_file_path, plugin_kwargs):
178180

179181
if response.ok:
180182
pdf_id = response.json()["pdf_id"]
181-
print(f"PDF processing initiated. PDF ID: {pdf_id}")
183+
logger.info(f"PDF processing initiated. PDF ID: {pdf_id}")
182184

183185
# Step 2: Check processing status
184186
while True:
185187
conversion_response = requests.get(f"https://api.mathpix.com/v3/pdf/{pdf_id}", headers=headers)
186188
conversion_data = conversion_response.json()
187189

188190
if conversion_data["status"] == "completed":
189-
print("PDF processing completed.")
191+
logger.info("PDF processing completed.")
190192
break
191193
elif conversion_data["status"] == "error":
192-
print("Error occurred during processing.")
194+
logger.info("Error occurred during processing.")
193195
else:
194-
print(f"Processing status: {conversion_data['status']}")
196+
logger.info(f"Processing status: {conversion_data['status']}")
195197
time.sleep(5) # wait for a few seconds before checking again
196198

197199
# Step 3: Save results to local files
@@ -206,7 +208,7 @@ def pdf2tex_project(pdf_file_path, plugin_kwargs):
206208
output_path = os.path.join(output_dir, output_name)
207209
with open(output_path, "wb") as output_file:
208210
output_file.write(response.content)
209-
print(f"tex.zip file saved at: {output_path}")
211+
logger.info(f"tex.zip file saved at: {output_path}")
210212

211213
import zipfile
212214
unzip_dir = os.path.join(output_dir, file_name_wo_dot)
@@ -216,7 +218,7 @@ def pdf2tex_project(pdf_file_path, plugin_kwargs):
216218
return unzip_dir
217219

218220
else:
219-
print(f"Error sending PDF for processing. Status code: {response.status_code}")
221+
logger.error(f"Error sending PDF for processing. Status code: {response.status_code}")
220222
return None
221223
else:
222224
from crazy_functions.pdf_fns.parse_pdf_via_doc2x import 解析PDF_DOC2X_转Latex

0 commit comments

Comments
 (0)