Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save davidaparicio/b4905b63dcce8fdb2770656891a18e7d to your computer and use it in GitHub Desktop.
Save davidaparicio/b4905b63dcce8fdb2770656891a18e7d to your computer and use it in GitHub Desktop.
Talk meetup Python Lyon
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 51,
"id": "03c0561e-c0fa-4293-8e90-a48b0d7ddaca",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"huggingface/tokenizers: The current process just got forked, after parallelism has already been used. Disabling parallelism to avoid deadlocks...\n",
"To disable this warning, you can either:\n",
"\t- Avoid using `tokenizers` before the fork if possible\n",
"\t- Explicitly set the environment variable TOKENIZERS_PARALLELISM=(true | false)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.3.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.2\u001b[0m\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"pip install -qU \"langchain-chroma>=0.1.2\" langchain_huggingface sentence_transformers langchain-openai"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "08c2b03b-a9d2-4c50-8bdc-f43fe16869ac",
"metadata": {},
"outputs": [],
"source": [
"GH_TOKEN = \"gh_token\"\n",
"AI_ENDPOINTS_TOKEN=\"you_token\"\n",
"from langchain_community.document_loaders import GitHubIssuesLoader\n",
"from langchain_huggingface.embeddings import HuggingFaceEmbeddings\n",
"from langchain.docstore.document import Document\n",
"from langchain_chroma import Chroma\n",
"from langchain.vectorstores import utils as chromautils\n",
"from langchain_core.messages import HumanMessage, AIMessage, SystemMessage"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "41ebf3bc-4325-4f94-b9c1-256aa2e0cdb4",
"metadata": {},
"outputs": [],
"source": [
"from langchain_core.tools import tool\n",
"\n",
"@tool\n",
"def diagnostic_infra(ip_address: str) -> str:\n",
" \"\"\"Perform a quick diagnostic on a given IPv4 address to check if the infra is healthy or not.\n",
" Only call if an IP is present in the text\n",
"\n",
" Args:\n",
" ip_address: IPv4 address of customer gateway\n",
" \"\"\"\n",
" return f\"Server for {ip_address} is currently shut down and can't forward any trafic or be contacted\"\n",
"\n",
"tools = [diagnostic_infra]\n",
"import re\n",
"\n",
"pat = re.compile(\"^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$\")\n",
"check_ip = lambda x: pat.match(x)\n",
"check_ip(\"1.2.3.a\")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "7afd46c9-5153-4d9f-91a6-a5e98df548d1",
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"import json\n",
"import ast\n",
"\n",
"from langchain_openai import ChatOpenAI\n",
"# OVH AI endpoint does not support Function calling while in Alpha, but will in GA. You can use any OpenAI compatible service instead\n",
"llm = ChatOpenAI(model=\"NousResearch/Hermes-2-Pro-Llama-3-8B\",\n",
" base_url=\"https://openai-endpoint\",\n",
" api_key=AI_ENDPOINTS_TOKEN)\n",
"def ask_llm(tool=False):\n",
" messages = []\n",
" chat = llm\n",
" if tool:\n",
" chat = llm.bind_tools(tools)\n",
" while True:\n",
" prompt = input(\"[User]> \")\n",
" if prompt.lower() == \"exit\":\n",
" break\n",
" messages.append(HumanMessage(prompt))\n",
" name = \"\"\n",
" args = \"\"\n",
" \n",
" print(\"[Llama-3-8B]> \", end=\"\", flush=True)\n",
" ct = \"\"\n",
" for chunk in chat.stream(messages):\n",
" if chunk.tool_call_chunks:\n",
" name += str(chunk.tool_call_chunks[0]['name']) if chunk.tool_call_chunks[0]['name'] else \"\"\n",
" args += str(chunk.tool_call_chunks[0]['args']) if chunk.tool_call_chunks[0]['args'] else \"\"\n",
" print(chunk.content, end=\"\", flush=True)\n",
" ct += chunk.content\n",
" messages.append(AIMessage(ct))\n",
" print(name, args)\n",
" if name and args:\n",
" dct = ast.literal_eval(args)\n",
" print(dct)\n",
" if not check_ip(dct['ip_address']):\n",
" continue\n",
" res = globals()[name].func(**ast.literal_eval(args))\n",
" if res:\n",
" messages.append(HumanMessage(f\"\\nINFRA_DIAGNOSTIC_RESULT: {res}\\nAbove is the state of customer infra, Now redo your diagnostic\"))\n",
" for chunk in llm.stream(messages):\n",
" print(chunk.content, end=\"\", flush=True)\n",
" print(\"done\")"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "b18c069b-3244-4601-a3fb-5db059c30e2c",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"[User]> exit\n"
]
}
],
"source": [
"#Help on infra 1.2.3.4 plz\n",
"# Why can't I ping server 56.12.32.12\n",
"# Why is my gateway 56.12.32.12 not forwarding trafic\n",
"ask_llm()"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "cddf706a-def2-4dc0-a4d6-ad077995cda3",
"metadata": {},
"outputs": [
{
"ename": "ValidationError",
"evalue": "1 validation error for GitHubIssuesLoader\n Value error, Did not find access_token, please add an environment variable `GITHUB_PERSONAL_ACCESS_TOKEN` which contains it, or pass `access_token` as a named parameter. [type=value_error, input_value={'repo': 'ovh/the-bastion...en': '', 'state': 'all'}, input_type=dict]\n For further information visit https://errors.pydantic.dev/2.9/v/value_error",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValidationError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[8], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m loader \u001b[38;5;241m=\u001b[39m \u001b[43mGitHubIssuesLoader\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 2\u001b[0m \u001b[43m \u001b[49m\u001b[43mrepo\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43movh/the-bastion\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 3\u001b[0m \u001b[43m \u001b[49m\u001b[43maccess_token\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mGH_TOKEN\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 4\u001b[0m \u001b[43m \u001b[49m\u001b[43mstate\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mall\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;66;43;03m# delete/comment out this argument if you've set the access token as an env var.\u001b[39;49;00m\n\u001b[1;32m 5\u001b[0m \u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/.miniconda3/lib/python3.11/site-packages/pydantic/main.py:212\u001b[0m, in \u001b[0;36mBaseModel.__init__\u001b[0;34m(self, **data)\u001b[0m\n\u001b[1;32m 210\u001b[0m \u001b[38;5;66;03m# `__tracebackhide__` tells pytest and some other tools to omit this function from tracebacks\u001b[39;00m\n\u001b[1;32m 211\u001b[0m __tracebackhide__ \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[0;32m--> 212\u001b[0m validated_self \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m__pydantic_validator__\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mvalidate_python\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdata\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mself_instance\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 213\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m validated_self:\n\u001b[1;32m 214\u001b[0m warnings\u001b[38;5;241m.\u001b[39mwarn(\n\u001b[1;32m 215\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mA custom validator is returning a value other than `self`.\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 216\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mReturning anything other than `self` from a top level model validator isn\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mt supported when validating via `__init__`.\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 217\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mSee the `model_validator` docs (https://docs.pydantic.dev/latest/concepts/validators/#model-validators) for more details.\u001b[39m\u001b[38;5;124m'\u001b[39m,\n\u001b[1;32m 218\u001b[0m category\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 219\u001b[0m )\n",
"\u001b[0;31mValidationError\u001b[0m: 1 validation error for GitHubIssuesLoader\n Value error, Did not find access_token, please add an environment variable `GITHUB_PERSONAL_ACCESS_TOKEN` which contains it, or pass `access_token` as a named parameter. [type=value_error, input_value={'repo': 'ovh/the-bastion...en': '', 'state': 'all'}, input_type=dict]\n For further information visit https://errors.pydantic.dev/2.9/v/value_error"
]
}
],
"source": [
"loader = GitHubIssuesLoader(\n",
" repo=\"ovh/the-bastion\",\n",
" access_token=GH_TOKEN,\n",
" state=\"all\"# delete/comment out this argument if you've set the access token as an env var.\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 63,
"id": "b58a9226-260f-4ea5-9e88-cd88017c318a",
"metadata": {},
"outputs": [],
"source": [
"#docs = loader.load()\n",
"# OR\n",
"with open(\"docs.pkl\", \"rb\") as _f:\n",
" docs = pickle.load(_f)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "fcf52c2f-4f95-4ce4-abcf-02731d7686c3",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/workspace/.miniconda3/lib/python3.11/site-packages/sentence_transformers/cross_encoder/CrossEncoder.py:13: TqdmExperimentalWarning: Using `tqdm.autonotebook.tqdm` in notebook mode. Use `tqdm.tqdm` instead to force console mode (e.g. in jupyter console)\n",
" from tqdm.autonotebook import tqdm, trange\n",
"2024-09-26 08:00:32.418177: I tensorflow/core/util/port.cc:110] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.\n",
"2024-09-26 08:00:34.476654: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.\n",
"To enable the following instructions: AVX2 AVX512F AVX512_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n",
"2024-09-26 08:00:42.788830: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT\n"
]
}
],
"source": [
"embeddings = HuggingFaceEmbeddings(model_name=\"intfloat/multilingual-e5-base\")"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "df74fa36-9a53-47a3-98d8-03dcafff8c83",
"metadata": {},
"outputs": [],
"source": [
"vector_store_titles = Chroma(\n",
" collection_name=\"bastion_docs_titles\",\n",
" embedding_function=embeddings,\n",
" persist_directory=\"./chroma_langchain_db\", # Where to save data locally, remove if not neccesary\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "f8b89783-b539-41a1-b5b4-68e993d45941",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Added\n"
]
}
],
"source": [
"filtered_docs = chromautils.filter_complex_metadata(docs)\n",
"vector_store_titles.add_documents(documents=[Document(page_content=doc.metadata['title'], metadata=doc.metadata) for doc in docs], ids=list(map(str, range(len(filtered_docs)))))\n",
"print(\"Issues added to Vector DB\")"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "825cd283-1bf2-4b6f-bb80-54909ab7b452",
"metadata": {},
"outputs": [],
"source": [
"USER_PROMPT = \"\"\"Connection to bastion is very slow, why\"\"\""
]
},
{
"cell_type": "code",
"execution_count": 206,
"id": "5c514b7e-314f-4743-b795-447c9a88aa5c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Closest issues from your new issue:\n",
"Issue 397#: Connection to the Bastion takes many seconds\n",
"Issue 244#: DNS timeout hangs the bastion\n"
]
}
],
"source": [
"results = vector_store_titles.similarity_search(\n",
" USER_PROMPT,\n",
" k=2,\n",
")\n",
"print(\"Closest issues from your new issue:\")\n",
"for res in results:\n",
" print(f\"Issue {res.metadata['number']}#: {res.page_content}\")"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "7f09b33b-876b-4c19-834a-e0d57620fcf8",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['Hey,\\r\\n\\r\\nWhen you talk about the shell, do you mean the interactive mode prompt? (as follows)\\r\\n\\r\\n```\\r\\nWelcome to fix-my-config-please-missing-bastion-name interactive mode, type `help\\' for available commands.\\r\\nYou can use <tab> and <tab><tab> for autocompletion.\\r\\nYou\\'ll be disconnected after 60 seconds of inactivity.\\r\\nLoading... 90 commands and 372 autocompletion rules loaded.\\r\\n\\r\\nyou@bastion(master)>\\r\\n```\\r\\n\\r\\nbefore the \"you@bastion(master)\" prompt appears, but after the \"Loading....\" message does?\\r\\n\\r\\nNote that if it\\'s slow on the early phase of the connection (before any text is printed), a common cause is a broken DNS configuration on your system.', \"Hi,\\r\\nI've been there, and spend almost 3 weeks debugging that stupid error. Finally debuged that line by line in perl... but to the point.\\r\\nThe bastion is trying to find a name for your client using dns request - so this is taking reallly long 20s after it finds out that there is no dns name for your client thus you waiting each command execution 20s xd. It's nice when clients have such name but for dayli usage it doesn't have.\\r\\n\\r\\nThe answer is to turn your dns off -> comment out everything in /etc/resolv.conf\\r\\n \\r\\n Regards,\\r\\n ;3\", 'Hi.\\r\\nTry use options in your `/etc/resolv.conf` for test env. For example:\\r\\n```\\r\\noptions attempts=2, timeout=2, rotate\\r\\nnameserver 1.1.1.1\\r\\nnameserver 8.8.8.8\\r\\n```\\r\\n\\r\\nFor debug, try `options debug`', \"Closing, as this is not directly related to The Bastion: if your `/etc/resolv.conf` point to unresponsive DNS servers, any program running on your system will appear to be slow when attempting to use the DNS. The Bastion uses the DNS to resolve any hostname you may have passed to it, but also to get the PTR of the IP it's connecting to, for audit logs purposes.\"]\n"
]
}
],
"source": [
"import requests\n",
"def get_issue_member_comments(issue_number):\n",
" res = requests.get(f\"https://api.github.com/repos/ovh/the-bastion/issues/{issue_number}/comments\",\n",
" headers={\n",
" \"Authorization\": f\"Bearer {GH_TOKEN}\"})\n",
" js = res.json()\n",
" return [item for item in js]# if item[\"author_association\"] in {\"MEMBER\", \"CONTRIBUTOR\"}]\n",
"\n",
"context = []\n",
"for issue in results:\n",
" valid_comments = get_issue_member_comments(issue.metadata['number'])\n",
" _context = [comm['body'] for comm in valid_comments]\n",
" context.extend(_context)\n",
"print(context)"
]
},
{
"cell_type": "code",
"execution_count": 40,
"id": "2852d659-35a4-4f5b-9b90-15c58dd1105b",
"metadata": {},
"outputs": [],
"source": [
"def build_prompt(user_text, context):\n",
" context_to_str = \"\\n\".join([f\"TECHNICIAN_ANSWER: {answer}\" for answer in context])\n",
" prompt = f\"\"\"You're a support agent, please help us answer customer issues from our Github.\\n Here's the answer from our technicians to similar tickets:{context_to_str}\n",
"\n",
"Now, taking into account our past answers, build a precise Github answer to this issue:\\n{user_text}\"\"\"\n",
" return prompt\n",
"\n",
"ready_prompt=build_prompt(USER_PROMPT, context)"
]
},
{
"cell_type": "code",
"execution_count": 41,
"id": "de55a93c-7007-4f2d-81f8-cb0559fec689",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'You\\'re a support agent, please help us answer customer issues from our Github.\\n Here\\'s the answer from our technicians to similar tickets:TECHNICIAN_ANSWER: Hey,\\r\\n\\r\\nWhen you talk about the shell, do you mean the interactive mode prompt? (as follows)\\r\\n\\r\\n```\\r\\nWelcome to fix-my-config-please-missing-bastion-name interactive mode, type `help\\' for available commands.\\r\\nYou can use <tab> and <tab><tab> for autocompletion.\\r\\nYou\\'ll be disconnected after 60 seconds of inactivity.\\r\\nLoading... 90 commands and 372 autocompletion rules loaded.\\r\\n\\r\\nyou@bastion(master)>\\r\\n```\\r\\n\\r\\nbefore the \"you@bastion(master)\" prompt appears, but after the \"Loading....\" message does?\\r\\n\\r\\nNote that if it\\'s slow on the early phase of the connection (before any text is printed), a common cause is a broken DNS configuration on your system.\\nTECHNICIAN_ANSWER: Hi,\\r\\nI\\'ve been there, and spend almost 3 weeks debugging that stupid error. Finally debuged that line by line in perl... but to the point.\\r\\nThe bastion is trying to find a name for your client using dns request - so this is taking reallly long 20s after it finds out that there is no dns name for your client thus you waiting each command execution 20s xd. It\\'s nice when clients have such name but for dayli usage it doesn\\'t have.\\r\\n\\r\\nThe answer is to turn your dns off -> comment out everything in /etc/resolv.conf\\r\\n \\r\\n Regards,\\r\\n ;3\\nTECHNICIAN_ANSWER: Hi.\\r\\nTry use options in your `/etc/resolv.conf` for test env. For example:\\r\\n```\\r\\noptions attempts=2, timeout=2, rotate\\r\\nnameserver 1.1.1.1\\r\\nnameserver 8.8.8.8\\r\\n```\\r\\n\\r\\nFor debug, try `options debug`\\nTECHNICIAN_ANSWER: Closing, as this is not directly related to The Bastion: if your `/etc/resolv.conf` point to unresponsive DNS servers, any program running on your system will appear to be slow when attempting to use the DNS. The Bastion uses the DNS to resolve any hostname you may have passed to it, but also to get the PTR of the IP it\\'s connecting to, for audit logs purposes.\\n\\nNow, taking into account our past answers, build a precise Github answer to this issue:\\nConnection to bastion is very slow, why'"
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ready_prompt"
]
},
{
"cell_type": "code",
"execution_count": 207,
"id": "197fad3a-18fc-482a-b3c4-294214c35b20",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"[User]> You\\'re a support agent, please help us answer customer issues from our Github.\\n Here\\'s the answer from our technicians to similar tickets:TECHNICIAN_ANSWER: Hey,\\r\\n\\r\\nWhen you talk about the shell, do you mean the interactive mode prompt? (as follows)\\r\\n\\r\\n```\\r\\nWelcome to fix-my-config-please-missing-bastion-name interactive mode, type `help\\' for available commands.\\r\\nYou can use <tab> and <tab><tab> for autocompletion.\\r\\nYou\\'ll be disconnected after 60 seconds of inactivity.\\r\\nLoading... 90 commands and 372 autocompletion rules loaded.\\r\\n\\r\\nyou@bastion(master)>\\r\\n```\\r\\n\\r\\nbefore the \"you@bastion(master)\" prompt appears, but after the \"Loading....\" message does?\\r\\n\\r\\nNote that if it\\'s slow on the early phase of the connection (before any text is printed), a common cause is a broken DNS configuration on your system.\\nTECHNICIAN_ANSWER: Hi,\\r\\nI\\'ve been there, and spend almost 3 weeks debugging that stupid error. Finally debuged that line by line in perl... but to the point.\\r\\nThe bastion is trying to find a name for your client using dns request - so this is taking reallly long 20s after it finds out that there is no dns name for your client thus you waiting each command execution 20s xd. It\\'s nice when clients have such name but for dayli usage it doesn\\'t have.\\r\\n\\r\\nThe answer is to turn your dns off -> comment out everything in /etc/resolv.conf\\r\\n \\r\\n Regards,\\r\\n ;3\\nTECHNICIAN_ANSWER: Hi.\\r\\nTry use options in your `/etc/resolv.conf` for test env. For example:\\r\\n```\\r\\noptions attempts=2, timeout=2, rotate\\r\\nnameserver 1.1.1.1\\r\\nnameserver 8.8.8.8\\r\\n```\\r\\n\\r\\nFor debug, try `options debug`\\nTECHNICIAN_ANSWER: Closing, as this is not directly related to The Bastion: if your `/etc/resolv.conf` point to unresponsive DNS servers, any program running on your system will appear to be slow when attempting to use the DNS. The Bastion uses the DNS to resolve any hostname you may have passed to it, but also to get the PTR of the IP it\\'s connecting to, for audit logs purposes.\\n\\nNow, taking into account our past answers, build a precise Github answer to this issue:\\nConnection to bastion is very slow, why\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"[Llama-3-8B]> is this happening? \n",
"\n",
"Dear Customer, \n",
"\n",
"It appears that the connection to our Bastion is slow before the \"you@bastion(master)>\" prompt appears, particularly after the \"Loading...\" message. This issue may be caused by a broken DNS configuration on your system or slow DNS resolution.\n",
"\n",
"To resolve this issue, we recommend taking the following steps:\n",
"\n",
"1. **Check your DNS configuration:** Ensure that your `/etc/resolv.conf` file is properly configured with accurate nameserver addresses. You can also try commenting out everything in this file to disable DNS resolution temporarily and see if that speeds up the connection process.\n",
"2. **Use options in your `/etc/resolv.conf` file:** To optimize DNS resolution for a test environment, you can add options to your `/etc/resolv.conf` file, such as:\n",
"``` \n",
"options attempts=2 timeout=2 rotate\n",
"nameserver 1.1.1.1\n",
"nameserver 8.8.8.8\n",
"```\n",
"3. **Debug DNS resolution:** If you want to troubleshoot further, you can add the `options debug` line to your `/etc/resolv.conf` file to enable debugging information for DNS queries.\n",
"\n",
"If the issue persists, please make sure that your system is not experiencing any other performance-related issues that might affect the connection speed. If you still face this problem, feel free to reach out to our support team again for further assistance. We're here to help! \n"
]
},
{
"ename": "KeyboardInterrupt",
"evalue": "Interrupted by user",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[207], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mask_llm\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
"Cell \u001b[0;32mIn[194], line 15\u001b[0m, in \u001b[0;36mask_llm\u001b[0;34m(tool)\u001b[0m\n\u001b[1;32m 13\u001b[0m chat \u001b[38;5;241m=\u001b[39m llm\u001b[38;5;241m.\u001b[39mbind_tools(tools)\n\u001b[1;32m 14\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m:\n\u001b[0;32m---> 15\u001b[0m prompt \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43minput\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m[User]> \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 16\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m prompt\u001b[38;5;241m.\u001b[39mlower() \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mexit\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[1;32m 17\u001b[0m \u001b[38;5;28;01mbreak\u001b[39;00m\n",
"File \u001b[0;32m~/.miniconda3/lib/python3.11/site-packages/ipykernel/kernelbase.py:1251\u001b[0m, in \u001b[0;36mKernel.raw_input\u001b[0;34m(self, prompt)\u001b[0m\n\u001b[1;32m 1249\u001b[0m msg \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mraw_input was called, but this frontend does not support input requests.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 1250\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m StdinNotImplementedError(msg)\n\u001b[0;32m-> 1251\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_input_request\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1252\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mprompt\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1253\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_parent_ident\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mshell\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1254\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_parent\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mshell\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1255\u001b[0m \u001b[43m \u001b[49m\u001b[43mpassword\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m 1256\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/.miniconda3/lib/python3.11/site-packages/ipykernel/kernelbase.py:1295\u001b[0m, in \u001b[0;36mKernel._input_request\u001b[0;34m(self, prompt, ident, parent, password)\u001b[0m\n\u001b[1;32m 1292\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyboardInterrupt\u001b[39;00m:\n\u001b[1;32m 1293\u001b[0m \u001b[38;5;66;03m# re-raise KeyboardInterrupt, to truncate traceback\u001b[39;00m\n\u001b[1;32m 1294\u001b[0m msg \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInterrupted by user\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m-> 1295\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyboardInterrupt\u001b[39;00m(msg) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m 1296\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m:\n\u001b[1;32m 1297\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlog\u001b[38;5;241m.\u001b[39mwarning(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInvalid Message:\u001b[39m\u001b[38;5;124m\"\u001b[39m, exc_info\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n",
"\u001b[0;31mKeyboardInterrupt\u001b[0m: Interrupted by user"
]
}
],
"source": [
"ask_llm()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "52c110e3-a33e-4fe0-b232-3217708435b0",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"[User]> Hey\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"[Llama-3-8B]> I'm here to help you with your queries. Please ask your question or provide more information so I can assist you better. \n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
"[User]> I'm still stuck, I can't connect to my bastion from servers under gateway 52.34.25.12\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"[Llama-3-8B]> diagnostic_infra {\"ip_address\": \"52.34.25.12\"}\n",
"{'ip_address': '52.34.25.12'}\n",
"I apologize for the inconvenience. Based on the updated information, it seems that the server associated with the gateway 52.34.25.12 is shut down and cannot forward any traffic or be contacted. This would explain the issue you're experiencing when trying to connect to the bastion from servers under this gateway.\n",
"\n",
"To resolve this issue, you can follow these steps:\n",
"\n",
"1. Verify the server's status: Confirm if the server associated with the gateway 52.34.25.12 is indeed shut down. If it's not, ensure that it's powered off correctly and not in a maintenance mode or standby state.\n",
"\n",
"2. Check network connectivity: Ensure that there are no network connectivity issues between the servers under the 52.34.25.12 gateway and the bastion host. You can do this by pinging the bastion host from one of the affected servers and checking if the packets are being received.\n",
"\n",
"3. Check firewall rules and security groups: Verify that there are no firewall rules or security group configurations blocking the connection between the servers under the 52.34.25.12 gateway and the bastion host.\n",
"\n",
"4. Verify routing: Ensure that the routing between the servers under the 52.34.25.12 gateway and the bastion host is correct. Check if there are any misconfigured routes or if the default gateway is set up correctly.\n",
"\n",
"5. Check VPN connectivity (if applicable): If the servers under the 52.34.25.12 gateway are connected via a VPN, ensure that the VPN connection is established and functional.\n",
"\n",
"Once you've verified the above, you might need to reach out to your network administrator or cloud provider for further assistance, as they can help with any infrastructure-related issues and ensure that the server associated with the 52.34.25.12 gateway is properly functioning.done\n"
]
}
],
"source": [
"ask_llm(True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "608572b1-7e59-4f69-9eec-31a6c912fd48",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Hugging Face",
"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.11.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment