{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "initial_id",
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": "pip install aidkit"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "aidkit --uri https://github.com/example/repo.git",
   "id": "b7b0419bfd476125"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": [
    "from aidkits import MarkdownCrawler\n",
    "\n",
    "MarkdownCrawler(\"repo/path\").work()"
   ],
   "id": "97955f58f0208b0"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "aidkit --uri ./local_directory --output_path result.json",
   "id": "d0dccb77a41ed0d3"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": [
    "[\n",
    "  {\n",
    "    \"title\": \"example.md\",\n",
    "    \"chunks\": [\n",
    "      {\n",
    "        \"title\": \"Header 1\",\n",
    "        \"content\": \"Content under Header 1\",\n",
    "        \"length\": 120,\n",
    "        \"chunk_num\": 1,\n",
    "        \"chunk_amount\": 2\n",
    "      },\n",
    "      {\n",
    "        \"title\": \"Header 2\",\n",
    "        \"content\": \"Content under Header 2\",\n",
    "        \"length\": 240,\n",
    "        \"chunk_num\": 2,\n",
    "        \"chunk_amount\": 2\n",
    "      }\n",
    "    ]\n",
    "  }\n",
    "]"
   ],
   "id": "e0e26eb45a5d2568"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": [
    "from opensearchpy import OpenSearch\n",
    "from sentence_transformers import SentenceTransformer\n",
    "from aidkits.opensearch_retriever import OpenSearchRetriever\n",
    "from aidkits.models import LibrarySource\n",
    "\n",
    "# Initialize the OpenSearch client\n",
    "client = OpenSearch(\n",
    "   hosts=[{\"host\": \"localhost\", \"port\": 9200}],\n",
    "   http_auth=(\"admin\", \"admin\"),\n",
    "   use_ssl=False,\n",
    "   verify_certs=False,\n",
    ")\n",
    "\n",
    "# Initialize the encoder\n",
    "encoder = SentenceTransformer(\"all-MiniLM-L6-v2\")\n",
    "\n",
    "# Create the retriever\n",
    "retriever = OpenSearchRetriever(client, encoder)\n",
    "\n",
    "# Create a collection\n",
    "retriever.create_collection(\"documentation\")\n",
    "\n",
    "# Upload a library\n",
    "library = LibrarySource.from_json(\"path/to/library.json\")\n",
    "retriever.upload_library(library)\n",
    "\n",
    "# Search for documents\n",
    "results = retriever.search(\n",
    "   question=\"How do I use the API?\",\n",
    "   collection_name=\"documentation\",\n",
    "   top_k=5\n",
    ")\n",
    "\n",
    "# Print the results\n",
    "for result in results:\n",
    "   print(result.markdown)"
   ],
   "id": "e5f682b302a22f00"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": [
    "from langchain_core.language_models import ChatOpenAI\n",
    "from aidkits.documentation_tool import DocumentationTool\n",
    "from aidkits.opensearch_retriever import OpenSearchRetriever\n",
    "\n",
    "# Initialize the language model\n",
    "llm = ChatOpenAI(model=\"gpt-3.5-turbo\")\n",
    "\n",
    "# Initialize the retriever (as shown above)\n",
    "# ...\n",
    "\n",
    "# Create the documentation tool\n",
    "doc_tool = DocumentationTool(\n",
    "   llm=llm,\n",
    "   retriever=retriever,\n",
    "   collection_name=\"documentation\",\n",
    "   top_k=5\n",
    ")\n",
    "\n",
    "# Answer a question\n",
    "answer = doc_tool.invoke({\"question\": \"How do I use the API?\"})\n",
    "print(answer)"
   ],
   "id": "de096fd0222b7d07"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
