<commit_before>{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This notebook shows you how ping the microservice that allows you to retrieve features given an issue title and body. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 183,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "import json\n",
    "import numpy as np\n",
    "from passlib.apps import custom_app_context as pwd_context\n",
    "API_ENDPOINT = 'https://embeddings.gh-issue-labeler.com/text'\n",
    "API_KEY = 'YOUR_API_KEY' # Hamel can give you this"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 189,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = {'title': 'Fix the issue', \n",
    "        'body': 'I am encountering an error\\n when trying to push the button.'}\n",
    "\n",
    "# sending post request and saving response as response object \n",
    "r = requests.post(url=API_ENDPOINT,\n",
    "                  headers={'Token':pwd_context.hash(API_KEY)},\n",
    "                  json=data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 190,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-0.00552384,  0.07269634,  0.01958341, ...,  0.19486058,\n",
       "       -0.08276526, -0.02112966], dtype=float32)"
      ]
     },
     "execution_count": 190,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.frombuffer(r.content, dtype='<f4')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "issue-features-api",
   "language": "python",
   "name": "issue-features-api"
  },
  "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.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}<commit_msg>clean up demo notebook (#10)<commit_after>{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h1 align=\"center\">GitHub Issue Embeddings API</h1> \n",
    "\n",
    "This tutorial shows you how ping the microservice that allows you to retrieve an embedding given an issue title and body. This notebook is [available on GitHub](https://github.com/kubeflow/code-intelligence/blob/master/Issue-Embeddings/notebooks/09_LangModel_API_Demo.ipynb)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Import Dependencies"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "import json\n",
    "import numpy as np\n",
    "from passlib.apps import custom_app_context as pwd_context\n",
    "API_ENDPOINT = 'https://embeddings.gh-issue-labeler.com/text'\n",
    "API_KEY = 'YOUR_API_KEY' # Contact maintainers for your api key"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## API Endpoints"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Route 1: `https://embeddings.gh-issue-labeler.com/text`\n",
    "\n",
    "Allows you to get embeddings for the raw text corresponding to a single GitHub issue.  The motivation for this endpoint is to use this at inference time, for example, when you need to perform computation on a new issue.\n",
    "\n",
    "This endpoint listens to `POST` requests, with the payload illustrated below:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = {'title': 'Fix the issue', \n",
    "        'body': 'I am encountering an error\\n when trying to push the button.'}\n",
    "\n",
    "# sending post request and saving response as response object \n",
    "r = requests.post(url=API_ENDPOINT,\n",
    "                  headers={'Token':pwd_context.hash(API_KEY)},\n",
    "                  json=data)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Convert byte stream sent over REST back to a numpy array.  The numpy array is a 2,400 dimensional embedding which are latent features of the GitHub Issue."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2400,)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "embeddings = np.frombuffer(r.content, dtype='<f4')\n",
    "embeddings.shape"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "issue-features-api",
   "language": "python",
   "name": "issue-features-api"
  },
  "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.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
{'fraction_non_alphanumeric': 0.18366549433372412, 'fraction_numerical': 0.02012504884720594, 'mean_word_length': 2.7148040638606674, 'pattern_counts': {'":': 94, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1688157', 'n_tokens_mistral': 1898, 'n_tokens_neox': 1795, 'n_words': 415}