可以看到,前一轮的输出会成为后一轮的输入,从而让 AI 可在每个阶段不断完善其思维。最后,所有这些思考会凝练成一个合理的最终答案。就像看着一枚莓果逐渐成熟!
如何实现
下面将深入 Llamaberry 的实现细节。
设置舞台
首先,我们需要为 AI 助手设置一些基本规则,代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13
initial_system_prompt = """You are an AI assistant capable of detailed, step-by-step thinking. When presented with a question or problem, break down your thought process into clear, logical steps. For each step, explain your reasoning. Conclude with a final answer. Use the following markdown structure:
## Reasoning 1. [First step] **Explanation:** [Detailed explanation of this step] 2. [Second step] **Explanation:** [Detailed explanation of this step] ...
## Answer [Final answer]
Be comprehensive and show your reasoning clearly."""
这就是提供给 AI 大厨的菜谱。它知道需要逐步分解其思考过程并解释每个步骤,并且以 Markdown 格式将它们显示出来。
思考过程
在每一轮推理中,都需要让 AI 对问题进行思考。但在第一轮结束后,还需要求它思考之前已经思考过的东西。这就像问朋友,「嘿,还记得你之前说过什么吗?让我们再想一想。」
async def generate_turn(query: str, previous_turns: list = None) -> str: is_first_turn = previous_turns is None or len(previous_turns) == 0 if is_first_turn: messages = [{ "role": "system", "content": initial_system_prompt }, { "role": "user", "content": query }] else: previous_content = "\n\n".join(previous_turns) messages = [{ "role": "system", "content": followup_system_prompt }, { "role": "user", "content": f"Original Query: {query}\n\nPrevious Turns:\n{previous_content}\n\nProvide the next turn of reasoning." }]
return await call_llm(messages)
该函数是多轮推理的核心。它决定我们是在第一轮还是在后续轮,并以此构建提示词。对于后续轮,它会将之前所有推理轮都包含在上下文中,让 AI 可以基于之前的思考进行构建。
综合结果
经过三轮思考之后,再让 AI 检视其所有思考并得出一个合理的最终答案。这就像是让专家讨论问题,然后编写最终报告。
1 2 3 4 5 6 7 8 9 10 11 12 13
async def synthesize_turns(query: str, turns: list) -> str: turns_text = "\n\n".join( [f"Turn {i+1}:\n{turn}" for i, turn in enumerate(turns)]) messages = [{ "role": "system", "content": synthesis_prompt }, { "role": "user", "content": f"Original Query: {query}\n\nTurns of Reasoning:\n{turns_text}" }] return await call_llm(messages)
这个综合步骤至关重要,是 AI 综合所有思考内容凝练出最终答案的一步。
单轮推理 vs 多轮推理
Martin Bowling 在其博客中简单比较了单轮和多轮推理。
这里他采用了一个简单示例,即询问 AI:「人工智能对就业市场有什么潜在影响?」
单轮推理:
1 2 3 4 5 6 7
AI: Artificial intelligence will likely have significant impacts on the job market, including: 1. Automation of routine tasks 2. Creation of new job roles in AI development and maintenance 3. Potential job displacement in certain industries 4. Increased demand for skills in data analysis and machine learning
While AI may eliminate some jobs, it will also create new opportunities and increase productivity in many fields.
使用 Llamaberry 执行多轮推理:
第 1 轮:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
AI: Let's approach this step-by-step:
1. Identify current AI capabilities Explanation: AI can perform data analysis, pattern recognition, and automate routine tasks.
2. Analyze vulnerable job sectors Explanation: Manufacturing, customer service, and data entry are likely to be affected.
3. Consider new job opportunities Explanation: AI development, data science, and AI ethics consultation may see growth.
4. Examine potential economic effects Explanation: Increased productivity might lead to economic growth, but wealth distribution could be a challenge.
Initial Answer: AI will likely cause significant shifts in the job market, with both job losses in some sectors and new opportunities in others.
第 2 轮:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
AI: Let's refine our thinking:
1. Reassess the timeline of AI impact Explanation: The effects won't be immediate but will unfold over years or decades.
2. Consider the adaptability of the workforce Explanation: Retraining and education will be crucial for workers to transition to new roles.
3. Analyze potential societal changes Explanation: The nature of work itself might change, with more emphasis on creativity and emotional intelligence.
4. Examine global differences Explanation: AI's impact will vary across different countries and economies.
...
Refined Answer: AI's impact on the job market will be complex and gradual, requiring proactive measures in education and economic policy to ensure a smooth transition.
第 3 轮:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
AI: Let's delve deeper:
1. Explore the concept of human-AI collaboration Explanation: Many jobs may evolve to involve working alongside AI rather than being replaced by it.
2. Consider the ethical implications Explanation: Issues like algorithmic bias in hiring processes need to be addressed.
3. Analyze the potential for new economic models Explanation: Universal Basic Income or reduced working hours might become more prominent discussions.
...
Further Refined Answer: While AI will undoubtedly transform the job market, its impact will likely be nuanced, involving collaboration between humans and AI, ethical considerations, and potentially new economic paradigms.
You are an expert AI assistant that explains your reasoning step by step. For each step, provide a title that describes what you're doing in that step, along with the content. Decide if you need another step or if you're ready to give the final answer. Respond in JSON format with 'title', 'content', and 'next_action' (either 'continue' or 'final_answer') keys. USE AS MANY REASONING STEPS AS POSSIBLE. AT LEAST 3. BE AWARE OF YOUR LIMITATIONS AS AN LLM AND WHAT YOU CAN AND CANNOT DO. IN YOUR REASONING, INCLUDE EXPLORATION OF ALTERNATIVE ANSWERS. CONSIDER YOU MAY BE WRONG, AND IF YOU ARE WRONG IN YOUR REASONING, WHERE IT WOULD BE. FULLY TEST ALL OTHER POSSIBILITIES. YOU CAN BE WRONG. WHEN YOU SAY YOU ARE RE-EXAMINING, ACTUALLY RE-EXAMINE, AND USE ANOTHER APPROACH TO DO SO. DO NOT JUST SAY YOU ARE RE-EXAMINING. USE AT LEAST 3 METHODS TO DERIVE THE ANSWER. USE BEST PRACTICES.
Example of a valid JSON response: json { "title": "Identifying Key Information", "content": "To begin solving this problem, we need to carefully examine the given information and identify the crucial elements that will guide our solution process. This involves...", "next_action": "continue" }
对这些提示词的详细解释请参阅原项目的 Prompt Breakdown 一节。这里就不赘述了,仅给出几个示例,比如可以在提示词中加入「include exploration of alternative answers」(探索其它答案)和「use at least 3 methods to derive the answer」(使用至少三种方法来得出答案)。
Brian Boso,博士,曾担任Smiths Detection的首席技术官和首席科学家,在那里领导国际技术团队负责开发威胁检测和安全筛查产品的所有研发工作。Brian于2003年8月加入Smiths Detection,此前曾在Scientific-Atlanta, Inc.担任研发副总裁,负责电缆电视分销设备的开发工作。在SA之前,Brian在Tektronix, Inc.担任技术副总裁,负责电子和光学测试与测量产品的开发。在他的职业生涯中,Brian担任C级管理、技术/研发管理、基础/应用研究、产品/流程开发、市场/销售管理和制造的职位。Brian毕业于俄亥俄州立大学获得学士学位,之后在伊利诺伊大学取得物理学硕士和博士学位。在加入工业界之前,他在宾夕法尼亚州立大学进行博士后研究。他的工作荣获了多项专利,并发表了多篇科学和技术论文。
Christopher D Brown,博士,是一位经验丰富的技术高管,在成功领导医学、生命科学、法医学和消费类市场领域突破性化学/生化传感技术开发方面有二十多年经验。在他的领导下,团队在分析平台的微型化和微加工,以及在化学分析中应用机器学习方法方面取得了许多行业首创。Brown博士获得了多个行业和技术奖项,在分析传感、仪器和统计/机器学习领域发表了200多项专利、论文和会议发言。他继续担任技术行业内多个委员会和咨询小组的成员。目前,他是908 Devices的联合创始人兼首席产品官。在创立908 Devices之前,他曾在加利福尼亚的苹果公司担任健康传感平台架构师,并在其他几家领先行业公司担任领导职务。
Joel Mainland,博士,是嗅觉神经科学家,是蒙奈尔化学感官中心的成员。他运用来自分子生物学、遗传学、神经科学和机器学习的方法来研究人类如何感知气味。他开发了用于在基于细胞的测定中筛选嗅觉受体以识别配体的方法,利用人类遗传变异来研究嗅觉受体在气味感知中的作用,并开发了从分子结构预测气味感知的模型。
John Patrick Cunningham,博士,是一名机器学习研究员,在科学和工业领域应用人工智能工具,特别是利用人工智能工具来理解生物智能和其他复杂过程。他是哥伦比亚大学统计学教授,是扎克曼心智大脑行为研究所和理论神经科学中心的研究员。他毕业于达特茅斯学院获得学士学位,于斯坦福大学获得硕士和博士学位,之后在剑桥进行了研究。他曾与和为多家主要公司提供建议。
Pat Walters,博士,是Cambridge, MA的Relay Therapeutics首席数据官。加入Relay之前,在Vertex Pharmaceuticals工作了20多年,担任全球建模与信息化负责人。他是美国化学学会颁发的2023年化学信息科学赫尔曼‧斯科尔尼克奖获得者。他是《化学信息与模型杂志》和《生命科学中的人工智能》的编辑咨询委员会成员,并曾在《医药化学杂志》担任类似角色。他是2019年由O’Reilly和Associates出版的书籍《生命科学的深度学习》的合著者。他在亚利桑那大学获得有机化学博士学位,研究人工智能在构象分析中的应用。在获得博士学位之前,Pat曾在Varian Instruments担任化学家和软件开发人员。他从加利福尼亚大学圣芭芭拉分校获得化学学士学位。
Ryan Adams,博士,是普林斯顿大学计算机科学教授,计算机科学系副主任。他的研究涉及机器学习、人工智能和计算统计学,在科学和工程领域有应用。Ryan在剑桥大学在David MacKay指导下完成了物理学博士学位,他是盖茨剑桥学者和圣约翰学院成员。在博士学位后,他在多伦多大学加拿大高级研究所的一部分作为初级研究员从事了两年研究。在2011年至2016年期间,他在哈佛大学工程与应用科学学院担任助理教授。 2015年,Ryan将他共同创立的公司Whetlab出售给了Twitter,在Twitter和Google工作了三年后于2018年加入普林斯顿大学任职。Ryan是普林斯顿创新加速计划的联合主任,也是应用和计算数学课程的相关教师以及统计学与机器学习中心的附属教师。
Da Chuang自2018年共同创立Expedera以来一直担任CEO。在他的领导和出色技术才能下,Chuang创建了一个蓬勃发展的公司,成为AI推理IP领域的领导者。他将公司规模从3人增长到跨越六个国家的70多名员工。Expedera的知识产权产品已成功部署在超过1000万个消费设备上,客户授权商涵盖各个行业市场。在他担任执行主席的新角色中,Chuang负责长期战略规划和关键企业举措。在加入Expedera之前,Chuang曾是Memoir Systems的联合创始人兼首席运营官(被思科收购),并曾在Cisco、Nvidia和Abrizio担任高级管理和工程职位。他持有加州大学伯克利分校的EECS学士学位和斯坦福大学的电气工程硕士/博士学位。
Da Chuang表示:“我为我们所建立的成就感到非常骄傲,担任Expedera的CEO是我职业生涯的亮点。”“我期待着与Siyad和我们的董事会合作,在我的执行主席角色中继续公司的增长和创新。”
Can big corporations innovate like fast-moving startups? Aucctus (www.{ width=60% }
aucctus.com), a Toronto-based AI startup, believes it’s possible. Armed with a $1.5 million seed investment led by Four Cornerstones Capital, Aucctus has built an AI-powered platform that turns every employee into a potential innovator– equipped to bring the next big idea to their company. Large companies spend billions annually on innovation, relying on external consultants and internal teams. Traditionally, generating ideas, validating their potential, and launching them takes months or even years. Aucctus reduces the time and money it takes to do this using Generative AI– leveraging years’ of experience and proprietary methodologies to deploy autonomous agents. “We were frustrated that no one was harnessing generative AI to revolutionize corporate innovation,” said Tyler Anderson, CEO of Aucctus. “Our platform empowers every employee to become an innovator.” In minutes, Aucctus identifies new ideas, vets them against market trends and corporate strategy, proposes financial models, identifies target customers, and validates assumptions. These workflows help teams launch initiatives faster in a stage-gated process, bridging the gap between “new ideas” and “profitable innovations”. Founded in early 2024, Aucctus has spent eight months building with eight of the world’s largest companies. Now, it’s rolling out to thousands of employees across Canada, the U.S, Europe, and the Middle East, disrupting the billion-dollar innovation SaaS industry. “It’s humbling to see our product resonate with leaders at some of the world’s biggest brands,” added Vincent Atallah, President of Aucctus. “With this investment, we can accelerate our product development and become a must-have tool for companies committed to staying relevant.” Aucctus will use the seed funding to expand its team of AI and machine learning engineers, further developing its proprietary technologies and enhancing the platform’s capabilities. “My entire business career has been guided by the motto ‘Change or Die,’” says Rick Ekstein, President and CEO of Four Cornerstones Capital. “The power of the Aucctus platform won’t just help businesses keep up—it will push them ahead of the curve and ensure they stay there.”
Brian Boso,博士,曾任Smiths Detection的首席技术官和首席科学家,领导国际技术团队负责所有关于威胁检测和安全筛查产品的研发。Brian于2003年8月加入Smiths Detection,此前曾担任Scientific-Atlanta, Inc.的研发副总裁,主导有线电视分发设备的研发工作。在加入SA之前,Brian曾担任Tektronix, Inc.技术副总裁,主导电子和光学测试和测量产品的研发。在他的职业生涯中,Brian曾担任C级管理、技术/研发管理、基础/应用研究、产品/流程开发、营销/销售管理和制造领域的职务。Brian持有俄亥俄州立大学学士学位,并在伊利诺伊大学获得物理学硕士和博士学位。他还在宾夕法尼亚州立大学进行博士后研究,然后进入工业界任职。他的多项工作取得了专利,并有多篇科学和技术出版物。
Christopher D Brown,博士,是一位拥有20多年经验的技术高管,成功领导开发医疗、生命科学、法医学和消费品市场上突破性化学/生化传感技术的团队。在他的领导下,团队在分析平台的微型化和微加工以及在化学分析中应用机器学习方法方面取得了行业的多个第一。Brown博士获得了多项行业和技术奖项,在分析传感、仪器和统计/机器学习领域上有200多项专利、论文和会议发表记录。他继续在技术行业的几个委员会和咨询小组中任职。目前,他是908 Devices的联合创始人兼首席产品官。在创立908 Devices之前,他在加利福尼亚洲的苹果公司担任健康传感平台架构师,并在若干其他行业领先公司担任领导职务。
Joel Mainland,博士,是一位嗅觉神经科学家,是莫奈尔化学感知中心的成员。他使用了分子生物学、遗传学、神经科学和机器学习方法来研究人类如何感知气味。他发展了用于在细胞基础的分析中筛选嗅觉受体以识别配体的方法,利用人类遗传变异来研究嗅觉受体在气味感知中的作用,并开发了能从分子结构预测气味感知的模型。
John Patrick Cunningham,博士,是一名机器学习研究员,致力于将人工智能工具应用于科学和工业,特别是使用人工智能工具理解生物智能和其他复杂过程。他是哥伦比亚大学统计学教授,是Zuckerman Mind Brain Behavior研究所和理论神经科学中心的调查员。他本科毕业于达特茅斯学院,硕士和博士毕业于斯坦福大学,并在剑桥进行了研究员工作。他与一些领先公司合作并提供建议。
Pat Walters,博士,是位于马萨诸塞州剑桥市的Relay Therapeutics的首席数据官。加入Relay之前,他在Vertex Pharmaceuticals工作了20余年,担任了模型和信息管理的全球主管。Pat是美国化学学会颁发的荣誉Herman Skolnik化学信息科学奖2023年的获奖者。他是《化学信息与建模期刊》和《生命科学中的人工智能》的编辑顾问委员会成员,此前也担任过《药物化学期刊》的类似职务。他是《生命科学的深度学习》一书的合著者,该书于2019年由O’Reilly and Associates出版。他在亚利桑那大学获得了有机化学博士学位,研究了在构象分析中应用人工智能的方法。在获得博士学位之前,Pat在Varian Instruments公司担任化学家和软件开发人员。他在加利福尼亚大学圣巴巴拉分校获得了化学学士学位。
Ryan Adams,博士,是普林斯顿大学计算机科学教授,计算机科学系副主任。他的研究涉及机器学习、人工智能和计算统计,在科学和工程领域有着广泛的应用。Ryan在剑桥大学David MacKay师从物理学博士,是加兹·剑桥学者和圣约翰学院的成员。在获得博士学位后,Ryan在多伦多大学作为加拿大高级研究员工作了两年,作为加拿大高级研究所的一部分。在2011年至2016年期间,他在哈佛大学工程与应用科学学院担任助理教授。2015年,Ryan将他共同创立的公司Whetlab出售给Twitter,之后在Twitter和谷歌工作了三年,随后在2018年加入普林斯顿大学任教。Ryan是普林斯顿加快发明计划的联合主任,并是应用计算数学项目和统计与机器学习中心的相关教员。