Spaces:
Runtime error
Runtime error
zjowowen
commited on
Commit
•
844b93e
1
Parent(s):
b6924fe
feature(zjow): add chatglm api support (#13)
Browse files- README.md +18 -0
- README_zh.md +18 -4
- app.py +4 -2
- llmriddles/llms/__init__.py +1 -0
- llmriddles/llms/chatglm.py +26 -0
- requirements-dev.txt +11 -0
- requirements.txt +1 -2
README.md
CHANGED
@@ -21,6 +21,16 @@ We provide an online version for players to directly access and try out.
|
|
21 |
- [ChatGPT + Chinese(w/ key)](http://llmriddles.opendilab.net/)
|
22 |
|
23 |
Local deployment can be done in the following ways:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
### ChatGPT + Chinese
|
25 |
```shell
|
26 |
QUESTION_LANG=cn QUESTION_LLM='chatgpt' QUESTION_LLM_KEY=<your API key> python3 -u app.py
|
@@ -29,6 +39,14 @@ QUESTION_LANG=cn QUESTION_LLM='chatgpt' QUESTION_LLM_KEY=<your API key> python3
|
|
29 |
```shell
|
30 |
QUESTION_LANG=en QUESTION_LLM='chatgpt' QUESTION_LLM_KEY=<your API key> python3 -u app.py
|
31 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
### Mistral-7B-Instruct-v0.1 + English
|
33 |
```shell
|
34 |
QUESTION_LANG=en QUESTION_LLM='mistral-7b' python3 -u app.py
|
|
|
21 |
- [ChatGPT + Chinese(w/ key)](http://llmriddles.opendilab.net/)
|
22 |
|
23 |
Local deployment can be done in the following ways:
|
24 |
+
## Installation
|
25 |
+
### Use ChatGPT / ChatGLM API
|
26 |
+
```shell
|
27 |
+
pip3 install -r requirements.txt
|
28 |
+
```
|
29 |
+
### Do Mistral-7B-Instruct-v0.1 local inference
|
30 |
+
```shell
|
31 |
+
pip3 install -r requirements-dev.txt
|
32 |
+
```
|
33 |
+
## Launch
|
34 |
### ChatGPT + Chinese
|
35 |
```shell
|
36 |
QUESTION_LANG=cn QUESTION_LLM='chatgpt' QUESTION_LLM_KEY=<your API key> python3 -u app.py
|
|
|
39 |
```shell
|
40 |
QUESTION_LANG=en QUESTION_LLM='chatgpt' QUESTION_LLM_KEY=<your API key> python3 -u app.py
|
41 |
```
|
42 |
+
### ChatGLM + Chinese
|
43 |
+
```shell
|
44 |
+
QUESTION_LANG=cn QUESTION_LLM='chatglm' QUESTION_LLM_KEY=<your API key> python3 -u app.py
|
45 |
+
```
|
46 |
+
### ChatGLM + English
|
47 |
+
```shell
|
48 |
+
QUESTION_LANG=en QUESTION_LLM='chatglm' QUESTION_LLM_KEY=<your API key> python3 -u app.py
|
49 |
+
```
|
50 |
### Mistral-7B-Instruct-v0.1 + English
|
51 |
```shell
|
52 |
QUESTION_LANG=en QUESTION_LLM='mistral-7b' python3 -u app.py
|
README_zh.md
CHANGED
@@ -21,6 +21,16 @@
|
|
21 |
- [ChatGPT + 中文(已预设api key)](http://llmriddles.opendilab.net/)
|
22 |
|
23 |
本地部署可以通过以下方式:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
### ChatGPT + 中文
|
25 |
```shell
|
26 |
QUESTION_LANG=cn QUESTION_LLM='chatgpt' QUESTION_LLM_KEY=<your API key> python3 -u app.py
|
@@ -29,13 +39,17 @@ QUESTION_LANG=cn QUESTION_LLM='chatgpt' QUESTION_LLM_KEY=<your API key> python3
|
|
29 |
```shell
|
30 |
QUESTION_LANG=en QUESTION_LLM='chatgpt' QUESTION_LLM_KEY=<your API key> python3 -u app.py
|
31 |
```
|
32 |
-
###
|
|
|
|
|
|
|
|
|
33 |
```shell
|
34 |
-
QUESTION_LANG=
|
35 |
```
|
36 |
-
###
|
37 |
```shell
|
38 |
-
QUESTION_LANG=en QUESTION_LLM='
|
39 |
```
|
40 |
## :technologist: 为什么制作这个游戏
|
41 |
|
|
|
21 |
- [ChatGPT + 中文(已预设api key)](http://llmriddles.opendilab.net/)
|
22 |
|
23 |
本地部署可以通过以下方式:
|
24 |
+
## 安装
|
25 |
+
### ChatGPT 或 ChatGLM API
|
26 |
+
```shell
|
27 |
+
pip3 install -r requirements.txt
|
28 |
+
```
|
29 |
+
### Mistral-7B-Instruct-v0.1 本地推理
|
30 |
+
```shell
|
31 |
+
pip3 install -r requirements-dev.txt
|
32 |
+
```
|
33 |
+
## 启动
|
34 |
### ChatGPT + 中文
|
35 |
```shell
|
36 |
QUESTION_LANG=cn QUESTION_LLM='chatgpt' QUESTION_LLM_KEY=<your API key> python3 -u app.py
|
|
|
39 |
```shell
|
40 |
QUESTION_LANG=en QUESTION_LLM='chatgpt' QUESTION_LLM_KEY=<your API key> python3 -u app.py
|
41 |
```
|
42 |
+
### ChatGLM + 中文
|
43 |
+
```shell
|
44 |
+
QUESTION_LANG=cn QUESTION_LLM='chatglm' QUESTION_LLM_KEY=<your API key> python3 -u app.py
|
45 |
+
```
|
46 |
+
### ChatGLM + 英文
|
47 |
```shell
|
48 |
+
QUESTION_LANG=en QUESTION_LLM='chatglm' QUESTION_LLM_KEY=<your API key> python3 -u app.py
|
49 |
```
|
50 |
+
### Mistral-7B-Instruct-v0.1 + 英文
|
51 |
```shell
|
52 |
+
QUESTION_LANG=en QUESTION_LLM='mistral-7b' python3 -u app.py
|
53 |
```
|
54 |
## :technologist: 为什么制作这个游戏
|
55 |
|
app.py
CHANGED
@@ -13,7 +13,7 @@ _QUESTIONS = list_ordered_questions()
|
|
13 |
_LANG = os.environ.get('QUESTION_LANG', 'cn')
|
14 |
assert _LANG in ['cn', 'en'], _LANG
|
15 |
_LLM = os.environ.get('QUESTION_LLM', 'chatgpt')
|
16 |
-
assert _LLM in ['chatgpt', 'mistral-7b'], _LLM
|
17 |
_LLM_KEY = os.environ.get('QUESTION_LLM_KEY', None)
|
18 |
_DEBUG = os.environ.get('DEBUG', 'false').lower() == 'true'
|
19 |
|
@@ -105,12 +105,14 @@ else:
|
|
105 |
|
106 |
|
107 |
def _need_api_key():
|
108 |
-
return _LLM == 'chatgpt' and _LLM_KEY is None
|
109 |
|
110 |
|
111 |
def _get_api_key_cfgs(api_key):
|
112 |
if _LLM == 'chatgpt':
|
113 |
return {'api_key': api_key}
|
|
|
|
|
114 |
else:
|
115 |
return {}
|
116 |
|
|
|
13 |
_LANG = os.environ.get('QUESTION_LANG', 'cn')
|
14 |
assert _LANG in ['cn', 'en'], _LANG
|
15 |
_LLM = os.environ.get('QUESTION_LLM', 'chatgpt')
|
16 |
+
assert _LLM in ['chatgpt', 'chatglm', 'mistral-7b'], _LLM
|
17 |
_LLM_KEY = os.environ.get('QUESTION_LLM_KEY', None)
|
18 |
_DEBUG = os.environ.get('DEBUG', 'false').lower() == 'true'
|
19 |
|
|
|
105 |
|
106 |
|
107 |
def _need_api_key():
|
108 |
+
return (_LLM == 'chatgpt' or _LLM == 'chatglm') and _LLM_KEY is None
|
109 |
|
110 |
|
111 |
def _get_api_key_cfgs(api_key):
|
112 |
if _LLM == 'chatgpt':
|
113 |
return {'api_key': api_key}
|
114 |
+
elif _LLM == 'chatglm':
|
115 |
+
return {'api_key': api_key}
|
116 |
else:
|
117 |
return {}
|
118 |
|
llmriddles/llms/__init__.py
CHANGED
@@ -1,3 +1,4 @@
|
|
1 |
from .base import register_llm, get_llm_fn
|
2 |
from .chatgpt import ask_chatgpt
|
|
|
3 |
from .mistral import ask_mistral_7b_instruct
|
|
|
1 |
from .base import register_llm, get_llm_fn
|
2 |
from .chatgpt import ask_chatgpt
|
3 |
+
from .chatglm import ask_chatglm
|
4 |
from .mistral import ask_mistral_7b_instruct
|
llmriddles/llms/chatglm.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import zhipuai
|
2 |
+
from .base import register_llm
|
3 |
+
|
4 |
+
|
5 |
+
def ask_chatglm(message: str, api_key: str):
|
6 |
+
zhipuai.api_key = api_key
|
7 |
+
|
8 |
+
response = zhipuai.model_api.invoke(
|
9 |
+
model="chatglm_turbo",
|
10 |
+
prompt=[{
|
11 |
+
"role": "user",
|
12 |
+
"content": message
|
13 |
+
}],
|
14 |
+
top_p=0.7,
|
15 |
+
temperature=0.9,
|
16 |
+
)
|
17 |
+
|
18 |
+
response_msg = response['data']['choices'][0]['content']
|
19 |
+
# strip the front and end '"'
|
20 |
+
if len(response_msg) >= 2:
|
21 |
+
response_msg = response_msg[1:-1]
|
22 |
+
|
23 |
+
return response_msg
|
24 |
+
|
25 |
+
|
26 |
+
register_llm('chatglm', ask_chatglm)
|
requirements-dev.txt
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
hbutils>=0.9.1
|
2 |
+
tqdm
|
3 |
+
requests>=2.20
|
4 |
+
gradio==4.1.1
|
5 |
+
openai>=1
|
6 |
+
zhipuai
|
7 |
+
sympy
|
8 |
+
flask
|
9 |
+
transformers
|
10 |
+
torch
|
11 |
+
huggingface-hub
|
requirements.txt
CHANGED
@@ -3,6 +3,5 @@ tqdm
|
|
3 |
requests>=2.20
|
4 |
gradio==4.1.1
|
5 |
openai>=1
|
|
|
6 |
sympy
|
7 |
-
flask
|
8 |
-
transformers
|
|
|
3 |
requests>=2.20
|
4 |
gradio==4.1.1
|
5 |
openai>=1
|
6 |
+
zhipuai
|
7 |
sympy
|
|
|
|