{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Neptune Open Cypher QA Chain\n",
    "This QA chain queries Neptune graph database using openCypher and returns human readable response\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain.graphs import NeptuneGraph\n",
    "\n",
    "\n",
    "host = \"<neptune-host>\"\n",
    "port = 8182\n",
    "use_https = True\n",
    "\n",
    "graph = NeptuneGraph(host=host, port=port, use_https=use_https)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'The Austin airport has 98 outgoing routes.'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from langchain.chat_models import ChatOpenAI\n",
    "from langchain.chains import NeptuneOpenCypherQAChain\n",
    "\n",
    "llm = ChatOpenAI(temperature=0, model=\"gpt-4\")\n",
    "\n",
    "chain = NeptuneOpenCypherQAChain.from_llm(llm=llm, graph=graph)\n",
    "\n",
    "chain.run(\"how many outgoing routes does the Austin airport have?\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "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.13"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
