Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update link to tutorial #84

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions book/1-crystalstructure-agent-anthropic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"# Crystalstructure Agent\n",
"As a first demonstration the langchain team decided to develop a LLM agent, which can predict the crystal structure of a chemical element, by accessing the reference database of the [Atomic Simulation Environment](https://wiki.fysik.dtu.dk/ase/). While the corresponding python function is simple and only requires a few lines of code, this example already limits the hallucinations of the LLM, by using the [langchain](https://www.langchain.com) framework to interface the LLM with the python function. \n",
"\n",
"In particular, we follow the [Custom Agent](https://python.langchain.com/docs/modules/agents/how_to/custom_agent/) tutorial from the Langchain documentation. "
"In particular, we follow the [Custom Agent](https://python.langchain.com/docs/how_to/custom_tools/) tutorial from the Langchain documentation. "
]
},
{
Expand Down Expand Up @@ -64,7 +64,7 @@
"outputs": [],
"source": [
"from ase.data import reference_states, atomic_numbers\n",
"from langchain.agents import tool"
"from langchain_core.tools import tool"
]
},
{
Expand Down Expand Up @@ -203,9 +203,7 @@
"cell_type": "markdown",
"id": "367384b0-1fe6-43cf-a2b5-b3689e65b9fa",
"metadata": {},
"source": [
"Finally, the different parts are plugged together, by creating an agent which combines the prompt with the python function referenced here as one tool in a list of potentially many tools and an executor to communicate with the agent. The technical details are discussed in the corresponding [langchain Custom Agent tutorial](https://python.langchain.com/docs/modules/agents/how_to/custom_agent/)."
]
"source": "Finally, the different parts are plugged together, by creating an agent which combines the prompt with the python function referenced here as one tool in a list of potentially many tools and an executor to communicate with the agent. The technical details are discussed in the corresponding [langchain Custom Agent tutorial](https://python.langchain.com/docs/how_to/custom_tools/)."
},
{
"cell_type": "code",
Expand Down Expand Up @@ -256,14 +254,14 @@
"text": [
"\n",
"\n",
"\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
"\u001b[32;1m\u001b[1;3m\n",
"\u001B[1m> Entering new AgentExecutor chain...\u001B[0m\n",
"\u001B[32;1m\u001B[1;3m\n",
"Invoking: `get_crystal_structure` with `{'chemical_symbol': 'Au'}`\n",
"responded: [{'text': 'To answer your question about the crystal structure of gold, I can use the available tool to retrieve this information. Let me do that for you.', 'type': 'text', 'index': 0}, {'id': 'toolu_01CjhjuywsNK48xWcJ7YK2ND', 'input': {}, 'name': 'get_crystal_structure', 'type': 'tool_use', 'index': 1, 'partial_json': '{\"chemical_symbol\": \"Au\"}'}]\n",
"\n",
"\u001b[0m\u001b[36;1m\u001b[1;3mfcc\u001b[0m\u001b[32;1m\u001b[1;3m[{'text': \"\\n\\nBased on the result from the tool, I can tell you that the crystal structure of gold (Au) is face-centered cubic (fcc).\\n\\nFace-centered cubic (fcc) is one of the most common crystal structures found in metals. In this structure, atoms are arranged at the corners of a cubic lattice, with additional atoms at the center of each face of the cube. This arrangement gives gold its characteristic properties, such as its malleability and ductility.\\n\\nSome key features of the fcc structure in gold include:\\n\\n1. High atomic packing factor, which contributes to gold's high density.\\n2. Good ductility and malleability, allowing gold to be easily shaped into thin sheets or wires.\\n3. Excellent thermal and electrical conductivity.\\n4. Twelve nearest neighbors for each atom, contributing to its stability.\\n\\nThis crystal structure is one of the reasons why gold is so valued in jewelry making and various industrial applications, as it allows for easy manipulation while maintaining its desirable properties.\", 'type': 'text', 'index': 0}]\u001b[0m\n",
"\u001B[0m\u001B[36;1m\u001B[1;3mfcc\u001B[0m\u001B[32;1m\u001B[1;3m[{'text': \"\\n\\nBased on the result from the tool, I can tell you that the crystal structure of gold (Au) is face-centered cubic (fcc).\\n\\nFace-centered cubic (fcc) is one of the most common crystal structures found in metals. In this structure, atoms are arranged at the corners of a cubic lattice, with additional atoms at the center of each face of the cube. This arrangement gives gold its characteristic properties, such as its malleability and ductility.\\n\\nSome key features of the fcc structure in gold include:\\n\\n1. High atomic packing factor, which contributes to gold's high density.\\n2. Good ductility and malleability, allowing gold to be easily shaped into thin sheets or wires.\\n3. Excellent thermal and electrical conductivity.\\n4. Twelve nearest neighbors for each atom, contributing to its stability.\\n\\nThis crystal structure is one of the reasons why gold is so valued in jewelry making and various industrial applications, as it allows for easy manipulation while maintaining its desirable properties.\", 'type': 'text', 'index': 0}]\u001B[0m\n",
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n"
"\u001B[1m> Finished chain.\u001B[0m\n"
]
}
],
Expand Down Expand Up @@ -304,10 +302,10 @@
"text": [
"\n",
"\n",
"\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
"\u001b[32;1m\u001b[1;3m[{'text': 'I apologize, but I need to clarify something before I can answer your question. The term \"car\" is not a chemical symbol or element. To determine a crystal structure, we need to specify a chemical element or compound.\\n\\nThe tool available to us can provide information about the crystal structure of chemical elements based on their chemical symbols. For example, we could look up the crystal structure of iron (Fe), carbon (C), or aluminum (Al), which are common elements used in car manufacturing.\\n\\nCould you please specify which chemical element you\\'re interested in learning about? Once you provide a valid chemical symbol, I can use the tool to retrieve its crystal structure information for you.', 'type': 'text', 'index': 0}]\u001b[0m\n",
"\u001B[1m> Entering new AgentExecutor chain...\u001B[0m\n",
"\u001B[32;1m\u001B[1;3m[{'text': 'I apologize, but I need to clarify something before I can answer your question. The term \"car\" is not a chemical symbol or element. To determine a crystal structure, we need to specify a chemical element or compound.\\n\\nThe tool available to us can provide information about the crystal structure of chemical elements based on their chemical symbols. For example, we could look up the crystal structure of iron (Fe), carbon (C), or aluminum (Al), which are common elements used in car manufacturing.\\n\\nCould you please specify which chemical element you\\'re interested in learning about? Once you provide a valid chemical symbol, I can use the tool to retrieve its crystal structure information for you.', 'type': 'text', 'index': 0}]\u001B[0m\n",
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n"
"\u001B[1m> Finished chain.\u001B[0m\n"
]
}
],
Expand Down Expand Up @@ -379,10 +377,10 @@
"text": [
"\n",
"\n",
"\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
"\u001b[32;1m\u001b[1;3m[{'text': 'I apologize, but \"car\" is not a chemical element. To provide information about crystal structures, I need a valid chemical symbol for an element. Could you please provide the chemical symbol for an element you\\'d like to know about? For example, you could ask about elements like carbon (C), iron (Fe), or gold (Au).', 'type': 'text', 'index': 0}]\u001b[0m\n",
"\u001B[1m> Entering new AgentExecutor chain...\u001B[0m\n",
"\u001B[32;1m\u001B[1;3m[{'text': 'I apologize, but \"car\" is not a chemical element. To provide information about crystal structures, I need a valid chemical symbol for an element. Could you please provide the chemical symbol for an element you\\'d like to know about? For example, you could ask about elements like carbon (C), iron (Fe), or gold (Au).', 'type': 'text', 'index': 0}]\u001B[0m\n",
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n"
"\u001B[1m> Finished chain.\u001B[0m\n"
]
}
],
Expand All @@ -404,7 +402,7 @@
"metadata": {},
"source": [
"## Summary\n",
"By following the [Custom Agent](https://python.langchain.com/docs/modules/agents/how_to/custom_agent/) tutorial from the Langchain documentation, we were able to create a first simulation agent, which calls specialized python frameworks like [ASE](https://wiki.fysik.dtu.dk/ase/) to address material-science specific questions. Still, it is important to carefully engineer the prompt of the agent, otherwise even these LLMs with access to specialized agents tend to hallucinate."
"By following the [Custom Agent](https://python.langchain.com/docs/how_to/custom_tools/) tutorial from the Langchain documentation, we were able to create a first simulation agent, which calls specialized python frameworks like [ASE](https://wiki.fysik.dtu.dk/ase/) to address material-science specific questions. Still, it is important to carefully engineer the prompt of the agent, otherwise even these LLMs with access to specialized agents tend to hallucinate."
]
},
{
Expand Down
34 changes: 16 additions & 18 deletions book/1-crystalstructure-agent-groq.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"# Crystalstructure Agent\n",
"As a first demonstration the langchain team decided to develop a LLM agent, which can predict the crystal structure of a chemical element, by accessing the reference database of the [Atomic Simulation Environment](https://wiki.fysik.dtu.dk/ase/). While the corresponding python function is simple and only requires a few lines of code, this example already limits the hallucinations of the LLM, by using the [langchain](https://www.langchain.com) framework to interface the LLM with the python function. \n",
"\n",
"In particular, we follow the [Custom Agent](https://python.langchain.com/docs/modules/agents/how_to/custom_agent/) tutorial from the Langchain documentation. "
"In particular, we follow the [Custom Agent](https://python.langchain.com/docs/how_to/custom_tools/) tutorial from the Langchain documentation. "
]
},
{
Expand Down Expand Up @@ -64,7 +64,7 @@
"outputs": [],
"source": [
"from ase.data import reference_states, atomic_numbers\n",
"from langchain.agents import tool"
"from langchain_core.tools import tool"
]
},
{
Expand Down Expand Up @@ -203,9 +203,7 @@
"cell_type": "markdown",
"id": "367384b0-1fe6-43cf-a2b5-b3689e65b9fa",
"metadata": {},
"source": [
"Finally, the different parts are plugged together, by creating an agent which combines the prompt with the python function referenced here as one tool in a list of potentially many tools and an executor to communicate with the agent. The technical details are discussed in the corresponding [langchain Custom Agent tutorial](https://python.langchain.com/docs/modules/agents/how_to/custom_agent/)."
]
"source": "Finally, the different parts are plugged together, by creating an agent which combines the prompt with the python function referenced here as one tool in a list of potentially many tools and an executor to communicate with the agent. The technical details are discussed in the corresponding [langchain Custom Agent tutorial](https://python.langchain.com/docs/how_to/custom_tools/)."
},
{
"cell_type": "code",
Expand Down Expand Up @@ -256,14 +254,14 @@
"text": [
"\n",
"\n",
"\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
"\u001b[32;1m\u001b[1;3m\n",
"\u001B[1m> Entering new AgentExecutor chain...\u001B[0m\n",
"\u001B[32;1m\u001B[1;3m\n",
"Invoking: `get_crystal_structure` with `{'chemical_symbol': 'Au'}`\n",
"\n",
"\n",
"\u001b[0m\u001b[36;1m\u001b[1;3mfcc\u001b[0m\u001b[32;1m\u001b[1;3mThe crystal structure of gold is Face-Centered Cubic (FCC).\u001b[0m\n",
"\u001B[0m\u001B[36;1m\u001B[1;3mfcc\u001B[0m\u001B[32;1m\u001B[1;3mThe crystal structure of gold is Face-Centered Cubic (FCC).\u001B[0m\n",
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n"
"\u001B[1m> Finished chain.\u001B[0m\n"
]
}
],
Expand Down Expand Up @@ -304,14 +302,14 @@
"text": [
"\n",
"\n",
"\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
"\u001b[32;1m\u001b[1;3m\n",
"\u001B[1m> Entering new AgentExecutor chain...\u001B[0m\n",
"\u001B[32;1m\u001B[1;3m\n",
"Invoking: `get_crystal_structure` with `{'chemical_symbol': 'C'}`\n",
"\n",
"\n",
"\u001b[0m\u001b[36;1m\u001b[1;3mdiamond\u001b[0m\u001b[32;1m\u001b[1;3mThe crystal structure of carbon (car) is diamond.\u001b[0m\n",
"\u001B[0m\u001B[36;1m\u001B[1;3mdiamond\u001B[0m\u001B[32;1m\u001B[1;3mThe crystal structure of carbon (car) is diamond.\u001B[0m\n",
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n"
"\u001B[1m> Finished chain.\u001B[0m\n"
]
}
],
Expand Down Expand Up @@ -383,14 +381,14 @@
"text": [
"\n",
"\n",
"\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
"\u001b[32;1m\u001b[1;3m\n",
"\u001B[1m> Entering new AgentExecutor chain...\u001B[0m\n",
"\u001B[32;1m\u001B[1;3m\n",
"Invoking: `get_crystal_structure` with `{'chemical_symbol': 'C'}`\n",
"\n",
"\n",
"\u001b[0m\u001b[36;1m\u001b[1;3mdiamond\u001b[0m\u001b[32;1m\u001b[1;3mThe crystal structure of carbon is indeed diamond.\u001b[0m\n",
"\u001B[0m\u001B[36;1m\u001B[1;3mdiamond\u001B[0m\u001B[32;1m\u001B[1;3mThe crystal structure of carbon is indeed diamond.\u001B[0m\n",
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n"
"\u001B[1m> Finished chain.\u001B[0m\n"
]
}
],
Expand All @@ -412,7 +410,7 @@
"metadata": {},
"source": [
"## Summary\n",
"By following the [Custom Agent](https://python.langchain.com/docs/modules/agents/how_to/custom_agent/) tutorial from the Langchain documentation, we were able to create a first simulation agent, which calls specialized python frameworks like [ASE](https://wiki.fysik.dtu.dk/ase/) to address material-science specific questions. Still, it is important to carefully engineer the prompt of the agent, otherwise even these LLMs with access to specialized agents tend to hallucinate."
"By following the [Custom Agent](https://python.langchain.com/docs/how_to/custom_tools/) tutorial from the Langchain documentation, we were able to create a first simulation agent, which calls specialized python frameworks like [ASE](https://wiki.fysik.dtu.dk/ase/) to address material-science specific questions. Still, it is important to carefully engineer the prompt of the agent, otherwise even these LLMs with access to specialized agents tend to hallucinate."
]
},
{
Expand Down
10 changes: 4 additions & 6 deletions book/1-crystalstructure-agent.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"# Crystalstructure Agent\n",
"As a first demonstration the langchain team decided to develop a LLM agent, which can predict the crystal structure of a chemical element, by accessing the reference database of the [Atomic Simulation Environment](https://wiki.fysik.dtu.dk/ase/). While the corresponding python function is simple and only requires a few lines of code, this example already limits the hallucinations of the LLM, by using the [langchain](https://www.langchain.com) framework to interface the LLM with the python function. \n",
"\n",
"In particular, we follow the [Custom Agent](https://python.langchain.com/docs/modules/agents/how_to/custom_agent/) tutorial from the Langchain documentation. "
"In particular, we follow the [Custom Agent](https://python.langchain.com/docs/how_to/custom_tools/) tutorial from the Langchain documentation. "
]
},
{
Expand Down Expand Up @@ -62,7 +62,7 @@
"outputs": [],
"source": [
"from ase.data import reference_states, atomic_numbers\n",
"from langchain.agents import tool"
"from langchain_core.tools import tool"
]
},
{
Expand Down Expand Up @@ -199,9 +199,7 @@
"cell_type": "markdown",
"id": "367384b0-1fe6-43cf-a2b5-b3689e65b9fa",
"metadata": {},
"source": [
"Finally, the different parts are plugged together, by creating an agent which combines the prompt with the python function referenced here as one tool in a list of potentially many tools and an executor to communicate with the agent. The technical details are discussed in the corresponding [langchain Custom Agent tutorial](https://python.langchain.com/docs/modules/agents/how_to/custom_agent/)."
]
"source": "Finally, the different parts are plugged together, by creating an agent which combines the prompt with the python function referenced here as one tool in a list of potentially many tools and an executor to communicate with the agent. The technical details are discussed in the corresponding [langchain Custom Agent tutorial](https://python.langchain.com/docs/how_to/custom_tools/)."
},
{
"cell_type": "code",
Expand Down Expand Up @@ -402,7 +400,7 @@
"metadata": {},
"source": [
"## Summary\n",
"By following the [Custom Agent](https://python.langchain.com/docs/modules/agents/how_to/custom_agent/) tutorial from the Langchain documentation, we were able to create a first simulation agent, which calls specialized python frameworks like [ASE](https://wiki.fysik.dtu.dk/ase/) to address material-science specific questions. Still, it is important to carefully engineer the prompt of the agent, otherwise even these LLMs with access to specialized agents tend to hallucinate."
"By following the [Custom Agent](https://python.langchain.com/docs/how_to/custom_tools/) tutorial from the Langchain documentation, we were able to create a first simulation agent, which calls specialized python frameworks like [ASE](https://wiki.fysik.dtu.dk/ase/) to address material-science specific questions. Still, it is important to carefully engineer the prompt of the agent, otherwise even these LLMs with access to specialized agents tend to hallucinate."
]
},
{
Expand Down
Loading
Loading