Skip to content

Commit

Permalink
Merge pull request #1173 from guardrails-ai/llama-index-doc-tweak
Browse files Browse the repository at this point in the history
LlamaIndex Example FnF
  • Loading branch information
zsimjee authored Dec 5, 2024
2 parents 5652e0f + e123c28 commit 7f56993
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
40 changes: 22 additions & 18 deletions docs/integrations/llama_index.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 3,
"metadata": {},
"outputs": [
{
Expand All @@ -50,15 +50,14 @@
"\n",
"\n",
"Installing hub:\u001b[35m/\u001b[0m\u001b[35m/guardrails/\u001b[0m\u001b[95mcompetitor_check...\u001b[0m\n",
"✅Successfully installed guardrails/competitor_check version \u001b[1;36m0.0\u001b[0m.\u001b[1;36m1\u001b[0m!\n",
"✅Successfully installed guardrails/competitor_check!\n",
"\n",
"\n"
]
}
],
"source": [
"! guardrails hub install hub://guardrails/detect_pii --no-install-local-models -q\n",
"! guardrails hub install hub://guardrails/competitor_check --no-install-local-models -q"
"! guardrails hub install hub://guardrails/detect_pii hub://guardrails/competitor_check --no-install-local-models -q"
]
},
{
Expand All @@ -70,7 +69,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 4,
"metadata": {},
"outputs": [
{
Expand All @@ -79,7 +78,7 @@
"text": [
" % Total % Received % Xferd Average Speed Time Time Time Current\n",
" Dload Upload Total Spent Left Speed\n",
"100 75042 100 75042 0 0 959k 0 --:--:-- --:--:-- --:--:-- 964k\n"
"100 75042 100 75042 0 0 353k 0 --:--:-- --:--:-- --:--:-- 354k\n"
]
}
],
Expand All @@ -99,7 +98,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -136,7 +135,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -148,7 +147,12 @@
" competitors=[\"Fortran\", \"Ada\", \"Pascal\"],\n",
" on_fail=\"fix\"\n",
" )\n",
").use(DetectPII(pii_entities=\"pii\", on_fail=\"fix\"))"
").use(\n",
" DetectPII(\n",
" pii_entities=[\"PERSON\", \"EMAIL_ADDRESS\"], \n",
" on_fail=\"fix\"\n",
" )\n",
")"
]
},
{
Expand All @@ -162,21 +166,21 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The author worked on writing short stories and programming, starting with early attempts on an IBM 1401 using Fortran in 9th grade, and later transitioning to microcomputers like the TRS-80 and Apple II to write games, rocket prediction programs, and a word processor.\n"
"The author is Paul Graham. Growing up, he worked on writing short stories and programming, starting with the IBM 1401 in 9th grade using an early version of Fortran. Later, he transitioned to microcomputers like the TRS-80 and began programming more extensively, creating simple games and a word processor.\n"
]
}
],
"source": [
"# Use index on it's own\n",
"query_engine = index.as_query_engine()\n",
"response = query_engine.query(\"What did the author do growing up?\")\n",
"response = query_engine.query(\"Who is the author and what did they do growing up?\")\n",
"print(response)"
]
},
Expand All @@ -189,14 +193,14 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The author worked on writing short stories and programming, starting with early attempts on an IBM 1401 using [COMPETITOR] in 9th <URL>er, the author transitioned to microcomputers, building a Heathkit kit and eventually getting a TRS-80 to write simple games and <URL>spite enjoying programming, the author initially planned to study philosophy in college but eventually switched to AI due to a lack of interest in philosophy courses.\n"
"The author is <PERSON>. Growing up, he worked on writing short stories and programming, starting with the IBM 1401 in 9th grade using an early version of [COMPETITOR]. Later, he transitioned to microcomputers like the TRS-80 and Apple II, where he wrote simple games, programs, and a word processor. \n"
]
}
],
Expand All @@ -206,7 +210,7 @@
"\n",
"guardrails_query_engine = GuardrailsQueryEngine(engine=query_engine, guard=guard)\n",
"\n",
"response = guardrails_query_engine.query(\"What did the author do growing up?\")\n",
"response = guardrails_query_engine.query(\"Who is the author and what did they do growing up?\")\n",
"print(response)\n",
" "
]
Expand All @@ -220,14 +224,14 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The author worked on writing short stories and programming while growing <URL>ey started with early attempts on an IBM 1401 using [COMPETITOR] in 9th <URL>er, they transitioned to microcomputers, building simple games and a word processor on a TRS-80 in <DATE_TIME>.\n"
"The author is <PERSON>. Growing up, he worked on writing short stories and programming. He started with early attempts on an IBM 1401 using [COMPETITOR] in 9th grade. Later, he transitioned to microcomputers, building a Heathkit kit and eventually getting a TRS-80 to write simple games and programs. Despite enjoying programming, he initially planned to study philosophy in college but eventually switched to AI due to a lack of interest in philosophy courses. \n"
]
}
],
Expand All @@ -237,7 +241,7 @@
"chat_engine = index.as_chat_engine()\n",
"guardrails_chat_engine = GuardrailsChatEngine(engine=chat_engine, guard=guard)\n",
"\n",
"response = guardrails_chat_engine.chat(\"Tell me what the author did growing up.\")\n",
"response = guardrails_chat_engine.chat(\"Tell me who the author is and what they did growing up.\")\n",
"print(response)"
]
}
Expand Down
1 change: 1 addition & 0 deletions docusaurus/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ const sidebars = {
integrations: [
// "integrations/azure_openai",
"integrations/langchain",
"integrations/llama_index",
{
type: "category",
label: "Telemetry",
Expand Down

0 comments on commit 7f56993

Please sign in to comment.