Skip to content

Commit

Permalink
docs: notebook install release (#370)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-desmond authored Feb 21, 2025
1 parent 2c2083c commit bb1fde7
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 26 deletions.
8 changes: 0 additions & 8 deletions python/examples/notebooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,6 @@ source .venv/bin/activate

📦 You are now ready to install dependencies:

Install beeai-framework from local package.

```shell
pip install .
```

Install other dependencies.

```shell
pip install -r examples/notebooks/requirements.txt
```
Expand Down
96 changes: 80 additions & 16 deletions python/examples/notebooks/agents.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,15 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with '.venv (Python 3.12.6)' requires the ipykernel package.\n",
"\u001b[1;31mRun the following command to install 'ipykernel' into the Python environment. \n",
"\u001b[1;31mCommand: '/Users/mdesmond/projects/beeai-framework/python/.venv/bin/python -m pip install ipykernel -U --force-reinstall'"
"name": "stdout",
"output_type": "stream",
"text": [
"Agent(thought) 🤖 : The user wants to know the chemical elements that form a water molecule. This information can be retrieved from general knowledge.\n",
"Agent(final_answer) 🤖 : A water molecule is composed of two hydrogen atoms and one oxygen atom, represented chemically as H2O.\n"
]
}
],
Expand Down Expand Up @@ -110,9 +108,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Agent(thought) 🤖 : The user wants to know the current weather in London. I will use the OpenMeteoTool with location_name as \"London\" and temperature_unit set to \"celsius\".\n",
"Agent(tool_name) 🤖 : OpenMeteoTool\n",
"Agent(tool_input) 🤖 : {\"location_name\": \"London\", \"temperature_unit\": \"celsius\"}\n",
"Agent(tool_output) 🤖 : {\"latitude\": 51.5, \"longitude\": -0.120000124, \"generationtime_ms\": 0.06175041198730469, \"utc_offset_seconds\": 0, \"timezone\": \"GMT\", \"timezone_abbreviation\": \"GMT\", \"elevation\": 23.0, \"current_units\": {\"time\": \"iso8601\", \"interval\": \"seconds\", \"temperature_2m\": \"\\u00b0C\", \"rain\": \"mm\", \"relative_humidity_2m\": \"%\", \"wind_speed_10m\": \"km/h\"}, \"current\": {\"time\": \"2025-02-21T17:30\", \"interval\": 900, \"temperature_2m\": 13.4, \"rain\": 0.1, \"relative_humidity_2m\": 77, \"wind_speed_10m\": 17.7}, \"daily_units\": {\"time\": \"iso8601\", \"temperature_2m_max\": \"\\u00b0C\", \"temperature_2m_min\": \"\\u00b0C\", \"rain_sum\": \"mm\"}, \"daily\": {\"time\": [\"2025-02-21\"], \"temperature_2m_max\": [14.9], \"temperature_2m_min\": [11.8], \"rain_sum\": [2.8]}}\n",
"Agent(thought) 🤖 : I have retrieved the current weather information for London. The temperature is 13.4 degrees Celsius with light rain and a wind speed of 17.7 km/h.\n",
"Agent(final_answer) 🤖 : The current weather in London is 13.4 degrees Celsius with light rain and a wind speed of 17.7 km/h.\n"
]
}
],
"source": [
"from beeai_framework.backend.chat import ChatModel\n",
"from beeai_framework.tools.weather.openmeteo import OpenMeteoTool\n",
Expand Down Expand Up @@ -142,9 +153,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Agent(thought) 🤖 : I can find this information using the Wikipedia tool.\n",
"Agent(tool_name) 🤖 : Wikipedia\n",
"Agent(tool_input) 🤖 : {\"query\": \"current president of the European Commission\"}\n",
"Agent(tool_output) 🤖 : Page: Vice-President of the European Commission\n",
"Summary: A Vice-President of the European Commission is a member of the European Commission who leads the commission's work in particular focus areas in which multiple European Commissioners participate.\n",
"Currently, the European Commission has a total of six Vice-Presidents: five Executive-Vice Presidents, and the High Representative who is ex officio one of the Vice-Presidents as well.\n",
"\n",
"Page: List of presidents of the institutions of the European Union\n",
"Summary: This is a list of presidents of the institutions of the European Union (EU). Each of the institutions is headed by a president or a presidency, with some being more prominent than others. Both the President of the European Council and the President of the European Commission are sometimes wrongly termed the President of the European Union. Most go back to 1957 but others, such as the Presidents of the Auditors or the European Central Bank have been created recently. Currently (2025), the President of the European Commission is Ursula von der Leyen and the President of the European Council is António Costa.\n",
"\n",
"Page: European Commission\n",
"Summary: The European Commission (EC) is the primary executive arm of the European Union (EU). It operates as a cabinet government, with a number of members of the Commission (directorial system, informally known as \"Commissioners\") corresponding to two thirds of the number of member states, unless the European Council, acting unanimously, decides to alter this number. The current number of Commissioners is 27, including the President. It includes an administrative body of about 32,000 European civil servants. The commission is divided into departments known as Directorates-General (DGs) that can be likened to departments or ministries each headed by a Director-General who is responsible to a Commissioner.\n",
"Currently, there is one member per member state, but members are bound by their oath of office to represent the general interest of the EU as a whole rather than their home state. The Commission President (currently Ursula von der Leyen) is proposed by the European Council (the 27 heads of state/governments) and elected by the European Parliament. The Council of the European Union then nominates the other members of the Commission in agreement with the nominated President, and the 27 members as a team are then subject to a vote of approval by the European Parliament. The current Commission is the Von der Leyen Commission II, which took office in December 2024, following the European Parliament elections in June of the same year.\n",
"Agent(thought) 🤖 : Based on the Wikipedia search results, Ursula von der Leyen is the current president of the European Commission.\n",
"Agent(final_answer) 🤖 : The current President of the European Commission is Ursula von der Leyen.\n"
]
}
],
"source": [
"from typing import Any\n",
"\n",
Expand Down Expand Up @@ -200,9 +233,40 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Agent(thought) 🤖 : The user wants to know about the longest living vertebrate. I can use the Wikipedia tool to search for this information.\n",
"Agent(tool_name) 🤖 : langchain_wikipedia_tool\n",
"Agent(tool_input) 🤖 : {\"query\": \"Longest living vertebrate\"}\n",
"Agent(tool_output) 🤖 : Page: Hákarl\n",
"Summary: Hákarl (an abbreviation of kæstur hákarl [ˈcʰaistʏr ˈhauːˌkʰa(r)tl̥]), referred to as fermented shark in English, is a national dish of Iceland consisting of Greenland shark or other sleeper shark that has been cured with a particular fermentation process and hung to dry for four to five months. It has a strong ammonia-rich smell and fishy taste, making hákarl an acquired taste.\n",
"Fermented shark is readily available in Icelandic stores and may be eaten year-round, but is most often served as part of a Þorramatur, a selection of traditional Icelandic food served at the midwinter festival þorrablót.\n",
"\n",
"Page: List of longest-living organisms\n",
"Summary: This is a list of the longest-living biological organisms: the individual(s) (or in some instances, clones) of a species with the longest natural maximum life spans. For a given species, such a designation may include:\n",
"\n",
"The oldest known individual(s) that are currently alive, with verified ages.\n",
"Verified individual record holders, such as the longest-lived human, Jeanne Calment, or the longest-lived domestic cat, Creme Puff.\n",
"The definition of \"longest-living\" used in this article considers only the observed or estimated length of an individual organism's natural lifespan – that is, the duration of time between its birth or conception, or the earliest emergence of its identity as an individual organism, and its death – and does not consider other conceivable interpretations of \"longest-living\", such as the length of time between the earliest appearance of a species in the fossil record and the present (the historical \"age\" of the species as a whole), the time between a species' first speciation and its extinction (the phylogenetic \"lifespan\" of the species), or the range of possible lifespans of a species' individuals. This list includes long-lived organisms that are currently still alive as well as those that are dead.\n",
"Determining the length of an organism's natural lifespan is complicated by many problems of definition and interpretation, as well as by practical difficulties in reliably measuring age, particularly for extremely old organisms and for those that reproduce by asexual cloning. In many cases the ages listed below are estimates based on observed present-day growth rates, which may differ significantly from the growth rates experienced thousands of years ago. Identifying the longest-living organisms also depends on defining what constitutes an \"individual\" organism, which can be problematic, since many asexual organisms and clonal colonies defy one or both of the traditional colloquial definitions of individuality (having a distinct genotype and having an independent, physically separate body). Additionally, some organisms maintain the capability to reproduce through very long periods of metabolic dormancy, during which they may not be considered \"alive\" by certain definitions but nonetheless can resume normal metabolism afterward; it is unclear whether the dormant periods should be counted as part of the organism's lifespan.\n",
"\n",
"\n",
"\n",
"Page: Greenland shark\n",
"Summary: The Greenland shark (Somniosus microcephalus), also known as the gurry shark or grey shark, is a large shark of the family Somniosidae (\"sleeper sharks\"), closely related to the Pacific and southern sleeper sharks. Inhabiting the North Atlantic and Arctic Oceans, they are notable for their exceptional longevity, although they are poorly studied due to the depth and remoteness of their natural habitat.\n",
"Greenland sharks have the longest lifespan of any known vertebrate, estimated to be between 250 and 500 years. They are among the largest extant species of shark, reaching a maximum confirmed length of 6.4 m (21 ft) long and weighing over 1,000 kg (2,200 lb). They reach sexual maturity at about 150 years of age, and their pups are born alive after an estimated gestation period of 8 to 18 years.\n",
"The shark is a generalist feeder, consuming a variety of available foods, including carrion.\n",
"Greenland shark \n",
"Agent(thought) 🤖 : The Wikipedia page \"List of longest-living organisms\" mentions that the Greenland shark has an estimated lifespan between 250 and 500 years, making it the longest living vertebrate known to science.\n",
"Agent(final_answer) 🤖 : The Greenland shark is the longest living vertebrate with an estimated lifespan of 250 to 500 years.\n"
]
}
],
"source": [
"from langchain_community.tools import WikipediaQueryRun # noqa: F811\n",
"from langchain_community.utilities import WikipediaAPIWrapper # noqa: F811\n",
Expand All @@ -214,7 +278,7 @@
"# defining a tool using the `tool` decorator\n",
"# Note: the pydoc is important as it serves as the tool description to the agent\n",
"@tool\n",
"def langchain_wikipedia_tool(expression: str) -> str:\n",
"def langchain_wikipedia_tool(query: str) -> str:\n",
" \"\"\"\n",
" Search factual and historical information, including biography, history, politics, geography, society, culture,\n",
" science, technology, people, animal species, mathematics, and other subjects.\n",
Expand All @@ -226,7 +290,7 @@
" The information found via searching Wikipedia.\n",
" \"\"\"\n",
" wikipedia = WikipediaQueryRun(api_wrapper=WikipediaAPIWrapper())\n",
" return StringToolOutput(wikipedia.run(expression))\n",
" return StringToolOutput(wikipedia.run(query))\n",
"\n",
"\n",
"# using the tool in an agent\n",
Expand Down
1 change: 1 addition & 0 deletions python/examples/notebooks/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
beeai-framework
langchain-community
ipykernel
jupyterlab
4 changes: 2 additions & 2 deletions python/examples/notebooks/workflows.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -249,7 +249,7 @@
" }\n",
" )\n",
" # Run search and store results in state\n",
" state.search_results = search_tool.run(response.object[\"query\"])\n",
" state.search_results = str(search_tool.run(response.object[\"query\"]))\n",
" return \"generate_answer\""
]
},
Expand Down

0 comments on commit bb1fde7

Please sign in to comment.