Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add groq models support #1734

Open
wants to merge 66 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
2adaf6d
Update version to 3.74
binary-husky Mar 11, 2024
51e0ca8
Add support for Yi Model API (#1635)
Menghuan1918 Mar 16, 2024
0fe62db
Merge branch 'master' into frontier
binary-husky Mar 16, 2024
50c5da4
Merge branch 'master' into frontier
binary-husky Mar 17, 2024
cc170fd
Merge branch 'master' into frontier
binary-husky Mar 20, 2024
ca63993
Merge branch 'master' into frontier
binary-husky Mar 20, 2024
b7ed33f
Refactor function signatures in bridge files
binary-husky Mar 20, 2024
f4f0ff1
Merge branch 'master' into frontier
binary-husky Apr 1, 2024
a276443
store system prompt etc. with cookie
binary-husky Apr 2, 2024
fe52938
fix qwen api change
binary-husky Apr 3, 2024
b7226e9
rename and ref functions
binary-husky Apr 4, 2024
250ddeb
rename and move some cookie functions
binary-husky Apr 4, 2024
9ab9c83
增加haiku模型,新增endpoint配置说明 (#1626)
Skyzayre Apr 4, 2024
72fc2b7
private_upload目录下进行文件鉴权 (#1596)
Kilig947 Apr 4, 2024
dcec2f7
remove yaml deps
binary-husky Apr 4, 2024
f7b8777
fix favicon
binary-husky Apr 4, 2024
efc94aa
fix abs path auth problem
binary-husky Apr 4, 2024
fdbc905
forget to write a return
binary-husky Apr 4, 2024
09b02e6
add `dashscope` to deps
binary-husky Apr 4, 2024
a438a19
fix GHSA-v9q9-xj86-953p
binary-husky Apr 5, 2024
02060ce
用户名重叠越权访问patch (#1681)
Kilig947 Apr 5, 2024
06262ab
add cohere model api access
binary-husky Apr 5, 2024
11ee988
Merge branch 'frontier' of github.com:binary-husky/chatgpt_academic i…
binary-husky Apr 5, 2024
b5de74b
cohere + can_multi_thread
binary-husky Apr 5, 2024
f6bf050
fix block user access(fail)
binary-husky Apr 7, 2024
090388f
fix fastapi bug
binary-husky Apr 7, 2024
0887c25
change cohere api endpoint
binary-husky Apr 8, 2024
227b22e
explain version
binary-husky Apr 8, 2024
6fce1ec
merge master
binary-husky Apr 8, 2024
a678b5b
# fix com_zhipuglm.py illegal temperature problem (#1687)
binaryYuki Apr 8, 2024
6ad6950
allow store lm model dropdown
binary-husky Apr 8, 2024
ac8e604
add a btn to reverse previous reset
binary-husky Apr 10, 2024
235c8ec
remove extra fns
binary-husky Apr 10, 2024
466eeba
Add support for glm-4v model (#1700)
Menghuan1918 Apr 11, 2024
f3c4899
修改chatglm3量化加载方式 (#1688)
zyren123 Apr 11, 2024
ad18eff
Merge branch 'master' into frontier
binary-husky Apr 11, 2024
161cd62
Merge branch 'frontier' of github.com:binary-husky/chatgpt_academic i…
binary-husky Apr 11, 2024
484f1b4
save chat stage 1
binary-husky Apr 14, 2024
d1568fb
Merge branch 'master' into frontier
binary-husky Apr 14, 2024
8ecdb1b
Merge branch 'master' into frontier
binary-husky Apr 16, 2024
3b191f7
consider null cookie situation
binary-husky Apr 16, 2024
b720ad9
Merge branch 'master' into frontier
binary-husky Apr 19, 2024
624ff43
在点击复制按钮时激活语音
binary-husky Apr 19, 2024
bab549e
miss some parts
binary-husky Apr 19, 2024
6383e71
move all to js
binary-husky Apr 20, 2024
e9fc174
done first stage
binary-husky Apr 20, 2024
9db4779
add edge tts
binary-husky Apr 20, 2024
17ea0d5
bug fix
binary-husky Apr 20, 2024
68828a1
bug fix
binary-husky Apr 20, 2024
b4dd91d
remove console log
binary-husky Apr 20, 2024
219a976
bug fix
binary-husky Apr 20, 2024
10641b4
bug fix
binary-husky Apr 20, 2024
5cd16c2
bug fix
binary-husky Apr 20, 2024
d7aa934
audio switch
binary-husky Apr 20, 2024
0b620a0
update tts readme
binary-husky Apr 20, 2024
4e6cd0e
remove tempfile when done
binary-husky Apr 21, 2024
5ea1d4a
Merge branch 'master' into frontier
binary-husky Apr 21, 2024
e2ef635
Merge branch 'master' into frontier
binary-husky Apr 21, 2024
6541d92
disable auto audio follow
binary-husky Apr 21, 2024
753bda2
avoid play queue update after shut up
binary-husky Apr 21, 2024
5f081cb
feat: minimizing common.js
binary-husky Apr 22, 2024
223b9c2
improve tts functionality
binary-husky Apr 22, 2024
893a78e
deterine whether the cached model is in choices
binary-husky Apr 23, 2024
20f4f4a
add groq models support
jiangfy-ihep Apr 23, 2024
7e04452
Add support for Ollama (#1740)
Menghuan1918 Apr 25, 2024
a723aeb
Merge branch 'frontier' into feature/groq
jiangfy-ihep Apr 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,4 @@ media
flagged
request_llms/ChatGLM-6b-onnx-u8s8
.pre-commit-config.yaml
themes/common.js.min.*.js
26 changes: 19 additions & 7 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
proxies = None

# [step 3]>> 模型选择是 (注意: LLM_MODEL是默认选中的模型, 它*必须*被包含在AVAIL_LLM_MODELS列表中 )
LLM_MODEL = "gpt-3.5-turbo-16k" # 可选 ↓↓↓
LLM_MODEL = "gpt-3.5-turbo" # 可选 ↓↓↓
AVAIL_LLM_MODELS = ["gpt-4-1106-preview", "gpt-4-turbo-preview", "gpt-4-vision-preview", "gpt-4-turbo", "gpt-4-turbo-2024-04-09",
"gpt-3.5-turbo-1106", "gpt-3.5-turbo-16k", "gpt-3.5-turbo", "azure-gpt-3.5",
"gpt-4", "gpt-4-32k", "azure-gpt-4", "glm-4", "glm-3-turbo",
"gemini-pro", "chatglm3"
"gpt-4", "gpt-4-32k", "azure-gpt-4", "glm-4", "glm-4v", "glm-3-turbo",
"gemini-pro", "chatglm3", "groq-llama3-8b-8192", "groq-llama3-70b-8192", "groq-llama2-70b-4096", "groq-mixtral-8x7b-32768", "groq-gemma-7b-it"
]
# --- --- --- ---
# P.S. 其他可用的模型还包括
Expand All @@ -50,17 +50,17 @@
# "yi-34b-chat-0205", "yi-34b-chat-200k"
# ]
# --- --- --- ---
# 此外,为了更灵活地接入one-api多模型管理界面,您还可以在接入one-api时
# 使用"one-api-*"前缀直接使用非标准方式接入的模型,例如
# AVAIL_LLM_MODELS = ["one-api-claude-3-sonnet-20240229(max_token=100000)"]
# 此外,您还可以在接入one-api/vllm/ollama时
# 使用"one-api-*","vllm-*","ollama-*"前缀直接使用非标准方式接入的模型,例如
# AVAIL_LLM_MODELS = ["one-api-claude-3-sonnet-20240229(max_token=100000)", "ollama-phi3(max_token=4096)"]
# --- --- --- ---


# --------------- 以下配置可以优化体验 ---------------

# 重新URL重新定向,实现更换API_URL的作用(高危设置! 常规情况下不要修改! 通过修改此设置,您将把您的API-KEY和对话隐私完全暴露给您设定的中间人!)
# 格式: API_URL_REDIRECT = {"https://api.openai.com/v1/chat/completions": "在这里填写重定向的api.openai.com的URL"}
# 举例: API_URL_REDIRECT = {"https://api.openai.com/v1/chat/completions": "https://reverse-proxy-url/v1/chat/completions"}
# 举例: API_URL_REDIRECT = {"https://api.openai.com/v1/chat/completions": "https://reverse-proxy-url/v1/chat/completions", "http://localhost:11434/api/chat": "在这里填写您ollama的URL"}
API_URL_REDIRECT = {}


Expand Down Expand Up @@ -195,6 +195,12 @@
ALIYUN_SECRET="" # (无需填写)


# GPT-SOVITS 文本转语音服务的运行地址(将语言模型的生成文本朗读出来)
TTS_TYPE = "DISABLE" # LOCAL / LOCAL_SOVITS_API / DISABLE
GPT_SOVITS_URL = ""
EDGE_TTS_VOICE = "zh-CN-XiaoxiaoNeural"


# 接入讯飞星火大模型 https://console.xfyun.cn/services/iat
XFYUN_APPID = "00000000"
XFYUN_API_SECRET = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
Expand All @@ -217,6 +223,9 @@
# 零一万物(Yi Model) API KEY
YIMODEL_API_KEY = ""

# GROQ API KEY
GROQ_API_KEY = ""


# Mathpix 拥有执行PDF的OCR功能,但是需要注册账号
MATHPIX_APPID = ""
Expand Down Expand Up @@ -331,6 +340,9 @@
├── "Gemini"
│ └── GEMINI_API_KEY
├── "GROQ/*"等GROQ大模型
│ └── GROQ_API_KEY
└── "one-api-...(max_token=...)" 用一种更方便的方式接入one-api多模型管理界面
├── AVAIL_LLM_MODELS
Expand Down
58 changes: 58 additions & 0 deletions docs/use_tts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# 使用TTS文字转语音


## 1. 使用EDGE-TTS(简单)

将本项目配置项修改如下即可

```
TTS_TYPE = "EDGE_TTS"
EDGE_TTS_VOICE = "zh-CN-XiaoxiaoNeural"
```

## 2. 使用SoVITS(需要有显卡)

使用以下docker-compose.yml文件,先启动SoVITS服务API

1. 创建以下文件夹结构
```shell
.
├── docker-compose.yml
└── reference
├── clone_target_txt.txt
└── clone_target_wave.mp3
```
2. 其中`docker-compose.yml`为
```yaml
version: '3.8'
services:
gpt-sovits:
image: fuqingxu/sovits_gptac_trim:latest
container_name: sovits_gptac_container
working_dir: /workspace/gpt_sovits_demo
environment:
- is_half=False
- is_share=False
volumes:
- ./reference:/reference
ports:
- "19880:9880" # 19880 为 sovits api 的暴露端口,记住它
shm_size: 16G
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: "all"
capabilities: [gpu]
command: bash -c "python3 api.py"
```
3. 其中`clone_target_wave.mp3`为需要克隆的角色音频,`clone_target_txt.txt`为该音频对应的文字文本( https://wiki.biligame.com/ys/%E8%A7%92%E8%89%B2%E8%AF%AD%E9%9F%B3 )
4. 运行`docker-compose up`
5. 将本项目配置项修改如下即可
(19880 为 sovits api 的暴露端口,与docker-compose.yml中的端口对应)
```
TTS_TYPE = "LOCAL_SOVITS_API"
GPT_SOVITS_URL = "http://127.0.0.1:19880"
```
6. 启动本项目
34 changes: 21 additions & 13 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os; os.environ['no_proxy'] = '*' # 避免代理网络产生意外污染
import os, json; os.environ['no_proxy'] = '*' # 避免代理网络产生意外污染

help_menu_description = \
"""Github源代码开源和更新[地址🚀](https://github.com/binary-husky/gpt_academic),
Expand All @@ -14,7 +14,7 @@
</br></br>如何临时更换API_KEY: 在输入区输入临时API_KEY后提交(网页刷新后失效)"""

def enable_log(PATH_LOGGING):
import logging, uuid
import logging
admin_log_path = os.path.join(PATH_LOGGING, "admin")
os.makedirs(admin_log_path, exist_ok=True)
log_dir = os.path.join(admin_log_path, "chat_secrets.log")
Expand All @@ -29,13 +29,14 @@ def main():
if gr.__version__ not in ['3.32.9']:
raise ModuleNotFoundError("使用项目内置Gradio获取最优体验! 请运行 `pip install -r requirements.txt` 指令安装内置Gradio及其他依赖, 详情信息见requirements.txt.")
from request_llms.bridge_all import predict
from toolbox import format_io, find_free_port, on_file_uploaded, on_report_generated, get_conf, ArgsGeneralWrapper, load_chat_cookies, DummyWith
from toolbox import format_io, find_free_port, on_file_uploaded, on_report_generated, get_conf, ArgsGeneralWrapper, DummyWith
# 建议您复制一个config_private.py放自己的秘密, 如API和代理网址
proxies, WEB_PORT, LLM_MODEL, CONCURRENT_COUNT, AUTHENTICATION = get_conf('proxies', 'WEB_PORT', 'LLM_MODEL', 'CONCURRENT_COUNT', 'AUTHENTICATION')
CHATBOT_HEIGHT, LAYOUT, AVAIL_LLM_MODELS, AUTO_CLEAR_TXT = get_conf('CHATBOT_HEIGHT', 'LAYOUT', 'AVAIL_LLM_MODELS', 'AUTO_CLEAR_TXT')
ENABLE_AUDIO, AUTO_CLEAR_TXT, PATH_LOGGING, AVAIL_THEMES, THEME, ADD_WAIFU = get_conf('ENABLE_AUDIO', 'AUTO_CLEAR_TXT', 'PATH_LOGGING', 'AVAIL_THEMES', 'THEME', 'ADD_WAIFU')
NUM_CUSTOM_BASIC_BTN, SSL_KEYFILE, SSL_CERTFILE = get_conf('NUM_CUSTOM_BASIC_BTN', 'SSL_KEYFILE', 'SSL_CERTFILE')
DARK_MODE, INIT_SYS_PROMPT, ADD_WAIFU = get_conf('DARK_MODE', 'INIT_SYS_PROMPT', 'ADD_WAIFU')
DARK_MODE, INIT_SYS_PROMPT, ADD_WAIFU, TTS_TYPE = get_conf('DARK_MODE', 'INIT_SYS_PROMPT', 'ADD_WAIFU', 'TTS_TYPE')
if LLM_MODEL not in AVAIL_LLM_MODELS: AVAIL_LLM_MODELS += [LLM_MODEL]

# 如果WEB_PORT是-1, 则随机选取WEB端口
PORT = find_free_port() if WEB_PORT <= 0 else WEB_PORT
Expand Down Expand Up @@ -79,15 +80,18 @@ def main():
cancel_handles = []
customize_btns = {}
predefined_btns = {}
from shared_utils.cookie_manager import make_cookie_cache, make_history_cache
with gr.Blocks(title="GPT 学术优化", theme=set_theme, analytics_enabled=False, css=advanced_css) as app_block:
gr.HTML(title_html)
secret_css, web_cookie_cache = gr.Textbox(visible=False), gr.Textbox(visible=False)
cookies = gr.State(load_chat_cookies())
secret_css = gr.Textbox(visible=False, elem_id="secret_css")


cookies, web_cookie_cache = make_cookie_cache() # 定义 后端state(cookies)、前端(web_cookie_cache)两兄弟
with gr_L1():
with gr_L2(scale=2, elem_id="gpt-chat"):
chatbot = gr.Chatbot(label=f"当前模型:{LLM_MODEL}", elem_id="gpt-chatbot")
if LAYOUT == "TOP-DOWN": chatbot.style(height=CHATBOT_HEIGHT)
history = gr.State([])
history, history_cache, history_cache_update = make_history_cache() # 定义 后端state(history)、前端(history_cache)、后端setter(history_cache_update)三兄弟
with gr_L2(scale=1, elem_id="gpt-panel"):
with gr.Accordion("输入区", open=True, elem_id="input-panel") as area_input_primary:
with gr.Row():
Expand Down Expand Up @@ -155,7 +159,7 @@ def main():
file_upload_2 = gr.Files(label="任何文件, 推荐上传压缩文件(zip, tar)", file_count="multiple", elem_id="elem_upload_float")

with gr.Tab("更换模型", elem_id="interact-panel"):
md_dropdown = gr.Dropdown(AVAIL_LLM_MODELS, value=LLM_MODEL, label="更换LLM模型/请求源").style(container=False)
md_dropdown = gr.Dropdown(AVAIL_LLM_MODELS, value=LLM_MODEL, elem_id="elem_model_sel", label="更换LLM模型/请求源").style(container=False)
top_p = gr.Slider(minimum=-0, maximum=1.0, value=1.0, step=0.01,interactive=True, label="Top-p (nucleus sampling)",)
temperature = gr.Slider(minimum=-0, maximum=2.0, value=1.0, step=0.01, interactive=True, label="Temperature", elem_id="elem_temperature")
max_length_sl = gr.Slider(minimum=256, maximum=1024*32, value=4096, step=128, interactive=True, label="Local LLM MaxLength",)
Expand All @@ -164,6 +168,8 @@ def main():
_js="""(temperature)=>gpt_academic_gradio_saveload("save", "elem_prompt", "js_temperature_cookie", temperature)""")
system_prompt.change(None, inputs=[system_prompt], outputs=None,
_js="""(system_prompt)=>gpt_academic_gradio_saveload("save", "elem_prompt", "js_system_prompt_cookie", system_prompt)""")
md_dropdown.change(None, inputs=[md_dropdown], outputs=None,
_js="""(md_dropdown)=>gpt_academic_gradio_saveload("save", "elem_model_sel", "js_md_dropdown_cookie", md_dropdown)""")

with gr.Tab("界面外观", elem_id="interact-panel"):
theme_dropdown = gr.Dropdown(AVAIL_THEMES, value=THEME, label="更换UI主题").style(container=False)
Expand Down Expand Up @@ -247,8 +253,10 @@ def fn_area_visibility_2(a):
cancel_handles.append(submitBtn2.click(**predict_args))
resetBtn.click(None, None, [chatbot, history, status], _js=js_code_reset) # 先在前端快速清除chatbot&status
resetBtn2.click(None, None, [chatbot, history, status], _js=js_code_reset) # 先在前端快速清除chatbot&status
resetBtn.click(lambda: ([], [], "已重置"), None, [chatbot, history, status]) # 再在后端清除history
resetBtn2.click(lambda: ([], [], "已重置"), None, [chatbot, history, status]) # 再在后端清除history
reset_server_side_args = (lambda history: ([], [], "已重置", json.dumps(history)),
[history], [chatbot, history, status, history_cache])
resetBtn.click(*reset_server_side_args) # 再在后端清除history,把history转存history_cache备用
resetBtn2.click(*reset_server_side_args) # 再在后端清除history,把history转存history_cache备用
clearBtn.click(None, None, [txt, txt2], _js=js_code_clear)
clearBtn2.click(None, None, [txt, txt2], _js=js_code_clear)
if AUTO_CLEAR_TXT:
Expand All @@ -271,7 +279,7 @@ def fn_area_visibility_2(a):
for k in plugins:
if not plugins[k].get("AsButton", True): continue
click_handle = plugins[k]["Button"].click(ArgsGeneralWrapper(plugins[k]["Function"]), [*input_combo], output_combo)
click_handle.then(on_report_generated, [cookies, file_upload, chatbot], [cookies, file_upload, chatbot])
click_handle.then(on_report_generated, [cookies, file_upload, chatbot], [cookies, file_upload, chatbot]).then(None, [plugins[k]["Button"]], None, _js=r"(fn)=>on_plugin_exe_complete(fn)")
cancel_handles.append(click_handle)
# 函数插件-下拉菜单与随变按钮的互动
def on_dropdown_changed(k):
Expand Down Expand Up @@ -309,7 +317,7 @@ def route(request: gr.Request, k, *args, **kwargs):
if k in [r"打开插件列表", r"请先从插件列表中选择"]: return
yield from ArgsGeneralWrapper(plugins[k]["Function"])(request, *args, **kwargs)
click_handle = switchy_bt.click(route,[switchy_bt, *input_combo], output_combo)
click_handle.then(on_report_generated, [cookies, file_upload, chatbot], [cookies, file_upload, chatbot])
click_handle.then(on_report_generated, [cookies, file_upload, chatbot], [cookies, file_upload, chatbot]).then(None, [switchy_bt], None, _js=r"(fn)=>on_plugin_exe_complete(fn)")
cancel_handles.append(click_handle)
# 终止按钮的回调函数注册
stopBtn.click(fn=None, inputs=None, outputs=None, cancels=cancel_handles)
Expand Down Expand Up @@ -342,7 +350,7 @@ def deal_audio(audio, cookies):
app_block.load(load_web_cookie_cache, inputs = [web_cookie_cache, cookies],
outputs = [web_cookie_cache, cookies, *customize_btns.values(), *predefined_btns.values()], _js=js_code_for_persistent_cookie_init)

app_block.load(None, inputs=[], outputs=None, _js=f"""()=>GptAcademicJavaScriptInit("{DARK_MODE}","{INIT_SYS_PROMPT}","{ADD_WAIFU}","{LAYOUT}")""") # 配置暗色主题或亮色主题
app_block.load(None, inputs=[], outputs=None, _js=f"""()=>GptAcademicJavaScriptInit("{DARK_MODE}","{INIT_SYS_PROMPT}","{ADD_WAIFU}","{LAYOUT}","{TTS_TYPE}")""") # 配置暗色主题或亮色主题

# gradio的inbrowser触发不太稳定,回滚代码到原始的浏览器打开函数
def run_delayed_tasks():
Expand Down