Skip to content

Commit

Permalink
Deploying to gh-pages from @ dce3f01 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-janssen committed Sep 14, 2024
1 parent 6a41ea3 commit 38a2cb9
Show file tree
Hide file tree
Showing 35 changed files with 289 additions and 305 deletions.
8 changes: 4 additions & 4 deletions README.html
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,10 @@
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1"><a class="reference internal" href="book/Benchmark.html">Benchmark</a></li>
<li class="toctree-l1"><a class="reference internal" href="book/first_agent.html">Crystalstructure Agent</a></li>
<li class="toctree-l1"><a class="reference internal" href="book/energy_volume_curve.html">Energy Volume Curve Agent</a></li>
<li class="toctree-l1"><a class="reference internal" href="book/demonstration.html">Hackathon Demonstration</a></li>
<li class="toctree-l1"><a class="reference internal" href="book/inverse-alloy-design.html">Inverse Alloy Design</a></li>
<li class="toctree-l1"><a class="reference internal" href="book/1-crystalstructure-agent.html">Crystalstructure Agent</a></li>
<li class="toctree-l1"><a class="reference internal" href="book/2-energy-volume-curve-agent.html">Energy Volume Curve Agent</a></li>
<li class="toctree-l1"><a class="reference internal" href="book/3-hackathon-demonstration.html">Hackathon Demonstration</a></li>
<li class="toctree-l1"><a class="reference internal" href="book/4-inverse-alloy-design.html">Inverse Alloy Design</a></li>
<li class="toctree-l1"><a class="reference internal" href="book/Literature.html">References</a></li>
<li class="toctree-l1"><a class="reference internal" href="book/Developer.html">For Developers</a></li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"metadata": {},
"source": [
"# Crystalstructure Agent\n",
"Develop an 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 a python function with the LLM. \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/modules/agents/how_to/custom_agent/) tutorial from the Langchain documentation. "
]
},
{
Expand All @@ -17,7 +17,7 @@
"metadata": {},
"source": [
"## Python Function\n",
"For this first example we use [OpenAI](https://www.langchain.com) as LLM provider but the example can also be adjusted to work with other LLM providers. We store the OpenAI API key in the `OPENAI_API_KEY` variable: "
"For this first example, we use [OpenAI](https://openai.com) as LLM provider but the example can also be adjusted to work with other LLM providers, for more details check the [langchain documentation](https://python.langchain.com/v0.2/docs/integrations/platforms/). We store the OpenAI API key in the `OPENAI_API_KEY` variable: "
]
},
{
Expand Down Expand Up @@ -52,9 +52,7 @@
"cell_type": "markdown",
"id": "136e7571-ac3b-4587-82b5-3351d6a6d3f2",
"metadata": {},
"source": [
"As a next step we import the corresponding functionality from `ASE` and the `tool` decorator from `langchain`:"
]
"source": "As a next step, we import the corresponding functionality from `ASE` and the `tool` decorator from `langchain`:"
},
{
"cell_type": "code",
Expand All @@ -71,9 +69,7 @@
"cell_type": "markdown",
"id": "3aae31dd-fb84-45f9-81b9-3f1f18786f4f",
"metadata": {},
"source": [
"For the python function it is important to include `type` hints and documentation based on a Docstring for the LLM to understand the functionality of the function. Finally, all data types used as input or output of the function need to have a `JSON` representation so they can be communicated to the LLM. For example numpy arrays have to be converted to standard python lists. "
]
"source": "For the python function, it is important to include `type` hints and documentation based on a Docstring for the LLM to understand the functionality of the function. Finally, all data types used as input or output of the function need to have a `JSON` representation so they can be communicated to the LLM. For example, numpy arrays have to be converted to standard python lists. "
},
{
"cell_type": "code",
Expand Down Expand Up @@ -148,7 +144,7 @@
"metadata": {},
"source": [
"## Define Agent\n",
"After the definition of the Python function, the next step is the definition of the agent which the LLM uses to interact with the Python function. In this example the `ChatOpenAI` interface of the `langchain_openai` package is used. Depending on your configuration it might be necessary to install this using: \n",
"After the definition of the Python function, the next step is the definition of the agent which the LLM uses to interact with the Python function. In this example the `ChatOpenAI` interface of the `langchain_openai` package is used. Depending on your configuration, it might be necessary to install the `langchain_openai` package using the following command: \n",
"```\n",
"conda install -c conda-forge langchain-openai\n",
"```"
Expand Down Expand Up @@ -256,14 +252,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 All @@ -276,11 +272,11 @@
"id": "43bc4d75-bae7-4fe2-8005-52e2629eec8d",
"metadata": {},
"source": [
"With the `verbose=True` parameter the internal steps of the LLM agent are printed in green. As a first step the Agent calls the `get_crystal_structure()` already with the converted input parameter, rather than using gold as input it uses the chemical symbol `Au`. The function returns `fcc` and the LLM converts this answer in a sentence a human can understand: \n",
"With the `verbose=True` parameter the internal steps of the LLM agent are printed in green. As a first step the agent calls the `get_crystal_structure()` already with the converted input parameter, rather than using gold as input it uses the chemical symbol `Au`. The function returns `fcc` and the LLM converts this answer in a sentence a human can understand: \n",
"```\n",
"The crystal structure of gold is face-centered cubic (fcc).\n",
"```\n",
"This example highlights how easy it is these days to make a python function accessible via an LLM for all kinds of users to interact with this python funtion."
"This example highlights how easy it is these days to make a python function accessible via a LLM for all kinds of users to interact with this python funtion."
]
},
{
Expand All @@ -304,14 +300,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 (C) 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 (C) 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,10 +379,10 @@
"text": [
"\n",
"\n",
"\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
"\u001b[32;1m\u001b[1;3mI'm sorry, but the query does not contain a valid chemical element. Please provide a chemical symbol for an element to determine its crystal structure.\u001b[0m\n",
"\u001B[1m> Entering new AgentExecutor chain...\u001B[0m\n",
"\u001B[32;1m\u001B[1;3mI'm sorry, but the query does not contain a valid chemical element. Please provide a chemical symbol for an element to determine its crystal structure.\u001B[0m\n",
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n"
"\u001B[1m> Finished chain.\u001B[0m\n"
]
}
],
Expand All @@ -398,17 +394,15 @@
"cell_type": "markdown",
"id": "f23ddd66-9032-41e0-90fb-a574845ce426",
"metadata": {},
"source": [
"With the modified system prompt the agent correctly replies that it was not able to determine the crystal structure of a car, because it fails to determine the chemical element a car consists of. "
]
"source": "With the modified system prompt, the agent correctly replies that it was not able to determine the crystal structure of a car, because it fails to determine the chemical element a car consists of. "
},
{
"cell_type": "markdown",
"id": "4a7f9b5f-cfe3-4b9c-9190-33d9505beedd",
"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 hallucinat."
"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."
]
},
{
Expand Down
Loading

0 comments on commit 38a2cb9

Please sign in to comment.