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
|
registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-py37-torch1.11.0-tf1.15.5-1.6.1
|
||||||
|
|
||||||
# py38
|
# 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
|
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
|
registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-cuda11.3.0-py37-torch1.11.0-tf1.15.5-1.6.1
|
||||||
|
|
||||||
# py38
|
# 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
|
## 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:
|
We suggest [anaconda](https://docs.anaconda.com/anaconda/install/) for creating local python environment:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
conda create -n modelscope python=3.9
|
conda create -n modelscope python=3.8
|
||||||
conda activate modelscope
|
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
|
registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-py37-torch1.11.0-tf1.15.5-1.6.1
|
||||||
|
|
||||||
# py38
|
# 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 イメージ
|
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
|
registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-cuda11.3.0-py37-torch1.11.0-tf1.15.5-1.6.1
|
||||||
|
|
||||||
# py38
|
# 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 環境のセットアップ
|
## ローカル Python 環境のセットアップ
|
||||||
|
|||||||
24
README_zh.md
24
README_zh.md
@@ -53,19 +53,19 @@ ModelScope开源了数百个(当前700+)模型,涵盖自然语言处理、计
|
|||||||
自然语言处理:
|
自然语言处理:
|
||||||
|
|
||||||
* [ChatGLM3-6B](https://modelscope.cn/models/ZhipuAI/chatglm3-6b/summary)
|
* [ChatGLM3-6B](https://modelscope.cn/models/ZhipuAI/chatglm3-6b/summary)
|
||||||
|
|
||||||
* [Qwen-14B-Chat](https://modelscope.cn/models/qwen/Qwen-14B-Chat/summary)
|
* [Qwen-14B-Chat](https://modelscope.cn/models/qwen/Qwen-14B-Chat/summary)
|
||||||
|
|
||||||
* [Baichuan2-13B-Chat](https://modelscope.cn/models/baichuan-inc/Baichuan2-13B-Chat/summary)
|
* [Baichuan2-13B-Chat](https://modelscope.cn/models/baichuan-inc/Baichuan2-13B-Chat/summary)
|
||||||
|
|
||||||
* [Ziya2-13B-Chat](https://modelscope.cn/models/Fengshenbang/Ziya2-13B-Chat/summary)
|
* [Ziya2-13B-Chat](https://modelscope.cn/models/Fengshenbang/Ziya2-13B-Chat/summary)
|
||||||
|
|
||||||
* [Internlm-chat-20b](https://modelscope.cn/models/Shanghai_AI_Laboratory/internlm-chat-20b/summary)
|
* [Internlm-chat-20b](https://modelscope.cn/models/Shanghai_AI_Laboratory/internlm-chat-20b/summary)
|
||||||
|
|
||||||
* [Udever-bloom-1b1](https://modelscope.cn/models/damo/udever-bloom-1b1/summary)
|
* [Udever-bloom-1b1](https://modelscope.cn/models/damo/udever-bloom-1b1/summary)
|
||||||
|
|
||||||
* [CoROM文本向量-中文-电商领域-base](https://modelscope.cn/models/damo/nlp_corom_sentence-embedding_chinese-base-ecom/summary)
|
* [CoROM文本向量-中文-电商领域-base](https://modelscope.cn/models/damo/nlp_corom_sentence-embedding_chinese-base-ecom/summary)
|
||||||
|
|
||||||
* [MGeo地址相似度匹配实体对齐-中文-地址领域-base](https://modelscope.cn/models/damo/mgeo_geographic_entity_alignment_chinese_base/summary)
|
* [MGeo地址相似度匹配实体对齐-中文-地址领域-base](https://modelscope.cn/models/damo/mgeo_geographic_entity_alignment_chinese_base/summary)
|
||||||
|
|
||||||
多模态:
|
多模态:
|
||||||
@@ -84,7 +84,7 @@ ModelScope开源了数百个(当前700+)模型,涵盖自然语言处理、计
|
|||||||
计算机视觉:
|
计算机视觉:
|
||||||
|
|
||||||
* [DamoFD人脸检测关键点模型-0.5G](https://modelscope.cn/models/damo/cv_ddsar_face-detection_iclr23-damofd/summary)
|
* [DamoFD人脸检测关键点模型-0.5G](https://modelscope.cn/models/damo/cv_ddsar_face-detection_iclr23-damofd/summary)
|
||||||
|
|
||||||
* [BSHM人像抠图](https://modelscope.cn/models/damo/cv_unet_image-matting/summary)
|
* [BSHM人像抠图](https://modelscope.cn/models/damo/cv_unet_image-matting/summary)
|
||||||
|
|
||||||
* [DCT-Net人像卡通化-3D](https://modelscope.cn/models/damo/cv_unet_person-image-cartoon-3d_compound-models/summary)
|
* [DCT-Net人像卡通化-3D](https://modelscope.cn/models/damo/cv_unet_person-image-cartoon-3d_compound-models/summary)
|
||||||
@@ -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
|
registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-py37-torch1.11.0-tf1.15.5-1.6.1
|
||||||
|
|
||||||
# py38
|
# 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镜像
|
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
|
registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-cuda11.3.0-py37-torch1.11.0-tf1.15.5-1.6.1
|
||||||
|
|
||||||
# py38
|
# 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环境
|
## 搭建本地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
|
```shell
|
||||||
conda create -n modelscope python=3.7
|
conda create -n modelscope python=3.8
|
||||||
conda activate modelscope
|
conda activate modelscope
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -115,8 +115,8 @@ def generate_response(input, model_name):
|
|||||||
def on_submit(input, model_name, state):
|
def on_submit(input, model_name, state):
|
||||||
# model_name = os.environ.get('MODEL', 'qwen-plus')
|
# model_name = os.environ.get('MODEL', 'qwen-plus')
|
||||||
name_map = {
|
name_map = {
|
||||||
'通义千问max': 'qwen-max',
|
'qwen-max': 'qwen-max',
|
||||||
'通义千问plus': 'qwen-plus',
|
'qwen-plus': 'qwen-plus',
|
||||||
'chatglm-turbo': 'chatglm_turbo',
|
'chatglm-turbo': 'chatglm_turbo',
|
||||||
}
|
}
|
||||||
gen_fn = functools.partial(
|
gen_fn = functools.partial(
|
||||||
@@ -156,62 +156,68 @@ def generate_share_image(state):
|
|||||||
return gr.Image.update(visible=True, value=img_pil)
|
return gr.Image.update(visible=True, value=img_pil)
|
||||||
|
|
||||||
|
|
||||||
# Gradio界面构建
|
def create_app():
|
||||||
block = gr.Blocks()
|
# Gradio界面构建
|
||||||
|
block = gr.Blocks()
|
||||||
|
|
||||||
with block as demo:
|
with block as demo:
|
||||||
current_chapter_index = 0
|
current_chapter_index = 0
|
||||||
current_challenge_index = 0
|
current_challenge_index = 0
|
||||||
state = gr.State(
|
state = gr.State(
|
||||||
dict(
|
dict(
|
||||||
current_challenge_index=current_challenge_index,
|
current_challenge_index=current_challenge_index,
|
||||||
current_chapter_index=current_chapter_index))
|
current_chapter_index=current_chapter_index))
|
||||||
|
|
||||||
gr.Markdown("""<center><font size=6>完蛋!我被LLM包围了!</center>""")
|
gr.Markdown("""<center><font size=6>完蛋!我被LLM包围了!</center>""")
|
||||||
gr.Markdown("""<font size=3>欢迎来玩LLM Riddles复刻版:完蛋!我被LLM包围了!
|
gr.Markdown("""<font size=3>欢迎来玩LLM Riddles复刻版:完蛋!我被LLM包围了!
|
||||||
|
|
||||||
你将通过本游戏对大型语言模型产生更深刻的理解。
|
你将通过本游戏对大型语言模型产生更深刻的理解。
|
||||||
|
|
||||||
在本游戏中,你需要构造一个提给一个大型语言模型的问题,使得它回复的答案符合要求。""")
|
在本游戏中,你需要构造一个提给一个大型语言模型的问题,使得它回复的答案符合要求。""")
|
||||||
|
|
||||||
model_selector = gr.Dropdown(
|
model_selector = gr.Dropdown(
|
||||||
label='选择模型',
|
label='选择模型',
|
||||||
choices=['通义千问max', '通义千问plus', 'chatglm-turbo'],
|
choices=['qwen-max', 'qwen-plus', 'chatglm-turbo'],
|
||||||
value='通义千问plus')
|
value='qwen-max')
|
||||||
question_info = gr.Markdown(
|
question_info = gr.Markdown(
|
||||||
update_question_info(current_chapter_index, current_challenge_index))
|
update_question_info(current_chapter_index,
|
||||||
challenge_info = gr.Textbox(
|
current_challenge_index))
|
||||||
value=update_challenge_info(current_chapter_index,
|
challenge_info = gr.Textbox(
|
||||||
current_challenge_index),
|
value=update_challenge_info(current_chapter_index,
|
||||||
label='当前挑战',
|
current_challenge_index),
|
||||||
disabled=True)
|
label='当前挑战',
|
||||||
challenge_result = gr.Textbox(label='挑战结果', disabled=True)
|
interactive=False)
|
||||||
chatbot = gr.Chatbot(
|
challenge_result = gr.Textbox(label='挑战结果', interactive=False)
|
||||||
lines=8, label='Qwen-plus', elem_classes='control-height')
|
chatbot = gr.Chatbot(label='llm', elem_classes='control-height')
|
||||||
message = gr.Textbox(lines=2, label='输入')
|
message = gr.Textbox(lines=2, label='输入')
|
||||||
|
|
||||||
with gr.Row():
|
with gr.Row():
|
||||||
submit = gr.Button('🚀 发送')
|
submit = gr.Button('🚀 发送')
|
||||||
shareBtn = gr.Button('💯 分享成绩')
|
shareBtn = gr.Button('💯 分享成绩')
|
||||||
|
|
||||||
shareImg = gr.Image(label='分享成绩', visible=False, width=400)
|
shareImg = gr.Image(label='分享成绩', visible=False, width=400)
|
||||||
|
|
||||||
submit.click(
|
submit.click(
|
||||||
on_submit,
|
on_submit,
|
||||||
inputs=[message, model_selector, state],
|
inputs=[message, model_selector, state],
|
||||||
outputs=[challenge_result, chatbot, question_info, challenge_info])
|
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("""
|
gr.HTML("""
|
||||||
<div style="text-align: center;">
|
<div style="text-align: center;">
|
||||||
<span>
|
<span>
|
||||||
Powered by <a href="https://dashscope.aliyun.com/" target="_blank">
|
Powered by <a href="https://dashscope.aliyun.com/" target="_blank">
|
||||||
<img src=
|
<img src=
|
||||||
"//img.alicdn.com/imgextra/i4/O1CN01SgKFXM1qLQwFvk6j5_!!6000000005479-2-tps-99-84.png"
|
"//img.alicdn.com/imgextra/i4/O1CN01SgKFXM1qLQwFvk6j5_!!6000000005479-2-tps-99-84.png"
|
||||||
style="display: inline; height: 20px; vertical-align: bottom;"/>DashScope
|
style="display: inline; height: 20px; vertical-align: bottom;"/>DashScope
|
||||||
</a>
|
</a>
|
||||||
</span>
|
</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 re
|
||||||
|
import unicodedata
|
||||||
|
|
||||||
|
|
||||||
def validate_palindrome_inverse(origin_input, response, generate_response):
|
def validate_palindrome_inverse(origin_input, response, generate_response):
|
||||||
@@ -86,5 +87,15 @@ challenge3 = {
|
|||||||
(all(char not in input
|
(all(char not in input
|
||||||
for char in ['狗', '汪', 'dog']) and response.strip() == '汪~')
|
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,
|
prompt=messages,
|
||||||
top_p=0.7,
|
top_p=0.7,
|
||||||
temperature=0.9,
|
temperature=0.9,
|
||||||
|
return_type='text',
|
||||||
)
|
)
|
||||||
if response['code'] == 200:
|
if response['code'] == 200:
|
||||||
return response['data']['choices'][0]['content']
|
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