JustinLin610 commited on
Commit
e08a91b
·
verified ·
1 Parent(s): d4eb1da

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +55 -26
README.md CHANGED
@@ -7,7 +7,7 @@ base_model:
7
  - Qwen/Qwen3-0.6B-Base
8
  ---
9
 
10
- # Qwen3-0.6B
11
  <a href="https://chat.qwen.ai/" target="_blank" style="margin: 2px;">
12
  <img alt="Chat" src="https://img.shields.io/badge/%F0%9F%92%9C%EF%B8%8F%20Qwen%20Chat%20-536af5" style="display: inline-block; vertical-align: middle;"/>
13
  </a>
@@ -47,14 +47,26 @@ KeyError: 'qwen3'
47
  The following contains a code snippet illustrating how to use the model generate content based on given inputs.
48
  ```python
49
  from mlx_lm import load, generate
 
50
  model, tokenizer = load("Qwen/Qwen3-0.6B-MLX-6bit")
51
- prompt = "hello, Introduce yourself, and what can you do ?"
 
52
  if tokenizer.chat_template is not None:
53
  messages = [{"role": "user", "content": prompt}]
54
  prompt = tokenizer.apply_chat_template(
55
- messages, add_generation_prompt=True
 
56
  )
57
- response = generate(model, tokenizer, prompt=prompt, verbose=True, max_tokens=1024)
 
 
 
 
 
 
 
 
 
58
  ```
59
 
60
  ## Switching Between Thinking and Non-Thinking Mode
@@ -108,6 +120,8 @@ Here is an example of a multi-turn conversation:
108
 
109
  ```python
110
  from mlx_lm import load, generate
 
 
111
  class QwenChatbot:
112
  def __init__(self, model_name="Qwen/Qwen3-0.6B-MLX-6bit"):
113
  self.model, self.tokenizer = load(model_name)
@@ -122,29 +136,36 @@ class QwenChatbot:
122
  add_generation_prompt=True
123
  )
124
 
125
- response = generate(self.model, self.tokenizer, prompt=text, verbose=True, max_tokens=32768)
 
 
 
 
 
 
126
  # Update history
127
  self.history.append({"role": "user", "content": user_input})
128
  self.history.append({"role": "assistant", "content": response})
129
 
130
  return response
131
 
 
132
  # Example Usage
133
  if __name__ == "__main__":
134
  chatbot = QwenChatbot()
135
 
136
  # First input (without /think or /no_think tags, thinking mode is enabled by default)
137
- user_input_1 = "How many r's in strawberries?"
138
  print(f"User: {user_input_1}")
139
  response_1 = chatbot.generate_response(user_input_1)
140
  print(f"Bot: {response_1}")
141
  print("----------------------")
142
 
143
  # Second input with /no_think
144
- user_input_2 = "Then, how many r's in blueberries? /no_think"
145
  print(f"User: {user_input_2}")
146
  response_2 = chatbot.generate_response(user_input_2)
147
- print(f"Bot: {response_2}")
148
  print("----------------------")
149
 
150
  # Third input with /think
@@ -168,47 +189,55 @@ from qwen_agent.agents import Assistant
168
 
169
  # Define LLM
170
  llm_cfg = {
171
- 'model': 'Qwen3-0.6B-MLX-6bit',
172
 
173
  # Use the endpoint provided by Alibaba Model Studio:
174
- # 'model_type': 'qwen_dashscope',
175
- # 'api_key': os.getenv('DASHSCOPE_API_KEY'),
176
 
177
  # Use a custom endpoint compatible with OpenAI API:
178
- 'model_server': 'http://localhost:8000/v1', # api_base
179
- 'api_key': 'EMPTY',
180
 
181
  # Other parameters:
182
- # 'generate_cfg': {
183
- # # Add: When the response content is `<think>this is the thought</think>this is the answer;
184
- # # Do not add: When the response has been separated by reasoning_content and content.
185
- # 'thought_in_content': True,
186
- # },
187
  }
188
 
189
  # Define Tools
190
  tools = [
191
- {'mcpServers': { # You can specify the MCP configuration file
192
- 'time': {
193
- 'command': 'uvx',
194
- 'args': ['mcp-server-time', '--local-timezone=Asia/Shanghai']
 
195
  },
196
  "fetch": {
197
  "command": "uvx",
198
- "args": ["mcp-server-fetch"]
199
- }
200
  }
201
  },
202
- 'code_interpreter', # Built-in tools
203
  ]
204
 
205
  # Define Agent
206
  bot = Assistant(llm=llm_cfg, function_list=tools)
207
 
208
  # Streaming generation
209
- messages = [{'role': 'user', 'content': 'https://qwenlm.github.io/blog/ Introduce the latest developments of Qwen'}]
 
 
 
 
 
 
210
  for responses in bot.run(messages=messages):
