Skip to content

Commit 343f2d5

Browse files
authored
qwen_instruct and search_env recipe fixes (#101)
1 parent 320e1c0 commit 343f2d5

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

tinker_cookbook/recipes/tool_use/search/search_env.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
SEARCH_TOOL_SYSTEM_PROMPT = """
3434
You are an expert assistant who solves tasks using a Wikipedia search tool.
35-
Tool calling. Execute the tool by wrapping calls in <function_call>...</function_call>
35+
Tool calling. Execute the tool by wrapping calls in <tool_call>...</tool_call>
3636
3737
The search tool you are given has the following schema:
3838
```
@@ -69,9 +69,9 @@
6969
“Between 2020 and 2025, which year did New York City see the most population growth and how did San Francisco population change in that year?”
7070
7171
1. Think step by step: In order to answer this question, I need to know the population of New York City and San Francisco between 2020 and 2025. I will search for the population of New York City in each year
72-
2. Calling search tool: <function_call>{"name": "search", "args": {"query_list": ["Population New York city between 2020 and 2025"]}}</function_call> (Output omitted for brevity)
72+
2. Calling search tool: <tool_call>{"name": "search", "args": {"query_list": ["Population New York city between 2020 and 2025"]}}</tool_call> (Output omitted for brevity)
7373
3. Think step by step again: I have the population of New York City in each year, and I see that the population of New York City grew the most in 2024. I need to know the population of San Francisco in 2024. I will search for the population of San Francisco in each year.
74-
<function_call>{"name": "search", "args": {"query_list": ["Population San Francisco between 2023 and 2024"]}}</function_call> (Output omitted for brevity)
74+
<tool_call>{"name": "search", "args": {"query_list": ["Population San Francisco between 2023 and 2024"]}}</tool_call> (Output omitted for brevity)
7575
4. Answer: The population of New York City grew the most in 2024, and the population of San Francisco changed by XXXX in 2024.
7676
"""
7777

tinker_cookbook/renderers.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,13 +481,20 @@ def _render_message(self, idx: int, message: Message) -> tuple[list[int], list[i
481481
ob_str = f"{maybe_newline}<|im_start|>{message['role']}\n"
482482
ac_content = message["content"]
483483
# Observation (prompt) part
484-
ac_str = f"{ac_content}<|im_end|>"
484+
if "tool_calls" in message:
485+
ac_content += "\n".join(
486+
[
487+
f"<tool_call>\n{json.dumps(tool_call)}\n</tool_call>"
488+
for tool_call in message["tool_calls"]
489+
]
490+
)
491+
ac_content += "<|im_end|>"
485492
# Action part
486493
ac_tail_str = "" # No action tail needed for Qwen format
487494
# Action part that's only included in the last message in SFT
488495
return (
489496
self.tokenizer.encode(ob_str, add_special_tokens=False),
490-
self.tokenizer.encode(ac_str, add_special_tokens=False),
497+
self.tokenizer.encode(ac_content, add_special_tokens=False),
491498
self.tokenizer.encode(ac_tail_str, add_special_tokens=False),
492499
)
493500

0 commit comments

Comments
 (0)