Agentic search/RAG pipeline

Peng Xia

这个 blog 是复现 ZeroSearch 的副产物。拿来和 function call search 对比时搭的 pipeline。
Search-O1, Search-R1, ReSearch, DeepResearcher, ZeroSearch 之类都是采用整体上类似的 agentic search 结构, i.e., think, search, infomation 交叉生成,直到生成了 answer.

以下示意图出自 Search-O1。

image-20250805222714583

接下来先构建搜索引擎,Bing 和 Google 之类的个人申请好麻烦,国内提供 api 服务的有博查。

1
2
import os, json, time, requests, transformers, torch, re
from openai import OpenAI

搜索引擎函数定义

google

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import serpapi
def retrieve_from_google(query, topk, retry_attempt=3):
SER_API_KEY = os.environ.get("SER_API_KEY", None)
params = {
"engine": "google",
"q": query,
"api_key": SER_API_KEY,
"num": topk
}

for i in range(retry_attempt):
try:
search = serpapi.search(params)
search_result = search["organic_results"]

search_texts = []
for item in search_result:
text_data = ''
if 'title' in item:
text_data += item['title']
if 'snippet' in item:
text_data += item['snippet']
search_texts.append(text_data)

return '\n'.join([f"Doc {i + 1}: {doc}" for i, doc in enumerate(search_texts)])

except Exception as e:
print(f"Attempt {i + 1} failed: {e}")
if i < retry_attempt - 1:
time.sleep(2) # 等待2秒后重试
else:
print("All retries failed.")
return 'No information available'

bocha

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def retrieve_from_bocha(query, topk, retry_attempt=3):

url = "https://api.bochaai.com/v1/web-search"
headers = {
'Authorization': 'Bearer sk-128428ba28314b80a8283695ff1385a3',
'Content-Type': 'application/json'
}

for i in range(retry_attempt):
try:
payload = json.dumps({
"query": query,
"summary": True,
"count": topk
})

response = requests.request("POST", url, headers=headers, data=payload)
search_results = response.json()['data']['webPages']['value']
search_texts = [item['summary'] for item in search_results if 'summary' in item]
return '\n'.join([f"Doc {i + 1}: {doc}" for i, doc in enumerate(search_texts)])

except Exception as e:
print(f"Attempt {i + 1} failed: {e}")
if i < retry_attempt - 1:
time.sleep(2) # 等待2秒后重试
else:
print("All retries failed.")
return 'No information available'

