Spaces:
Runtime error
Runtime error
stage llm model interface
Browse files- README.md +7 -5
- main.py +3 -2
- request_llm/bridge_tgui.py +14 -5
README.md
CHANGED
|
@@ -36,14 +36,16 @@ https://github.com/polarwinkel/mdtex2html
|
|
| 36 |
自定义快捷键 | 支持自定义快捷键
|
| 37 |
配置代理服务器 | 支持配置代理服务器
|
| 38 |
模块化设计 | 支持自定义高阶的实验性功能
|
| 39 |
-
自我程序剖析 | [
|
| 40 |
-
程序剖析 | [
|
| 41 |
-
读论文 | [
|
| 42 |
-
|
| 43 |
-
|
|
|
|
| 44 |
公式显示 | 可以同时显示公式的tex形式和渲染形式
|
| 45 |
图片显示 | 可以在markdown中显示图片
|
| 46 |
支持GPT输出的markdown表格 | 可以输出支持GPT的markdown表格
|
|
|
|
| 47 |
…… | ……
|
| 48 |
|
| 49 |
</div>
|
|
|
|
| 36 |
自定义快捷键 | 支持自定义快捷键
|
| 37 |
配置代理服务器 | 支持配置代理服务器
|
| 38 |
模块化设计 | 支持自定义高阶的实验性功能
|
| 39 |
+
自我程序剖析 | [函数插件] 一键读懂本项目的源代码
|
| 40 |
+
程序剖析 | [函数插件] 一键可以剖析其他Python/C++等项目
|
| 41 |
+
读论文 | [函数插件] 一键解读latex论文全文并生成摘要
|
| 42 |
+
arxiv小助手 | [函数插件] 输入url一键翻译摘要+下载论文
|
| 43 |
+
批量注释生成 | [函数插件] 一键批量生成函数注释
|
| 44 |
+
chat分析报告生成 | [函数插件] 运行后自动生成总结汇报
|
| 45 |
公式显示 | 可以同时显示公式的tex形式和渲染形式
|
| 46 |
图片显示 | 可以在markdown中显示图片
|
| 47 |
支持GPT输出的markdown表格 | 可以输出支持GPT的markdown表格
|
| 48 |
+
本地大语言模型接口 | 借助[TGUI](https://github.com/oobabooga/text-generation-webui)接入galactica等本地语言模型
|
| 49 |
…… | ……
|
| 50 |
|
| 51 |
</div>
|
main.py
CHANGED
|
@@ -11,8 +11,9 @@ proxies, WEB_PORT, LLM_MODEL, CONCURRENT_COUNT, AUTHENTICATION, CHATBOT_HEIGHT =
|
|
| 11 |
PORT = find_free_port() if WEB_PORT <= 0 else WEB_PORT
|
| 12 |
if not AUTHENTICATION: AUTHENTICATION = None
|
| 13 |
|
|
|
|
| 14 |
initial_prompt = "Serve me as a writing and programming assistant."
|
| 15 |
-
title_html = "
|
| 16 |
|
| 17 |
# 问询记录, python 版本建议3.9+(越新越好)
|
| 18 |
import logging
|
|
@@ -140,5 +141,5 @@ def auto_opentab_delay():
|
|
| 140 |
threading.Thread(target=open, name="open-browser", daemon=True).start()
|
| 141 |
|
| 142 |
auto_opentab_delay()
|
| 143 |
-
demo.title =
|
| 144 |
demo.queue(concurrency_count=CONCURRENT_COUNT).launch(server_name="0.0.0.0", share=True, server_port=PORT, auth=AUTHENTICATION)
|
|
|
|
| 11 |
PORT = find_free_port() if WEB_PORT <= 0 else WEB_PORT
|
| 12 |
if not AUTHENTICATION: AUTHENTICATION = None
|
| 13 |
|
| 14 |
+
title = "ChatGPT 学术优化" if LLM_MODEL.startswith('gpt') else "ChatGPT / LLM 学术优化"
|
| 15 |
initial_prompt = "Serve me as a writing and programming assistant."
|
| 16 |
+
title_html = f"<h1 align=\"center\">{title}</h1>"
|
| 17 |
|
| 18 |
# 问询记录, python 版本建议3.9+(越新越好)
|
| 19 |
import logging
|
|
|
|
| 141 |
threading.Thread(target=open, name="open-browser", daemon=True).start()
|
| 142 |
|
| 143 |
auto_opentab_delay()
|
| 144 |
+
demo.title = title
|
| 145 |
demo.queue(concurrency_count=CONCURRENT_COUNT).launch(server_name="0.0.0.0", share=True, server_port=PORT, auth=AUTHENTICATION)
|
request_llm/bridge_tgui.py
CHANGED
|
@@ -24,9 +24,9 @@ def random_hash():
|
|
| 24 |
letters = string.ascii_lowercase + string.digits
|
| 25 |
return ''.join(random.choice(letters) for i in range(9))
|
| 26 |
|
| 27 |
-
async def run(context):
|
| 28 |
params = {
|
| 29 |
-
'max_new_tokens':
|
| 30 |
'do_sample': True,
|
| 31 |
'temperature': 0.5,
|
| 32 |
'top_p': 0.9,
|
|
@@ -116,12 +116,15 @@ def predict_tgui(inputs, top_p, temperature, chatbot=[], history=[], system_prom
|
|
| 116 |
prompt = inputs
|
| 117 |
tgui_say = ""
|
| 118 |
|
| 119 |
-
mutable = [""]
|
| 120 |
def run_coorotine(mutable):
|
| 121 |
async def get_result(mutable):
|
| 122 |
async for response in run(prompt):
|
| 123 |
print(response[len(mutable[0]):])
|
| 124 |
mutable[0] = response
|
|
|
|
|
|
|
|
|
|
| 125 |
asyncio.run(get_result(mutable))
|
| 126 |
|
| 127 |
thread_listen = threading.Thread(target=run_coorotine, args=(mutable,), daemon=True)
|
|
@@ -129,6 +132,7 @@ def predict_tgui(inputs, top_p, temperature, chatbot=[], history=[], system_prom
|
|
| 129 |
|
| 130 |
while thread_listen.is_alive():
|
| 131 |
time.sleep(1)
|
|
|
|
| 132 |
# Print intermediate steps
|
| 133 |
if tgui_say != mutable[0]:
|
| 134 |
tgui_say = mutable[0]
|
|
@@ -147,12 +151,17 @@ def predict_tgui_no_ui(inputs, top_p, temperature, history=[], sys_prompt=""):
|
|
| 147 |
mutable = ["", time.time()]
|
| 148 |
def run_coorotine(mutable):
|
| 149 |
async def get_result(mutable):
|
| 150 |
-
async for response in run(prompt):
|
| 151 |
print(response[len(mutable[0]):])
|
| 152 |
mutable[0] = response
|
|
|
|
|
|
|
|
|
|
| 153 |
asyncio.run(get_result(mutable))
|
| 154 |
thread_listen = threading.Thread(target=run_coorotine, args=(mutable,))
|
| 155 |
thread_listen.start()
|
| 156 |
-
thread_listen.
|
|
|
|
|
|
|
| 157 |
tgui_say = mutable[0]
|
| 158 |
return tgui_say
|
|
|
|
| 24 |
letters = string.ascii_lowercase + string.digits
|
| 25 |
return ''.join(random.choice(letters) for i in range(9))
|
| 26 |
|
| 27 |
+
async def run(context, max_token=512):
|
| 28 |
params = {
|
| 29 |
+
'max_new_tokens': max_token,
|
| 30 |
'do_sample': True,
|
| 31 |
'temperature': 0.5,
|
| 32 |
'top_p': 0.9,
|
|
|
|
| 116 |
prompt = inputs
|
| 117 |
tgui_say = ""
|
| 118 |
|
| 119 |
+
mutable = ["", time.time()]
|
| 120 |
def run_coorotine(mutable):
|
| 121 |
async def get_result(mutable):
|
| 122 |
async for response in run(prompt):
|
| 123 |
print(response[len(mutable[0]):])
|
| 124 |
mutable[0] = response
|
| 125 |
+
if (time.time() - mutable[1]) > 3:
|
| 126 |
+
print('exit when no listener')
|
| 127 |
+
break
|
| 128 |
asyncio.run(get_result(mutable))
|
| 129 |
|
| 130 |
thread_listen = threading.Thread(target=run_coorotine, args=(mutable,), daemon=True)
|
|
|
|
| 132 |
|
| 133 |
while thread_listen.is_alive():
|
| 134 |
time.sleep(1)
|
| 135 |
+
mutable[1] = time.time()
|
| 136 |
# Print intermediate steps
|
| 137 |
if tgui_say != mutable[0]:
|
| 138 |
tgui_say = mutable[0]
|
|
|
|
| 151 |
mutable = ["", time.time()]
|
| 152 |
def run_coorotine(mutable):
|
| 153 |
async def get_result(mutable):
|
| 154 |
+
async for response in run(prompt, max_token=20):
|
| 155 |
print(response[len(mutable[0]):])
|
| 156 |
mutable[0] = response
|
| 157 |
+
if (time.time() - mutable[1]) > 3:
|
| 158 |
+
print('exit when no listener')
|
| 159 |
+
break
|
| 160 |
asyncio.run(get_result(mutable))
|
| 161 |
thread_listen = threading.Thread(target=run_coorotine, args=(mutable,))
|
| 162 |
thread_listen.start()
|
| 163 |
+
while thread_listen.is_alive():
|
| 164 |
+
time.sleep(1)
|
| 165 |
+
mutable[1] = time.time()
|
| 166 |
tgui_say = mutable[0]
|
| 167 |
return tgui_say
|