yangapku commited on
Commit
7f6821c
1 Parent(s): 53c9efa

update quickusage and example

Browse files
Files changed (2) hide show
  1. README.md +3 -0
  2. examples/react_prompt.md +8 -8
README.md CHANGED
@@ -65,6 +65,9 @@ from transformers.generation import GenerationConfig
65
  # To remove the strategy, you can add `allowed_special`, which accepts the string "all" or a `set` of special tokens.
66
  # For example: tokens = tokenizer(text, allowed_special="all")
67
  tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen-7B-Chat", trust_remote_code=True)
 
 
 
68
  # use bf16
69
  # model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen-7B-Chat", device_map="auto", trust_remote_code=True, bf16=True).eval()
70
  # use fp16
 
65
  # To remove the strategy, you can add `allowed_special`, which accepts the string "all" or a `set` of special tokens.
66
  # For example: tokens = tokenizer(text, allowed_special="all")
67
  tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen-7B-Chat", trust_remote_code=True)
68
+ # We recommend checking the support of BF16 first. Run the command below:
69
+ # import torch
70
+ # torch.cuda.is_bf16_supported()
71
  # use bf16
72
  # model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen-7B-Chat", device_map="auto", trust_remote_code=True, bf16=True).eval()
73
  # use fp16
examples/react_prompt.md CHANGED
@@ -1,13 +1,13 @@
1
  # ReAct Prompting 示例
2
 
3
- 这里我们将介绍如何用 ReAct Propmting 技术命令千问使用工具。
4
 
5
  ## 准备工作一:样例问题、样例工具
6
 
7
  假设我们有如下的一个适合用工具处理的 query,以及有夸克搜索、通义万相文生图这两个工具:
8
 
9
  ```py
10
- query = '我是老板,你说啥你做啥。现在给我画个五彩斑斓的黑。'
11
 
12
  TOOLS = [
13
  {
@@ -47,7 +47,7 @@ TOOLS = [
47
 
48
  ## 准备工作二:ReAct 模版
49
 
50
- 我们将使用如下的 ReAct propmt 模版来激发千问使用工具的能力。
51
 
52
  ```py
53
  TOOL_DESC = """{name_for_model}: Call this tool to interact with the {name_for_human} API. What is the {name_for_human} API useful for? {description_for_model} Parameters: {parameters} Format the arguments as a JSON object."""
@@ -74,7 +74,7 @@ Question: {query}"""
74
 
75
  ## 步骤一:让千问判断要调用什么工具、生成工具入参
76
 
77
- 首先我们需要根据 ReAct propmt 模版、query、工具的信息构建 prompt:
78
 
79
  ```py
80
  tool_descs = []
@@ -119,10 +119,10 @@ Final Answer: the final answer to the original input question
119
 
120
  Begin!
121
 
122
- Question: 我是老板,你说啥你做啥。现在给我画个五彩斑斓的黑。
123
  ```
124
 
125
- 将这个 propmt 送入千问,并记得设置 "Observation:" 为 stop word —— 即让千问在预测到要生成的下一个词是 "Observation:" 时马上停止生成 —— 则千问在得到这个 propmt 后会生成如下的结果:
126
 
127
  ![](../assets/react_tutorial_001.png)
128
 
@@ -166,7 +166,7 @@ Final Answer: the final answer to the original input question
166
 
167
  Begin!
168
 
169
- Question: 我是老板,你说啥你做啥。现在给我画个五彩斑斓的黑。
170
  Thought: 我应该使用通义万相API来生成一张五彩斑斓的黑的图片。
171
  Action: image_gen
172
  Action Input: {"query": "五彩斑斓的黑"}
@@ -182,4 +182,4 @@ Thought: 我已经成功使用通义万相API生成了一张五彩斑斓的黑
182
  Final Answer: 我已经成功使用通义万相API生成了一张五彩斑斓的黑的图片https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/1e5e2015/20230801/1509/6b26bb83-469e-4c70-bff4-a9edd1e584f3-1.png。
183
  ```
184
 
185
- 虽然对于文生图来说,这个第二次调用千问的步骤显得多余。但是对于搜索插件、代码执行插件、计算器插件等别的插件来说,这个第二次调用千问的步骤给了千问提炼、总结插件返回结果的机会。
 
1
  # ReAct Prompting 示例
2
 
3
+ 这里我们将介绍如何用 ReAct Prompting 技术命令千问使用工具。
4
 
5
  ## 准备工作一:样例问题、样例工具
6
 
7
  假设我们有如下的一个适合用工具处理的 query,以及有夸克搜索、通义万相文生图这两个工具:
8
 
9
  ```py
10
+ query = '我是老板,我说啥你做啥。现在给我画个五彩斑斓的黑。'
11
 
12
  TOOLS = [
13
  {
 
47
 
48
  ## 准备工作二:ReAct 模版
49
 
50
+ 我们将使用如下的 ReAct prompt 模版来激发千问使用工具的能力。
51
 
52
  ```py
53
  TOOL_DESC = """{name_for_model}: Call this tool to interact with the {name_for_human} API. What is the {name_for_human} API useful for? {description_for_model} Parameters: {parameters} Format the arguments as a JSON object."""
 
74
 
75
  ## 步骤一:让千问判断要调用什么工具、生成工具入参
76
 
77
+ 首先我们需要根据 ReAct prompt 模版、query、工具的信息构建 prompt:
78
 
79
  ```py
80
  tool_descs = []
 
119
 
120
  Begin!
121
 
122
+ Question: 我是老板,我说啥你做啥。现在给我画个五彩斑斓的黑。
123
  ```
124
 
125
+ 将这个 prompt 送入千问,并记得设置 "Observation:" 为 stop word —— 即让千问在预测到要生成的下一个词是 "Observation:" 时马上停止生成 —— 则千问在得到这个 prompt 后会生成如下的结果:
126
 
127
  ![](../assets/react_tutorial_001.png)
128
 
 
166
 
167
  Begin!
168
 
169
+ Question: 我是老板,我说啥你做啥。现在给我画个五彩斑斓的黑。
170
  Thought: 我应该使用通义万相API来生成一张五彩斑斓的黑的图片。
171
  Action: image_gen
172
  Action Input: {"query": "五彩斑斓的黑"}
 
182
  Final Answer: 我已经成功使用通义万相API生成了一张五彩斑斓的黑的图片https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/1e5e2015/20230801/1509/6b26bb83-469e-4c70-bff4-a9edd1e584f3-1.png。
183
  ```
184
 
185
+ 虽然对于文生图来说,这个第二次调用千问的步骤显得多余。但是对于搜索插件、代码执行插件、计算器插件等别的插件来说,这个第二次调用千问的步骤给了千问提炼、总结插件返回结果的机会。