# print(retrieve_from_bocha('2025金价', 5))
1
2
3
4
Doc 1: 正面观点:2025年金价会越来越高!不少机构及分析师预测2025年金价均价达到2800-2900美元区间,并可能突破3000美元关口。当然手里有黄金的朋友也不建议卖的太早了,未来金价有望达到700元/克。
Doc 2: 汇通网12月17日讯 —— MKS 预测2024年金价均价为每盎司2750美元,较今年当前的年均值上涨14%;2025年金价接近 2500 美元/盎司的可能性为30%,2025年金价突破每盎司 3000 美元的可能性只有20%;全球宽松措施应有助于刺激经济,提振2025年白银的工业需求,预计白银价格交易区间为每盎司 28 美元至 42 美元,均价为每盎司 36.50 美元,较当前年均价上涨 23%。 一位市场分析师表示,即将进入新的一年,黄金在 2025 年创下历史新高的道路似乎更加复杂。 MKS PAMP (瑞士金融公司)研究与金属策略主管 Nicky Shiels 在她的 2025 年贵金属展望中表示,她预计黄金交易价格将在每盎司 2500 美元至 3200 美元之间的相当宽的范围内,贵金属的命运很大程度上由美联储决定。与此同时,MKS 预测今年金价均价为每盎司 2750 美元,较今年当前的年均值上涨 14%。 “金价在 3000 美元以上或 2500 美元——取决于美联储是领先还是落后于特朗普通胀曲线;我们预计它们将落后,导致下半年实际利率下降和美元走软,”她表示,“从结构上看,长期高通胀、持续的去全球化、货币贬值、央行去美元化、混乱且不可预测的地缘政治、不可持续的全球债务路径以及持有不足的普通投资者群体的正反馈循环确保了黄金仍然是一种安全资产多元化者。” 尽管黄金在 2025 年拥有坚实的基本面支撑,但Shiels 指出,明年出现熊市的可能性高于牛市的可能性。 Shiels 在报告中表示,随着当选总统唐纳德·特朗普通过减税和放松管制等促增长政策推动美国例外论,明年金价接近 2500 美元/盎司的可能性为 30% 。 与此同时,美国优先的政策预计将推高消费者价格,迫使美联储放慢宽松周期,尽管它落后于通胀曲线。 Shiels还警告黄金投资者,新政府对其他货币的关注可能会
Doc 3: 根据伦敦金银市场协会对26位分析师的调查显示,黄金今年将在当前价格附近徘徊。 调查显示,2025年金价平均将达到每盎司2737美元。 最乐观的预测来自住友商事的Keisuke Okui,预计将达到2925美元。 最悲观的预测来自Robin Bhar Metals Consulting的Robin Bhar,预计将达到2500美元。 注:现货黄金周一的交易价格接近每盎司2760美元。 新浪合作大平台期货开户 安全快捷有保障 海量资讯、精准解读,尽在新浪财经APP
Doc 4: 各大投行对黄金 2025 年价格的预测及走势分析: 高盛 价格预测 :预计 2025 年初金价将达到每盎司 2900 美元,到2025 年底,金价将上涨 11%,至每盎司 3000 美元. 走势分析 :高盛认为推动金价走高的因素主要有三个。一是美联储的政策行动,预计美联储将在 2025 年大幅降息,借贷成本的下降会使黄金更具吸引力 。二是美元走强将推动各国央行主导的黄金购买热潮,外国机构对黄金的购买量将持续增加。三是黄金和美元在 2025 年有一个共同的上涨理由,当贸易关税或地缘政治冲击推动美元走强时,美元和金价往往会同时上涨,因二者均为避险资产. 摩根大通 价格预测 :预计 2025 年底金价将达到 3000 美元 / 盎司. 走势分析 :2025 年宏观不确定性加剧时,黄金将发挥重要对冲作用。宏观动荡时,央行和投资者增持黄金;宏观平稳时,美联储降息周期带动黄金 ETF 资金流入. 瑞银 价格预测 :预计 2025 年底金价将达到每盎司 2900 美元. 走势分析 :预计黄金在未来 6 到12 个月内仍有进一步上涨的空间,黄金是抵御经济不确定性的有吸引力的避险资产,特别是在特朗普政府的政策变化和美联储的利率路径不确定性增加的背景下,ETF 的大量资金流入是关键因素 美国银行 价格预测 :预计 2025 年下半年金价将达到 3000 美元,2025 年金价平均将在每盎司 2750 美元左右. 走势分析 :尽管 2025 年黄金面临如亚洲大国需求低迷、西方投资者面临潜在的债券收益率上升和美元走强等重大阻力,但受经济不确定性和地缘政治动荡刺激避险需求的推动,金银将获得坚实支撑. 荷兰国际集团 价格预测 :预计 2025 年第一季度和第二季度现货黄金均价为每盎司 2800 美元,全年均价为每盎司 2760 美元5. 走势

这是 zero search 的提示词,实际测试时还是有点问题,例如:

  • tag 部分不生成,例如非第一次think只会生成 </think> ,已修改
  • 没有搜索上限,复杂问题或者单纯没有搜索到内容的情况就会重复好久,我记得 search-o1 有搜索次数上限: “You can repeat the search process multiple times if necessary. The maximum number of search attempts is limited to {MAX_SEARCH_LIMIT}.\n\n”,我没有修改提示词,直接break。
  • 答案过于简洁,不大友善

整体推理流程是 loop,每个 loop 内:

  • 以 prompt 为输入 think,可能会直接回答或者生成 search
  • model.generate 检测到 </search> 中断
  • 检查是否是 eos 导致,是则退出 loop
  • 抽取新生成的内容 <search> 去搜索
  • 将本轮新生成的内容和搜索结果拼入 prompt 中
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# 搜索结果的模板,最后的 `<think>` 最好还是加下,可能会出现非第一次think只会生成 </think> 的情况
curr_search_template = '{output_text}\n<information>{search_results}</information>\n<think>'
# Prompt 模板
prompt_template = """Answer the given question. \
You must conduct reasoning inside <think> and </think> first every time you get new information. \
After reasoning, if you find you lack some knowledge, you can call a search engine by <search> query </search> and it will return the top searched results between <information> and </information>. \
You can search as many times as your want. \
If you find no further external knowledge needed, you can directly provide the answer inside <answer> and </answer>, without detailed illustrations. For example, <answer> Beijing </answer>. Question: {question}\n"""

