Feat/llmriddle update (#640)

* format chatglm output

* format code and add one problem to llm riddle

* fix app warning

* refine app.py and add test fn for validate fn
This commit is contained in:
wenmeng zhou
2023-11-13 23:29:25 +08:00
committed by GitHub
parent a831e3a85c
commit 5b67c02cef
7 changed files with 99 additions and 68 deletions

View File

@@ -202,7 +202,7 @@ CPU docker image
registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-py37-torch1.11.0-tf1.15.5-1.6.1
# py38
registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-py38-torch1.11.0-tf1.15.5-1.6.1
registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-py38-torch2.0.1-tf2.13.0-1.9.5
```
GPU docker image
@@ -211,7 +211,7 @@ GPU docker image
registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-cuda11.3.0-py37-torch1.11.0-tf1.15.5-1.6.1
# py38
registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-cuda11.3.0-py38-torch1.11.0-tf1.15.5-1.6.1
registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-cuda11.8.0-py38-torch2.0.1-tf2.13.0-1.9.5
```
## Setup Local Python Environment
@@ -220,7 +220,7 @@ One can also set up local ModelScope environment using pip and conda. ModelScop
We suggest [anaconda](https://docs.anaconda.com/anaconda/install/) for creating local python environment:
```shell
conda create -n modelscope python=3.9
conda create -n modelscope python=3.8
conda activate modelscope
```

View File

@@ -208,7 +208,7 @@ CPU docker イメージ
registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-py37-torch1.11.0-tf1.15.5-1.6.1
# py38
registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-py38-torch1.11.0-tf1.15.5-1.6.1
registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-py38-torch2.0.1-tf2.13.0-1.9.5
```
GPU docker イメージ
@@ -217,7 +217,7 @@ GPU docker イメージ
registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-cuda11.3.0-py37-torch1.11.0-tf1.15.5-1.6.1
# py38
registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-cuda11.3.0-py38-torch1.11.0-tf1.15.5-1.6.1
registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-cuda11.8.0-py38-torch2.0.1-tf2.13.0-1.9.5
```
## ローカル Python 環境のセットアップ

View File

@@ -195,7 +195,7 @@ CPU镜像
registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-py37-torch1.11.0-tf1.15.5-1.6.1
# py38
registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-py38-torch1.11.0-tf1.15.5-1.6.1
registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-py38-torch2.0.1-tf2.13.0-1.9.5
```
GPU镜像
@@ -204,14 +204,14 @@ GPU镜像
registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-cuda11.3.0-py37-torch1.11.0-tf1.15.5-1.6.1
# py38
registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-cuda11.3.0-py38-torch1.11.0-tf1.15.5-1.6.1
registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-cuda11.8.0-py38-torch2.0.1-tf2.13.0-1.9.5
```
## 搭建本地Python环境
你也可以使用pip和conda搭建本地python环境我们推荐使用[Anaconda](https://docs.anaconda.com/anaconda/install/)安装完成后执行如下命令为modelscope library创建对应的python环境
你也可以使用pip和conda搭建本地python环境ModelScope支持python3.7+以上环境,我们推荐使用[Anaconda](https://docs.anaconda.com/anaconda/install/)安装完成后执行如下命令为modelscope library创建对应的python环境
```shell
conda create -n modelscope python=3.7
conda create -n modelscope python=3.8
conda activate modelscope
```

View File

@@ -115,8 +115,8 @@ def generate_response(input, model_name):
def on_submit(input, model_name, state):
# model_name = os.environ.get('MODEL', 'qwen-plus')
name_map = {
'通义千问max': 'qwen-max',
'通义千问plus': 'qwen-plus',
'qwen-max': 'qwen-max',
'qwen-plus': 'qwen-plus',
'chatglm-turbo': 'chatglm_turbo',
}
gen_fn = functools.partial(
@@ -156,6 +156,7 @@ def generate_share_image(state):
return gr.Image.update(visible=True, value=img_pil)
def create_app():
# Gradio界面构建
block = gr.Blocks()
@@ -176,18 +177,18 @@ with block as demo:
model_selector = gr.Dropdown(
label='选择模型',
choices=['通义千问max', '通义千问plus', 'chatglm-turbo'],
value='通义千问plus')
choices=['qwen-max', 'qwen-plus', 'chatglm-turbo'],
value='qwen-max')
question_info = gr.Markdown(
update_question_info(current_chapter_index, current_challenge_index))
update_question_info(current_chapter_index,
current_challenge_index))
challenge_info = gr.Textbox(
value=update_challenge_info(current_chapter_index,
current_challenge_index),
label='当前挑战',
disabled=True)
challenge_result = gr.Textbox(label='挑战结果', disabled=True)
chatbot = gr.Chatbot(
lines=8, label='Qwen-plus', elem_classes='control-height')
interactive=False)
challenge_result = gr.Textbox(label='挑战结果', interactive=False)
chatbot = gr.Chatbot(label='llm', elem_classes='control-height')
message = gr.Textbox(lines=2, label='输入')
with gr.Row():
@@ -200,7 +201,8 @@ with block as demo:
on_submit,
inputs=[message, model_selector, state],
outputs=[challenge_result, chatbot, question_info, challenge_info])
shareBtn.click(generate_share_image, inputs=[state], outputs=[shareImg])
shareBtn.click(
generate_share_image, inputs=[state], outputs=[shareImg])
gr.HTML("""
<div style="text-align: center;">
@@ -215,3 +217,7 @@ with block as demo:
""")
demo.queue(concurrency_count=10).launch(height=800, share=True)
if __name__ == '__main__':
create_app()

View File

@@ -1,4 +1,5 @@
import re
import unicodedata
def validate_palindrome_inverse(origin_input, response, generate_response):
@@ -86,5 +87,15 @@ challenge3 = {
(all(char not in input
for char in ['', '', 'dog']) and response.strip() == '汪~')
},
{
'title':
'第7题 魔搭 (🐶)',
'description':
'请提一个不包含任何中文字符、换行或空格的问题,使模型正好回答"魔搭"',
'validator':
lambda response, input: not any(
'CJK' in unicodedata.name(char, '') or char in '\t\n '
for char in input) and (response.strip() == '魔搭')
},
]
}

View File

@@ -136,6 +136,7 @@ class ZhiPu:
prompt=messages,
top_p=0.7,
temperature=0.9,
return_type='text',
)
if response['code'] == 200:
return response['data']['choices'][0]['content']

View File

@@ -0,0 +1,13 @@
from app import challenges
def test_valid():
for challenge in challenges:
for p in challenge['problems']:
val_fn = p['validator']
try:
val_fn('response', 'input')
except Exception:
import traceback
traceback.print_exc()
print(p, 'failed')