mirror of
https://github.com/modelscope/modelscope.git
synced 2025-12-16 16:27:45 +01:00
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:
@@ -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
|
||||
```
|
||||
|
||||
|
||||
@@ -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 環境のセットアップ
|
||||
|
||||
@@ -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
|
||||
```
|
||||
|
||||
|
||||
@@ -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,10 +156,11 @@ def generate_share_image(state):
|
||||
return gr.Image.update(visible=True, value=img_pil)
|
||||
|
||||
|
||||
# Gradio界面构建
|
||||
block = gr.Blocks()
|
||||
def create_app():
|
||||
# Gradio界面构建
|
||||
block = gr.Blocks()
|
||||
|
||||
with block as demo:
|
||||
with block as demo:
|
||||
current_chapter_index = 0
|
||||
current_challenge_index = 0
|
||||
state = gr.State(
|
||||
@@ -170,24 +171,24 @@ with block as demo:
|
||||
gr.Markdown("""<center><font size=6>完蛋!我被LLM包围了!</center>""")
|
||||
gr.Markdown("""<font size=3>欢迎来玩LLM Riddles复刻版:完蛋!我被LLM包围了!
|
||||
|
||||
你将通过本游戏对大型语言模型产生更深刻的理解。
|
||||
你将通过本游戏对大型语言模型产生更深刻的理解。
|
||||
|
||||
在本游戏中,你需要构造一个提给一个大型语言模型的问题,使得它回复的答案符合要求。""")
|
||||
在本游戏中,你需要构造一个提给一个大型语言模型的问题,使得它回复的答案符合要求。""")
|
||||
|
||||
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,10 +201,11 @@ 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;">
|
||||
<div style="text-align: center;">
|
||||
<span>
|
||||
Powered by <a href="https://dashscope.aliyun.com/" target="_blank">
|
||||
<img src=
|
||||
@@ -211,7 +213,11 @@ with block as demo:
|
||||
style="display: inline; height: 20px; vertical-align: bottom;"/>DashScope
|
||||
</a>
|
||||
</span>
|
||||
</div>
|
||||
""")
|
||||
</div>
|
||||
""")
|
||||
|
||||
demo.queue(concurrency_count=10).launch(height=800, share=True)
|
||||
demo.queue(concurrency_count=10).launch(height=800, share=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
create_app()
|
||||
|
||||
@@ -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() == '魔搭')
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
@@ -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']
|
||||
|
||||
13
examples/apps/llm_riddles/test_validate_fn.py
Normal file
13
examples/apps/llm_riddles/test_validate_fn.py
Normal 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')
|
||||
Reference in New Issue
Block a user