# 这个用于控制在生成 </search> 时中断生成
class StopOnSequence(transformers.StoppingCriteria):
def __init__(self, target_sequences, tokenizer):
# Encode the string so we have the exact token-IDs pattern
self.target_ids = [tokenizer.encode(target_sequence, add_special_tokens=False) for target_sequence in
target_sequences]
self.target_lengths = [len(target_id) for target_id in self.target_ids]
self._tokenizer = tokenizer

def __call__(self, input_ids, scores, **kwargs):
# Make sure the target IDs are on the same device
targets = [torch.as_tensor(target_id, device=input_ids.device) for target_id in self.target_ids]

if input_ids.shape[1] < min(self.target_lengths):
return False

# Compare the tail of input_ids with our target_ids
for i, target in enumerate(targets):
if torch.equal(input_ids[0, -self.target_lengths[i]:], target):
return True

return False

# 提取 search query
def get_query(text):
pattern = re.compile(r"<search>(.*?)</search>", re.DOTALL)
matches = pattern.findall(text)
if matches:
return matches[-1].strip('\n').strip()
else:
return None


def run_agentic_search(model, tokenizer, question, search_engine_func=retrieve_from_bocha, search_engine_func_kwargs={'topk':5}):
device = model.device
question = question.strip()
if question[-1] != '?':
question += '?'

# Prepare the message
prompt = prompt_template.format(question=question)

# Initialize the stopping criteria
# real stopping criteria
curr_eos = [tokenizer.eos_token_id, tokenizer.pad_token_id]
# middle stopping criteria
target_sequences = ["</search>", " </search>", "</search>\n", " </search>\n", "</search>\n\n", " </search>\n\n"]
stopping_criteria = transformers.StoppingCriteriaList([StopOnSequence(target_sequences, tokenizer)])

cnt = 0
if tokenizer.chat_template:
prompt = tokenizer.apply_chat_template([{"role": "user", "content": prompt}], add_generation_prompt=True, tokenize=False)

# print('\n\n################# [Start Reasoning + Searching] ##################\n\n')
# print(prompt)
# Encode the chat-formatted prompt and move it to the correct device
while True:
input_ids = tokenizer.encode(prompt, return_tensors='pt').to(device)
attention_mask = torch.ones_like(input_ids)

# Generate text with the stopping criteria
outputs = model.generate(
input_ids,
attention_mask=attention_mask,
max_new_tokens=1024,
stopping_criteria=stopping_criteria,
pad_token_id=tokenizer.eos_token_id,
do_sample=True,
temperature=0.7
)

# real stop and exit loop
if outputs[0][-1].item() in curr_eos:
full_text = tokenizer.decode(outputs[0], skip_special_tokens=False)
return full_text
# generated_tokens = outputs[0][input_ids.shape[1]:]
# output_text = tokenizer.decode(generated_tokens, skip_special_tokens=True)
# print(output_text)
# break

# split generated tokens from current output_ids
generated_tokens = outputs[0][input_ids.shape[1]:]
output_text = tokenizer.decode(generated_tokens, skip_special_tokens=True)

# check for <search> invoking
tmp_query = get_query(tokenizer.decode(outputs[0], skip_special_tokens=True))
if tmp_query:
try:
search_results = search_engine_func(tmp_query, **search_engine_func_kwargs)
except Exception as e:
raise ValueError(f"Unknown using search engine: {search_engine_func.__name__}, error: {e}")
else:
search_results = 'No information available'

# reformat the input text - concat the generated text and search results with input text, and serve as the next input text
search_text = curr_search_template.format(output_text=output_text.strip('\n'), search_results=search_results)
prompt += search_text
cnt += 1

if cnt >=5:
break
# print(search_text)

return {'error': 'Reach max search rounds (5), force exit.'}

1
2
3
4
5
6
7
8
model_path = 'Alibaba-NLP/ZeroSearch_google_V2_Qwen2.5_7B_Instruct'
# Initialize the tokenizer and model
tokenizer = transformers.AutoTokenizer.from_pretrained(model_path)
model = transformers.AutoModelForCausalLM.from_pretrained(model_path, torch_dtype=torch.bfloat16).to('cuda:1')

