Files
langchain/docs/modules/chains/examples/dbpedia.ipynb
Harrison Chase 159cc166c2 cr
2023-03-19 16:43:14 -07:00

107 lines
2.5 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"id": "546fd3f7",
"metadata": {},
"source": [
"# DBPedia\n",
"\n",
"This example shows how you can use LLMs to interact in natural language with a SPARKQL database."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "6f3bf955",
"metadata": {},
"outputs": [],
"source": [
"from langchain.chat_models import ChatOpenAI\n",
"from langchain.chains.dbpedia.base import DBPediaChain\n",
"model = ChatOpenAI(model_name=\"gpt-4\")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "09dbd131",
"metadata": {},
"outputs": [],
"source": [
"chain = DBPediaChain.from_llm(model, verbose=True)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "408cb57d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\n",
"\u001b[1m> Entering new DBPediaChain chain...\u001b[0m\n",
"Query written:\n",
"\u001b[32;1m\u001b[1;3mSELECT ?capital WHERE { \n",
" ?country rdfs:label \"Wakanda\"@en . \n",
" ?country dbo:capital ?capital . \n",
" ?capital rdfs:label ?capitalLabel .\n",
" FILTER (LANG(?capitalLabel) = 'en') \n",
"}\u001b[0m\n",
"Response gotten:\n",
"\u001b[32;1m\u001b[1;3m{'head': {'link': [], 'vars': ['capital']}, 'results': {'distinct': False, 'ordered': True, 'bindings': []}}\u001b[0m\n",
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n"
]
},
{
"data": {
"text/plain": [
"'There is no capital information available for Wakanda in the provided SPARQL query response. This is because Wakanda is a fictional country in the Marvel Cinematic Universe and does not have a real-world capital.'"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"chain.run(\"what is the capital of wakanda?\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "950e2472",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.1"
}
},
"nbformat": 4,
"nbformat_minor": 5
}