LangChain Agent example
pip install langchain pip install google-search-results pip install openai from langchain.agents import load_tools from langchain.agents import initialize_agent from langchain.agents import AgentType from langchain.llms import OpenAI import os os.environ['OPENAI_API_KEY'] = str("xxxxxxxxxxxxxxxxxxx") os.environ["SERPAPI_API_KEY"] = str("xxxxxxxxxxxxxxxxxxx") llm = OpenAI(temperature=0,model_name='gpt-4-0314') tools = load_tools(["serpapi", "llm-math"], llm=llm) agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True) agent.run("What year was the founder of SpaceX and Tesla born and what is the name of the first company he founded?")
> Entering new AgentExecutor chain... I need to search for the birth year of the founder of SpaceX and Tesla and the name of his first company. Action: Search Action Input: founder of SpaceX and Tesla birth year and first company Observation: Elon Musk ; Born: June 28, 1971 (age 51) Pretoria South Africa ; Founder: PayPal SpaceX Zip2 ; Early life. Musk was born to a South African father and a Canadian ... Thought:I now know the final answer Final Answer: Elon Musk, the founder of SpaceX and Tesla, was born in 1971. The first company he founded was Zip2. > Finished chain. 'Elon Musk, the founder of SpaceX and Tesla, was born in 1971. The first company he founded was Zip2.
pip install langchain pip install wikipedia pip install openai from langchain.agents import load_tools from langchain.agents import initialize_agent from langchain.agents import AgentType from langchain.llms import OpenAI import os os.environ['OPENAI_API_KEY'] = str("xxxxxxxxxxxxxxxxxxxxxxxxxxx") llm = OpenAI(temperature=0,model_name='gpt-4-0314') tools = load_tools(["wikipedia"], llm=llm) agent = initialize_agent(tools, llm, agent="zero-shot-react-description", verbose=True) agent.run("What year was the founder of SpaceX and Tesla born and what is the name of the first company he founded?")
> Entering new AgentExecutor chain...
I need to find information about the founder of SpaceX and Tesla, including his birth year and the first company he founded.
Action Input: Elon Musk
Observation: Page: Elon Musk
Summary: Elon Reeve Musk ( EE-lon; born June 28, 1971) is a business magnate and investor. He is the founder, CEO and chief engineer of SpaceX; angel investor, CEO and product architect of Tesla, Inc.; owner and CEO of Twitter; founder of the Boring Company; co-founder of Neuralink and OpenAI; and president of the philanthropic Musk Foundation. With an estimated net worth of around $192 billion as of March 27, 2023, primarily from his ownership stakes in Tesla and SpaceX, Musk is the second-wealthiest person in the world, according to both the Bloomberg Billionaires Index and Forbes's real-time billionaires list.Musk was born in Pretoria, South Africa, and briefly attended at the University of Pretoria before moving to Canada at age 18, acquiring citizenship through his Canadian-born mother. Two years later, he matriculated at Queen's University and transferred to the University of Pennsylvania, where he received bachelor's degrees in economics and physics. He moved to California in 1995 to attend Stanford University. After two days, he dropped out and, with his brother Kimbal, co-founded the online city guide software company Zip2. In 1999, Zip2 was acquired by Compaq for $307 million and Musk co-founded X.com, a direct bank. X.com merged with Confinity in 2000 to form PayPal, which eBay acquired for $1.5 billion in 2002. Musk received an EB-5 investor green card in 1997, which led to his U.S. citizenship in 2002.With $175.8 million, Musk founded SpaceX in 2002, a spaceflight services company. In 2004, he was an early investor in the electric vehicle manufacturer Tesla Motors, Inc. (Tesla, Inc.). He became its chairman and product architect, assuming the position of CEO in 2008. In 2006, he helped create SolarCity, a solar energy company that was later acquired by Tesla and became Tesla Energy. In 2015, he co-founded OpenAI, a nonprofit artificial intelligence research company. The following year, he co-founded Neuralink—a neurotechnology company developing brain–computer interfaces—and the Boring Company, a tunnel construction company. Musk has also proposed a hyperloop high-speed vactrain transportation system. In 2022, his acquisition of Twitter for $44 billion was completed.
Musk has made controversial statements on politics and technology, particularly on Twitter, and is a polarizing figure. He has been criticized for making unscientific and misleading statements, including spreading COVID-19 misinformation. In 2018, the U.S. Securities and Exchange Commission (SEC) sued Musk for falsely tweeting that he had secured funding for a private takeover of Tesla. Musk stepped down as chairman of Tesla and paid a $20 million fine as part of a settlement agreement with the SEC.
Page: Acquisition of Twitter by Elon Musk
Summary: Business magnate Elon Musk initiated an acquisition of American social media company Twitter, Inc. on April 14, 2022, and concluded it on October 27, 2022. Musk had begun buying shares of the company in January 2022, becoming its largest shareholder by April with a 9.1 percent ownership stake. Twitter invited Musk to join its board of directors, an offer he initially accepted before declining. On April 14, Musk made an unsolicited offer to purchase the company, to which Twitter's board initially responded with a "poison pill" strategy to resist a hostile takeover, before unanimously accepting Musk's buyout offer of $44 billion on April 25. Musk stated that he planned to introduce new features to the platform, make its algorithms open-source, combat spambot accounts, and promote free speech.
In July, Musk announced his intention to terminate the agreement, asserting that Twitter had breached their agreement by refusing to crack down on spambot accounts. The company filed a lawsuit against Musk in the Delaware Court of Chancery shortly thereafter, with a trial scheduled for the week of October 17. Weeks before the trial was set to begin, Musk reversed course, announcing that he would move forward with the acquisition. The deal was closed on October 27, with Musk immediately becoming Twitter's new owner and CEO. Twitter was taken private and merged into a new parent company named X Corp. Upon acquiring Twitter, Musk promptly fired several top executives, including previous CEO Parag Agrawal. Musk has since proposed several reforms to Twitter and laid off half of the company's workforce. Hundreds of employees then resigned from the company after Musk issued an ultimatum demanding they commit to "extremely hardcore" work.
Reactions to the buyout have been mixed, with praise for Musk's planned reforms and vision for the company, particularly his calls for greater free speech, but criticism over fears of a potential rise in misinformation, disinformation, harassment, and hate speech on the platform. Within the United States, conservatives have largely supported the acquisition, while many liberals and former Twitter employees have voiced concerns about Musk's intentions. Since becoming owner, Musk has faced backlash for his handling of the company and account suspensions.
Page: Views of Elon Musk
Summary: Elon Musk, one of the richest men in the world and the CEO of Tesla, has expressed many views on a wide variety of subjects, ranging from politics to science.
Within the context of American politics, Musk has described himself as being politically moderate. Musk supported George W. Bush in 2004, Barack Obama in 2008 and 2012, Hillary Clinton in 2016, and Joe Biden in 2020. In 2022, Musk said he would start voting for Republican Party candidates. He has stated support for universal basic income, gun rights, freedom of speech, a tax on carbon emissions and opposes government subsidies.Musk is also a prominent critic of short-selling. Musk has expressed concern about issues such as artificial intelligence, climate change and population decline. He has also criticized COVID-19 lockdowns, public transportation, and labor unions.
Thought:I now know the final answer.
Final Answer: Elon Musk, the founder of SpaceX and Tesla, was born on June 28, 1971. The first company he founded was Zip2, which he co-founded with his brother Kimbal in 1995.
> Finished chain.
'Elon Musk, the founder of SpaceX and Tesla, was born on June 28, 1971. The first company he founded was Zip2, which he co-founded with his brother Kimbal in 1995.