question = "What is the capital of France?"
output_text = run_agentic_search(model, tokenizer, question, retrieve_from_bocha, {'topk': 5})
print(output_text)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
Answer the given question. You must conduct reasoning inside <think> and </think> first every time you get new information. After reasoning, if you find you lack some knowledge, you can call a search engine by <search> query </search> and it will return the top searched results between <information> and </information>. You can search as many times as your want. If you find no further external knowledge needed, you can directly provide the answer inside <answer> and </answer>, without detailed illustrations. For example, <answer> Beijing </answer>. Question: What is the capital of France?
<|im_end|>
<|im_start|>assistant
<think> The question is about the capital of France. I need to search for the capital of France. </think>
<search> capital of France </search>
<information>Doc 1: Study now See answers (2) Best Answer Copy The capital of France is Paris (Frankreich is the German namefor France) Wiki User ∙ 15 y ago This answer is:  Helpful ( 0 )  Not Helpful ( 0 ) Add a Comment More answers AnswerBot ∙ 8 mo ago Copy The capital of Frankreich is Paris. This answer is:  Helpful ( 0 )  Not Helpful ( 0 ) Add a Comment Add your answer: Earn + 20 pts Q: What is the capital of Frankreich? Write your answer... Submit Still have questions? Find more answers Ask your question Continue Learning about Linguistics Related questions What actors and actresses appeared in Gott in Frankreich - 2005? How do you say France in German? What is France called in gemany? How do you say France in Colognian?
Doc 2: 试卷征集 加入会员 操作视频 What is the capital of France? What is the capital of France? 【考点】 复合句 . 【答案】 What is the capital of France? 【解答】 【点评】 声明:本试题解析著作权属菁优网所有,未经书面同意,不得复制发布。 相似题 1. There are some lakes in the village. (改成一般疑问句) 组卷:3 引用:1 难度:0.0 2. These pants are short.( 同义句 ) These are 组卷:65 引用:4 难度:0.3 3. I am 10 years old this year . (用three years ago代替划线部分) 组卷:1 引用:1 难度:0.0 深圳市菁优智慧教育股份有限公司 ©2010-2025 jyeoo.com 版权所有 APP开发者:深圳市菁优智慧教育股份有限公司 | 应用名称:菁优网 | 应用版本:5.0.7 | 隐私协议 | 第三方SDK | 用户服务条款
Doc 3: Paris is the capital of my country
查看翻译
这个答案有帮助吗?
That's basic geography knowledge ^^'
@Nasdil ça me casse les couilles, ce genre de question
on est bien d'accord... déjà que c'est le niveau 0 de la culture générale, mais en plus, même en étant inculte, 2 secondes sur google suffisent !
@Nasdil oui, bien sûr !! Ça ne coûte rien.
Je ne comprends pas
surtout que le pays c'est pas french mais France Lol Mm le niveau anglais est pas au rdv
1. French is a language and languages can't have capitals.
2. Paris is famous, you should know that or at least look on google.
这个答案有帮助吗?
Où est la capitale de la France ?
这个答案有帮助吗?
the capital of france is Paris,do you like the eiffel tower?
Doc 4: 法国的首都是什么?
答:巴黎 Paris
解析看不懂?免费查看同类题视频解析
Doc 5: 关于 法国 的问题
what is the capital of France???
can you send me pics of paris
Sorry, I don't have pics of Paris
这个答案有帮助吗?
具体的国家或地区 印度
it's ok...
查看翻译
具体的国家或地区 法国
Here you go
这个答案有帮助吗?
thank you @haibaraaa , it's so beautiful
这个答案有帮助吗?
这个答案有帮助吗?
这个答案有帮助吗?
这个答案有帮助吗?
你知道如何提升自己的外语能力吗❓只需写下外语文章并让母语使用者更正!
使用HiNative,免费让母语使用者帮你订正文章✍️✨
注册新帐户</information>
<think> From the information provided, the capital of France is Paris. </think>
<answer> Paris </answer><|im_end|>

国内搜索引擎结果真是让人无语

text 拆分

以下函数是将 已经是 chat template 化的 str,重新组织为 messages。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
pattern_pairs_qwen = [
("system", r"(?s)^\s*<\|im_start\|>system\s*", r"\s*<\|im_end\|>"),
("user", r"(?s)^\s*<\|im_start\|>user\s*", r"\s*<\|im_end\|>"),
("assistant", r"(?s)^\s*<\|im_start\|>assistant\s*", r"\s*<\|im_end\|>"),
]

def reverse_chat_template(text, pattern_pairs=pattern_pairs_qwen):
msgs, idx = [], 0
while idx < len(text):
# 跳过段落间的空白字符
while idx < len(text) and text[idx].isspace():
idx += 1

