简介
在这里,我们将把 LlamaIndex 驱动的工具集成到 CrewAI 驱动的多代理框架中,从而创建一个复杂的金融研究助理代理。
在一个团队中,代理可以看作是被赋予特定专长和职责的团队成员。这些代理承担着不同的角色,如 "研究员"、"作家 "或 "客户支持",每个角色都在实现团队集体目标的过程中发挥着重要作用。
所需技术组件
CrewAI :
CrewAI 是一个创新的开源框架,允许用户利用智能代理的协作能力。与传统的聊天机器人不同,这些代理拥有协作、交换信息的能力,并能作为一个有凝聚力的团队处理复杂的任务。
设想一下一群专家和谐合作的场景。每个成员都拥有独特的专长和知识,但他们的沟通能力和责任分配能力使他们取得了超越个人能力的成就。CrewAI 将这一协作原则应用于人工智能领域。在这一框架内,各个具有独特优势和局限性的代理在 CrewAI 的协调下进行互动,最终实现共同目标。
LlamaIndex:
LlamaIndex 是一个用户友好型框架,它使开发人员能够利用自己的数据毫不费力地构建由 LLM 驱动的应用程序。这个全面的框架包括用于高效索引、检索、提示创建和代理协调的基本模块。LlamaIndex 的一个主要应用是开发一个多功能 QA 界面,该界面能够综合知识并为复杂的查询提供全面的答案。
GROQ:
Groq 是一个尖端平台,包括硬件和软件组件,以其出色的计算速度、卓越的质量和显著的能效而著称。与之配套的是 LPU™ 推断引擎。
LPU Inference Engine 也称为 Language Processing Unit™(语言处理单元),是一个最先进的平台,由硬件和软件组件组成,旨在提供无与伦比的计算速度、卓越的质量和出色的能效。这一革命性的端到端处理单元系统在为计算密集型应用提供快速推理方面表现出色,特别是对于人工智能语言应用等顺序组件,包括令人印象深刻的大型语言模型(LLM)。
金融研究分析员代理的实施
相关步骤:
代码实现:
使用高 RAM CPU 在 google colab 中实现。
安装所需的依赖项
!pip install llama-index
!pip install llama-index-llms-groq
!pip install llama-index-core
!pip install llama-index-readers-file
!pip install llama-index-tools-wolfram-alpha
!pip install llama-index-embeddings-huggingface
!pip install 'crewai[tools]'
设置 LLM
from google.colab import userdata
from llama_index.llms.groq import Groq
groq_api_key = userdata.get('GROQ_API_KEY')
#
llm = Groq(model="llama3-70b-8192", api_key=groq_api_key)
#
response = llm.complete("Explain the importance of low latency LLMs")
print(response)
######################################Response############################
Low-latency Large Language Models (LLMs) are crucial in various applications where real-time or near-real-time processing is essential. Here are some reasons why low-latency LLMs are important:
1. **Interactive Systems**: In interactive systems like chatbots, virtual assistants, and conversational AI, low-latency LLMs enable rapid response times, making the interaction feel more natural and human-like. This is particularly important in applications where users expect immediate responses, such as customer support or language translation.
2. **Real-time Decision Making**: In applications like autonomous vehicles, robotics, or medical diagnosis, low-latency LLMs can process and analyze vast amounts of data in real-time, enabling swift decision-making and reaction to changing circumstances.
3. **Live Streaming and Broadcasting**: Low-latency LLMs can facilitate real-time language translation, sentiment analysis, or content moderation in live streaming and broadcasting applications, enhancing the viewer experience and ensuring timely content delivery.
4. **Gaming and Esports**: In online gaming and esports, low-latency LLMs can improve the gaming experience by enabling faster language processing, sentiment analysis, and chat moderation, reducing lag and enhancing overall performance.
5. **Healthcare and Emergency Services**: In healthcare and emergency services, low-latency LLMs can quickly process medical records, diagnose conditions, and provide critical information to healthcare professionals, saving lives and improving patient outcomes.
6. **Financial Trading and Analytics**: Low-latency LLMs can rapidly analyze large datasets, enabling high-frequency trading, sentiment analysis, and risk assessment in financial markets, helping traders and analysts make informed decisions.
7. **Cybersecurity**: In cybersecurity, low-latency LLMs can quickly detect and respond to threats, such as malware, phishing attacks, or DDoS attacks, reducing the attack surface and minimizing damage.
8. **Edge Computing and IoT**: As IoT devices proliferate, low-latency LLMs can process data closer to the source, reducing latency and improving real-time decision-making in applications like smart homes, cities, or industrial automation.
9. **Accessibility and Inclusion**: Low-latency LLMs can enable real-time language translation, captioning, and transcription, improving accessibility and inclusion for people with disabilities, language barriers, or hearing impairments.
10. **Competitive Advantage**: In many industries, low-latency LLMs can provide a competitive advantage by enabling faster decision-making, improved customer experiences, and increased operational efficiency, ultimately driving business success.
To achieve low latency in LLMs, researchers and developers are exploring various techniques, including:
1. Model pruning and knowledge distillation
2. Quantization and precision reduction
3. Parallel processing and distributed computing
4. Edge computing and decentralized architectures
5. Optimized hardware and software designs
6. Caching and memoization
7. Lazy loading and just-in-time compilation
By reducing latency in LLMs, we can unlock new possibilities in various applications, leading to improved user experiences, increased efficiency, and enhanced decision-making capabilities.
## Crewai requires a chat based model for binding
from langchain_openai import ChatOpenAI
chat_llm = ChatOpenAI(
openai_api_base="https://api.groq.com/openai/v1",
openai_api_key=groq_api_key,
model="llama3-70b-8192",
temperature=0,
max_tokens=1000,
)
下载数据
!wget "https://s23.q4cdn.com/407969754/files/doc_financials/2019/ar/Uber-Technologies-Inc-2019-Annual-Report.pdf" -O uber_10k.pdf
解析数据内容
from llama_index.core import SimpleDirectoryReader, VectorStoreIndex
from llama_index.llms.openai import OpenAI
import os
from langchain_openai import ChatOpenAI
#
reader = SimpleDirectoryReader(input_files=["uber_10k.pdf"])
docs = reader.load_data()
docs[1]
##############################################################
Document(id_='dd161725-2512-4b03-a689-accc69dc46d4', embedding=None, metadata={'page_label': '2', 'file_name': 'uber_10k.pdf', 'file_path': 'uber_10k.pdf', 'file_type': 'application/pdf', 'file_size': 2829436, 'creation_date': '2024-06-30', 'last_modified_date': '2020-03-31'}, excluded_embed_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], excluded_llm_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], relationships={}, text='69 \nCountries\n10K+ \nCities\n$65B \nGross Bookings\n111M \nMAPCs\n7B \nTripsA global tech \nplatform at \nmassive scale\nServing multiple multi-trillion \ndollar markets with products \nleveraging our core technology \nand infrastructure\nWe believe deeply in our bold mission. Every minute \nof every day, consumers and Drivers on our platform \ncan tap a button and get a ride or tap a button and \nget work. We revolutionized personal mobility with \nridesharing, and we are leveraging our platform to \nredefine the massive meal delivery and logistics \nindustries. The foundation of our platform is our \nmassive network, leading technology, operational \nexcellence, and product expertise. Together, these \nelements power movement from point A to point B.', mimetype='text/plain', start_char_idx=None, end_char_idx=None, text_template='{metadata_str}\n\n{content}', metadata_template='{key}: {value}', metadata_seperator='\n')
设置嵌入模型
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
# loads BAAI/bge-small-en-v1.5
embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5")
建立索引
index = VectorStoreIndex.from_documents(docs,
embed_model=embed_model,
)
构建查询引擎
query_engine = index.as_query_engine(similarity_top_k=5, llm=llm)
将查询引擎作为工具实例化
CrewAI 与 LlamaIndex 用于 RAG(检索增强生成)和代理管道的综合工具包无缝集成,可实现基于搜索的高级查询等功能。以下是 LlamaIndex 提供的可用内置工具。
CrewAI 中的工具是一种技能或功能,代理可以利用它来执行各种操作。
from crewai_tools import LlamaIndexTool
query_tool = LlamaIndexTool.from_query_engine(
query_engine,
name="Uber 2019 10K Query Tool",
description="Use this tool to lookup the 2019 Uber 10K Annual Report",
)
#
query_tool.args_schema.schema()
########################################
{'title': 'QueryToolSchema',
'description': 'Schema for query tool.',
'type': 'object',
'properties': {'query': {'title': 'Query',
'description': 'Search query for the query tool.',
'type': 'string'}},
'required': ['query']}
实例化研究员和作家代理
重要的代理参数:
import os
from crewai import Agent, Task, Crew, Process
# Define your agents with roles and goals
researcher = Agent(
role="Senior Financial Analyst",
goal="Uncover insights about different tech companies",
backstory="""You work at an asset management firm.
Your goal is to understand tech stocks like Uber.""",
verbose=True,
allow_delegation=False,
tools=[query_tool],
llm=chat_llm,
)
writer = Agent(
role="Tech Content Strategist",
goal="Craft compelling content on tech advancements",
backstory="""You are a renowned Content Strategist, known for your insightful and engaging articles.
You transform complex concepts into compelling narratives.""",
llm=chat_llm,
verbose=True,
allow_delegation=False,
)
定义各自的任务
重要参数:
# Create tasks for your agents
task1 = Task(
description="""Conduct a comprehensive analysis of Uber's risk factors in 2019.""",
expected_output="Full analysis report in bullet points",
agent=researcher,
)
task2 = Task(
description="""Using the insights provided, develop an engaging blog
post that highlights the headwinds that Uber faces.
Your post should be informative yet accessible, catering to a casual audience.
Make it sound cool, avoid complex words.""",
expected_output="Full blog post of at least 4 paragraphs",
agent=writer,
)
通过顺序流程实例化船员团队。在此组建您的成员。
crew = Crew(
agents=[researcher, writer],
tasks=[task1, task2],
verbose=2, # You can set it to 1 or 2 to different logging levels
)
启动代理工作流程
机组人员执行流程
# Get your crew to work!
result = crew.kickoff()
print("######################")
print(result)
##########################Response######################################
[2024-06-30 16:41:45][DEBUG]: == Working Agent: Senior Financial Analyst
[2024-06-30 16:41:45][INFO]: == Starting Task: Conduct a comprehensive analysis of Uber's risk factors in 2019.
> Entering new CrewAgentExecutor chain...
I need to understand the risk factors associated with Uber in 2019.
Action: Uber 2019 10K Query Tool
Action Input: {"query": "Item 1A. Risk Factors"}
Our business, financial condition, operating results, and prospects are exposed to various risks and uncertainties, including those related to our expansion into new markets, development of new technologies, and growth of our network of vertical take-off and landing vehicles. These risks may have a material adverse effect on our business, financial condition, and results of operations.
Thought:
I need to understand the specific risks associated with Uber's expansion into new markets.
Action: Uber 2019 10K Query Tool
Action Input: {"query": "expansion into new markets"}
The company believes that European shippers and carriers experience many of the same pain points in their current operations as U.S. shippers and carriers, and therefore, they announced the expansion of their Freight offering into Europe in March 2019.
Thought:
I need to understand the specific risks associated with Uber's expansion into new markets.
Action: Uber 2019 10K Query Tool
Action Input: {"query": "expansion into new markets risks"}
Our business is substantially dependent on operations outside the United States, including those in markets in which we have limited experience, and if we are unable to manage the risks presented by our business model internationally, our financial results and future prospects will be adversely impacted.
Thought:
I need to understand the risk factors associated with Uber's development of new technologies.
Action: Uber 2019 10K Query Tool
Action Input: {"query": "development of new technologies risks"}
The development of new technologies is inherently risky, and we may never realize any expected benefits from them. In addition, the safety risks associated with these new technologies, such as dockless e-bikes and e-scooters, may not be fully mitigated, even with our efforts to advise users of local safety regulations and offer promotional codes for helmets. If we do not spend our development budget efficiently or effectively on commercially successful and innovative technologies, we may not realize the expected benefits of our strategy, and users may be exposed to increased risks of injuries or death.
Thought:
I need to understand the risk factors associated with Uber's growth of network of vertical take-off and landing vehicles.
Action: Uber 2019 10K Query Tool
Action Input: {"query": "vertical take-off and landing vehicles risks"}
There is no mention of "vertical take-off and landing vehicles" or "VTOL" in the provided context information. The context discusses Uber's business, including its autonomous vehicle technologies, dockless e-bikes and e-scooters, Freight, and Uber Elevate, as well as risks related to these services, such as competition, regulatory issues, and safety concerns. However, it does not mention VTOL vehicles or any related risks.
Thought: I now know the final answer
Final Answer:
Comprehensive Analysis of Uber's Risk Factors in 2019:
• Our business, financial condition, operating results, and prospects are exposed to various risks and uncertainties, including those related to our expansion into new markets, development of new technologies, and growth of our network of vertical take-off and landing vehicles. These risks may have a material adverse effect on our business, financial condition, and results of operations.
• Risks associated with expansion into new markets:
• The company believes that European shippers and carriers experience many of the same pain points in their current operations as U.S. shippers and carriers, and therefore, they announced the expansion of their Freight offering into Europe in March 2019.
• Our business is substantially dependent on operations outside the United States, including those in markets in which we have limited experience, and if we are unable to manage the risks presented by our business model internationally, our financial results and future prospects will be adversely impacted.
• Risks associated with development of new technologies:
• The development of new technologies is inherently risky, and we may never realize any expected benefits from them.
• In addition, the safety risks associated with these new technologies, such as dockless e-bikes and e-scooters, may not be fully mitigated, even with our efforts to advise users of local safety regulations and offer promotional codes for helmets.
• If we do not spend our development budget efficiently or effectively on commercially successful and innovative technologies, we may not realize the expected benefits of our strategy, and users may be exposed to increased risks of injuries or death.
• Risks associated with growth of network of vertical take-off and landing vehicles:
• There is no mention of "vertical take-off and landing vehicles" or "VTOL" in the provided context information. The context discusses Uber's business, including its autonomous vehicle technologies, dockless e-bikes and e-scooters, Freight, and Uber Elevate, as well as risks related to these services, such as competition, regulatory issues, and safety concerns. However, it does not mention VTOL vehicles or any related risks.
> Finished chain.
[2024-06-30 16:45:39][DEBUG]: == [Senior Financial Analyst] Task output: Comprehensive Analysis of Uber's Risk Factors in 2019:
• Our business, financial condition, operating results, and prospects are exposed to various risks and uncertainties, including those related to our expansion into new markets, development of new technologies, and growth of our network of vertical take-off and landing vehicles. These risks may have a material adverse effect on our business, financial condition, and results of operations.
• Risks associated with expansion into new markets:
• The company believes that European shippers and carriers experience many of the same pain points in their current operations as U.S. shippers and carriers, and therefore, they announced the expansion of their Freight offering into Europe in March 2019.
• Our business is substantially dependent on operations outside the United States, including those in markets in which we have limited experience, and if we are unable to manage the risks presented by our business model internationally, our financial results and future prospects will be adversely impacted.
• Risks associated with development of new technologies:
• The development of new technologies is inherently risky, and we may never realize any expected benefits from them.
• In addition, the safety risks associated with these new technologies, such as dockless e-bikes and e-scooters, may not be fully mitigated, even with our efforts to advise users of local safety regulations and offer promotional codes for helmets.
• If we do not spend our development budget efficiently or effectively on commercially successful and innovative technologies, we may not realize the expected benefits of our strategy, and users may be exposed to increased risks of injuries or death.
• Risks associated with growth of network of vertical take-off and landing vehicles:
• There is no mention of "vertical take-off and landing vehicles" or "VTOL" in the provided context information. The context discusses Uber's business, including its autonomous vehicle technologies, dockless e-bikes and e-scooters, Freight, and Uber Elevate, as well as risks related to these services, such as competition, regulatory issues, and safety concerns. However, it does not mention VTOL vehicles or any related risks.
[2024-06-30 16:45:39][DEBUG]: == Working Agent: Tech Content Strategist
[2024-06-30 16:45:39][INFO]: == Starting Task: Using the insights provided, develop an engaging blog
post that highlights the headwinds that Uber faces.
Your post should be informative yet accessible, catering to a casual audience.
Make it sound cool, avoid complex words.
> Entering new CrewAgentExecutor chain...
Formatting errors incremented
Thought: I now can give a great answer
Final Answer:
**Uber's Turbulent Ride: Navigating the Headwinds Ahead**
As the pioneer of ride-hailing, Uber has revolutionized the way we move around cities. But beneath its sleek interface and convenient services, the company faces a multitude of challenges that threaten to disrupt its growth and profitability. In this post, we'll delve into the key headwinds that Uber must navigate to stay ahead of the curve.
**Expansion into New Markets: A Double-Edged Sword**
Uber's aggressive expansion into new markets, including Europe, may seem like a bold move, but it comes with its fair share of risks. The company's business model is heavily dependent on operations outside the United States, where it has limited experience. This lack of familiarity can lead to cultural and regulatory missteps, ultimately impacting its financial results and future prospects. Moreover, Uber must contend with local competitors who are better acquainted with the nuances of their respective markets. As the company ventures into uncharted territories, it must be prepared to adapt and innovate to stay competitive.
**The Risks of Innovation: Developing New Technologies**
Uber's foray into new technologies, such as dockless e-bikes and e-scooters, is a high-stakes game. While these innovations have the potential to disrupt traditional transportation models, they also come with inherent safety risks. The company must balance the need to advise users of local safety regulations with the need to promote its services and encourage adoption. Furthermore, the development of new technologies is inherently risky, and there's no guarantee that Uber will realize the expected benefits from its investments. If the company fails to spend its development budget efficiently, it may not only miss out on potential revenue streams but also expose users to increased risks of injuries or death.
**The Road Ahead: Navigating Regulatory Hurdles and Safety Concerns**
As Uber continues to grow and evolve, it must contend with a complex web of regulatory hurdles and safety concerns. From competition and regulatory issues to safety concerns and user trust, the company faces a multitude of challenges that can impact its bottom line. To stay ahead of the curve, Uber must prioritize user safety, invest in innovative technologies, and foster collaborative relationships with regulators and local authorities. By doing so, the company can mitigate the risks associated with its business model and continue to thrive in an increasingly competitive landscape.
In conclusion, Uber's journey to the top has been marked by innovation and disruption, but it's not without its challenges. As the company navigates the headwinds ahead, it must be prepared to adapt, innovate, and prioritize user safety above all else. By doing so, Uber can continue to revolutionize the transportation industry and stay ahead of the competition.
> Finished chain.
[2024-06-30 16:45:59][DEBUG]: == [Tech Content Strategist] Task output: **Uber's Turbulent Ride: Navigating the Headwinds Ahead**
As the pioneer of ride-hailing, Uber has revolutionized the way we move around cities. But beneath its sleek interface and convenient services, the company faces a multitude of challenges that threaten to disrupt its growth and profitability. In this post, we'll delve into the key headwinds that Uber must navigate to stay ahead of the curve.
**Expansion into New Markets: A Double-Edged Sword**
Uber's aggressive expansion into new markets, including Europe, may seem like a bold move, but it comes with its fair share of risks. The company's business model is heavily dependent on operations outside the United States, where it has limited experience. This lack of familiarity can lead to cultural and regulatory missteps, ultimately impacting its financial results and future prospects. Moreover, Uber must contend with local competitors who are better acquainted with the nuances of their respective markets. As the company ventures into uncharted territories, it must be prepared to adapt and innovate to stay competitive.
**The Risks of Innovation: Developing New Technologies**
Uber's foray into new technologies, such as dockless e-bikes and e-scooters, is a high-stakes game. While these innovations have the potential to disrupt traditional transportation models, they also come with inherent safety risks. The company must balance the need to advise users of local safety regulations with the need to promote its services and encourage adoption. Furthermore, the development of new technologies is inherently risky, and there's no guarantee that Uber will realize the expected benefits from its investments. If the company fails to spend its development budget efficiently, it may not only miss out on potential revenue streams but also expose users to increased risks of injuries or death.
**The Road Ahead: Navigating Regulatory Hurdles and Safety Concerns**
As Uber continues to grow and evolve, it must contend with a complex web of regulatory hurdles and safety concerns. From competition and regulatory issues to safety concerns and user trust, the company faces a multitude of challenges that can impact its bottom line. To stay ahead of the curve, Uber must prioritize user safety, invest in innovative technologies, and foster collaborative relationships with regulators and local authorities. By doing so, the company can mitigate the risks associated with its business model and continue to thrive in an increasingly competitive landscape.
In conclusion, Uber's journey to the top has been marked by innovation and disruption, but it's not without its challenges. As the company navigates the headwinds ahead, it must be prepared to adapt, innovate, and prioritize user safety above all else. By doing so, Uber can continue to revolutionize the transportation industry and stay ahead of the competition.
######################
最终答案
**Uber's Turbulent Ride: Navigating the Headwinds Ahead**
As the pioneer of ride-hailing, Uber has revolutionized the way we move around cities. But beneath its sleek interface and convenient services, the company faces a multitude of challenges that threaten to disrupt its growth and profitability. In this post, we'll delve into the key headwinds that Uber must navigate to stay ahead of the curve.
**Expansion into New Markets: A Double-Edged Sword**
Uber's aggressive expansion into new markets, including Europe, may seem like a bold move, but it comes with its fair share of risks. The company's business model is heavily dependent on operations outside the United States, where it has limited experience. This lack of familiarity can lead to cultural and regulatory missteps, ultimately impacting its financial results and future prospects. Moreover, Uber must contend with local competitors who are better acquainted with the nuances of their respective markets. As the company ventures into uncharted territories, it must be prepared to adapt and innovate to stay competitive.
**The Risks of Innovation: Developing New Technologies**
Uber's foray into new technologies, such as dockless e-bikes and e-scooters, is a high-stakes game. While these innovations have the potential to disrupt traditional transportation models, they also come with inherent safety risks. The company must balance the need to advise users of local safety regulations with the need to promote its services and encourage adoption. Furthermore, the development of new technologies is inherently risky, and there's no guarantee that Uber will realize the expected benefits from its investments. If the company fails to spend its development budget efficiently, it may not only miss out on potential revenue streams but also expose users to increased risks of injuries or death.
**The Road Ahead: Navigating Regulatory Hurdles and Safety Concerns**
As Uber continues to grow and evolve, it must contend with a complex web of regulatory hurdles and safety concerns. From competition and regulatory issues to safety concerns and user trust, the company faces a multitude of challenges that can impact its bottom line. To stay ahead of the curve, Uber must prioritize user safety, invest in innovative technologies, and foster collaborative relationships with regulators and local authorities. By doing so, the company can mitigate the risks associated with its business model and continue to thrive in an increasingly competitive landscape.
In conclusion, Uber's journey to the top has been marked by innovation and disruption, but it's not without its challenges. As the company navigates the headwinds ahead, it must be prepared to adapt, innovate, and prioritize user safety above all else. By doing so, Uber can continue to revolutionize the transportation industry and stay ahead of the competition.
结论
本解决方案基于 Llamaindex 分享的使用 CrewAI 的示例。