211
  pass
 
212
  print(responses)
213
  ```
214
 
 
7
  - Qwen/Qwen3-0.6B-Base
8
  ---
9
 
10
+ # Qwen3-0.6B-MLX-6bit
11
  <a href="https://chat.qwen.ai/" target="_blank" style="margin: 2px;">
12
  <img alt="Chat" src="https://img.shields.io/badge/%F0%9F%92%9C%EF%B8%8F%20Qwen%20Chat%20-536af5" style="display: inline-block; vertical-align: middle;"/>
13
  </a>
 
47
  The following contains a code snippet illustrating how to use the model generate content based on given inputs.
48
  ```python
49
  from mlx_lm import load, generate
50
+
51
  model, tokenizer = load("Qwen/Qwen3-0.6B-MLX-6bit")
52
+ prompt = "Hello, please introduce yourself and tell me what you can do."
53
+
54
  if tokenizer.chat_template is not None:
55
  messages = [{"role": "user", "content": prompt}]
56
  prompt = tokenizer.apply_chat_template(
57
+ messages,
58
+ add_generation_prompt=True
59
  )
60
+
61
+ response = generate(
62
+ model,
63
+ tokenizer,
64
+ prompt=prompt,
65
+ verbose=True,
66
+ max_tokens=1024
67
+ )
68
+
69
+ print(response)
70
  ```
71
 
72
  ## Switching Between Thinking and Non-Thinking Mode
 
120
 
121
  ```python
122
  from mlx_lm import load, generate
123
+
124
+
125
  class QwenChatbot:
126
  def __init__(self, model_name="Qwen/Qwen3-0.6B-MLX-6bit"):
127
  self.model, self.tokenizer = load(model_name)
 
136
  add_generation_prompt=True
137
  )
138
 
139
+ response = generate(
140
+ self.model,
141
+ self.tokenizer,
142
+ prompt=text,
143
+ verbose=True,
144
+ max_tokens=32768
145
+ )
146
  # Update history
147
  self.history.append({"role": "user", "content": user_input})
148
  self.history.append({"role": "assistant", "content": response})
149
 
150
  return response
151
 
152
+
153
  # Example Usage
154
  if __name__ == "__main__":
155
  chatbot = QwenChatbot()
156
 
157
  # First input (without /think or /no_think tags, thinking mode is enabled by default)
158
+ user_input_1 = "How many 'r's are in strawberries?"
159
  print(f"User: {user_input_1}")
160
  response_1 = chatbot.generate_response(user_input_1)
161
  print(f"Bot: {response_1}")
162
  print("----------------------")
163
 
164
  # Second input with /no_think
165
+ user_input_2 = "Then, how many 'r's are in blueberries? /no_think"
166
  print(f"User: {user_input_2}")
167
  response_2 = chatbot.generate_response(user_input_2)
168
+ print(f"Bot: {response_2}")
169
  print("----------------------")
170
 
171
  # Third input with /think
 
189
 
190
  # Define LLM
191
  llm_cfg = {
192
+ "model": "Qwen3-0.6B-MLX-6bit",
193
 
194
  # Use the endpoint provided by Alibaba Model Studio:
195
+ # "model_type": "qwen_dashscope",
196
+ # "api_key": os.getenv("DASHSCOPE_API_KEY"),
197
 
198
  # Use a custom endpoint compatible with OpenAI API:
199
+ "model_server": "http://localhost:8000/v1", # api_base
200
+ "api_key": "EMPTY",
201
 
202
  # Other parameters:
203
+ # "generate_cfg": {
204
+ # # Add: When the response content is `<think>this is the thought</think>this is the answer;
205
+ # # Do not add: When the response has been separated by reasoning_content and content.
206
+ # "thought_in_content": True,
207
+ # },
208
  }
209
 
210
  # Define Tools
211
  tools = [
212
+ {
213
+ "mcpServers": { # You can specify the MCP configuration file
214
+ "time": {
215
+ "command": "uvx",
216
+ "args": ["mcp-server-time", "--local-timezone=Asia/Shanghai"],
217
  },
218
  "fetch": {
219
  "command": "uvx",
220
+ "args": ["mcp-server-fetch"],
221
+ },
222
  }
223
  },
224
+ "code_interpreter", # Built-in tools
225
  ]
226
 
227
  # Define Agent
228
  bot = Assistant(llm=llm_cfg, function_list=tools)
229
 
230
  # Streaming generation
231
+ messages = [
232
+ {
233
+ "role": "user",
234
+ "content": "https://qwenlm.github.io/blog/ Introduce the latest developments of Qwen",
235
+ }
236
+ ]
237
+
238
  for responses in bot.run(messages=messages):
239
  pass
240
+
241
  print(responses)
242
  ```
243