for role, start_pat, end_pat in pattern_pairs:
m = re.match(start_pat, text[idx:])
if not m:
continue

start_pos = idx + m.end() # content 起点

if end_pat: # 找 <|im_end|>
end_m = re.search(end_pat, text[start_pos:])
if not end_m: # 理论上不会发生
content_end = end_pos = len(text)
else:
content_end = start_pos + end_m.start()
end_pos = start_pos + end_m.end() # 关键:跨过 END 标记
else: # 无显式 END(几乎不用)
end_pos = content_end = len(text)

msgs.append({"role": role,
"content": text[start_pos:content_end].rstrip()})
idx = end_pos # 继续下一段
break
else:
# 没一个 pattern 命中,避免死循环
break
return msgs

msgs = reverse_chat_template(output_text, pattern_pairs=pattern_pairs_qwen)
print(msgs)
print(msgs[-1]['content'])
1
2
3
4
5
6
[{'role': 'system',
'content': 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.'},
{'role': 'user',
'content': 'Answer the given question. You must conduct reasoning inside <think> and </think> first every time you get new information. After reasoning, if you find you lack some knowledge, you can call a search engine by <search> query </search> and it will return the top searched results between <information> and </information>. You can search as many times as your want. If you find no further external knowledge needed, you can directly provide the answer inside <answer> and </answer>, without detailed illustrations. For example, <answer> Beijing </answer>. Question: What is the capital of France?'},
{'role': 'assistant',
'content': "<think> The question is about the capital of France. I need to search for the capital of France. </think>\n<search> capital of France </search>\n<information>Doc 1: Study now See answers (2) Best Answer Copy The capital of France is Paris (Frankreich is the German namefor France) Wiki User ∙ 15 y ago This answer is: \uf44d Helpful ( 0 ) \uf44e Not Helpful ( 0 ) Add a Comment More answers AnswerBot ∙ 8 mo ago Copy The capital of Frankreich is Paris. This answer is: \uf44d Helpful ( 0 ) \uf44e Not Helpful ( 0 ) Add a Comment Add your answer: Earn + 20 pts Q: What is the capital of Frankreich? Write your answer... Submit Still have questions? Find more answers Ask your question Continue Learning about Linguistics Related questions What actors and actresses appeared in Gott in Frankreich - 2005? How do you say France in German? What is France called in gemany? How do you say France in Colognian?\nDoc 2: 试卷征集 加入会员 操作视频 What is the capital of France? What is the capital of France? 【考点】 复合句 . 【答案】 What is the capital of France? 【解答】 【点评】 声明:本试题解析著作权属菁优网所有,未经书面同意,不得复制发布。 相似题 1. There are some lakes in the village. (改成一般疑问句) 组卷:3 引用:1 难度:0.0 2. These pants are short.( 同义句 ) These are 组卷:65 引用:4 难度:0.3 3. I am 10 years old this year . (用three years ago代替划线部分) 组卷:1 引用:1 难度:0.0 深圳市菁优智慧教育股份有限公司 ©2010-2025 jyeoo.com 版权所有 APP开发者:深圳市菁优智慧教育股份有限公司 | 应用名称:菁优网 | 应用版本:5.0.7 | 隐私协议 | 第三方SDK | 用户服务条款\nDoc 3: Paris is the capital of my country\n查看翻译 \n这个答案有帮助吗?\nThat's basic geography knowledge ^^'\n@Nasdil ça me casse les couilles, ce genre de question\n on est bien d'accord... déjà que c'est le niveau 0 de la culture générale, mais en plus, même en étant inculte, 2 secondes sur google suffisent !\n@Nasdil oui, bien sûr !! Ça ne coûte rien. \nJe ne comprends pas\nsurtout que le pays c'est pas french mais France Lol Mm le niveau anglais est pas au rdv\n1. French is a language and languages can't have capitals.\n2. Paris is famous, you should know that or at least look on google.\n这个答案有帮助吗?\nOù est la capitale de la France ?\n这个答案有帮助吗?\nthe capital of france is Paris,do you like the eiffel tower?\nDoc 4: 法国的首都是什么?\n答:巴黎 Paris\n解析看不懂?免费查看同类题视频解析\nDoc 5: 关于 法国 的问题\nwhat is the capital of France???\ncan you send me pics of paris\nSorry, I don't have pics of Paris\n这个答案有帮助吗?\n 具体的国家或地区 印度 \nit's ok... \n查看翻译 \n 具体的国家或地区 法国 \nHere you go\n这个答案有帮助吗?\nthank you @haibaraaa , it's so beautiful \n这个答案有帮助吗?\n这个答案有帮助吗?\n这个答案有帮助吗?\n这个答案有帮助吗?\n你知道如何提升自己的外语能力吗❓只需写下外语文章并让母语使用者更正!\n使用HiNative,免费让母语使用者帮你订正文章✍️✨\n 注册新帐户</information>\n<think> From the information provided, the capital of France is Paris. </think>\n<answer> Paris </answer>"}]

以上是完整的 messages,以下是仅模型生成部分。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<think> The question is about the capital of France. I need to search for the capital of France. </think>
<search> capital of France </search>
<information>Doc 1: Study now See answers (2) Best Answer Copy The capital of France is Paris (Frankreich is the German namefor France) Wiki User ∙ 15 y ago This answer is:  Helpful ( 0 )  Not Helpful ( 0 ) Add a Comment More answers AnswerBot ∙ 8 mo ago Copy The capital of Frankreich is Paris. This answer is:  Helpful ( 0 )  Not Helpful ( 0 ) Add a Comment Add your answer: Earn + 20 pts Q: What is the capital of Frankreich? Write your answer... Submit Still have questions? Find more answers Ask your question Continue Learning about Linguistics Related questions What actors and actresses appeared in Gott in Frankreich - 2005? How do you say France in German? What is France called in gemany? How do you say France in Colognian?
Doc 2: 试卷征集 加入会员 操作视频 What is the capital of France? What is the capital of France? 【考点】 复合句 . 【答案】 What is the capital of France? 【解答】 【点评】 声明:本试题解析著作权属菁优网所有,未经书面同意,不得复制发布。 相似题 1. There are some lakes in the village. (改成一般疑问句) 组卷:3 引用:1 难度:0.0 2. These pants are short.( 同义句 ) These are 组卷:65 引用:4 难度:0.3 3. I am 10 years old this year . (用three years ago代替划线部分) 组卷:1 引用:1 难度:0.0 深圳市菁优智慧教育股份有限公司 ©2010-2025 jyeoo.com 版权所有 APP开发者:深圳市菁优智慧教育股份有限公司 | 应用名称:菁优网 | 应用版本:5.0.7 | 隐私协议 | 第三方SDK | 用户服务条款
Doc 3: Paris is the capital of my country
查看翻译
这个答案有帮助吗?
That's basic geography knowledge ^^'
@Nasdil ça me casse les couilles, ce genre de question
on est bien d'accord... déjà que c'est le niveau 0 de la culture générale, mais en plus, même en étant inculte, 2 secondes sur google suffisent !
@Nasdil oui, bien sûr !! Ça ne coûte rien.
Je ne comprends pas
surtout que le pays c'est pas french mais France Lol Mm le niveau anglais est pas au rdv
1. French is a language and languages can't have capitals.
2. Paris is famous, you should know that or at least look on google.
这个答案有帮助吗?
Où est la capitale de la France ?
这个答案有帮助吗?
the capital of france is Paris,do you like the eiffel tower?
Doc 4: 法国的首都是什么?
答:巴黎 Paris
解析看不懂?免费查看同类题视频解析
Doc 5: 关于 法国 的问题
what is the capital of France???
can you send me pics of paris
Sorry, I don't have pics of Paris
这个答案有帮助吗?
具体的国家或地区 印度
it's ok...
查看翻译
具体的国家或地区 法国
Here you go
这个答案有帮助吗?
thank you @haibaraaa , it's so beautiful
这个答案有帮助吗?
这个答案有帮助吗?
这个答案有帮助吗?
这个答案有帮助吗?
你知道如何提升自己的外语能力吗❓只需写下外语文章并让母语使用者更正!
使用HiNative,免费让母语使用者帮你订正文章✍️✨
注册新帐户</information>
<think> From the information provided, the capital of France is Paris. </think>
<answer> Paris </answer>
1
2
3
4
5
6
7
8
9
10
11
# 提取 answer
def get_answer(text):
pattern = re.compile(r"<answer>(.*?)</answer>", re.DOTALL)
matches = pattern.findall(text)
if matches:
return matches[-1].strip('\n').strip()
else:
return None

final_answer = get_answer(output_text)
print(final_answer)

Paris

Comments
On this page
Agentic search/RAG pipeline