Resolve error in StructuredOutputParser docs (#5240)

# Resolve error in StructuredOutputParser docs

Documentation for `StructuredOutputParser` currently not reproducible,
that is, `output_parser.parse(output)` raises an error because the LLM
returns a response with an invalid format

```python
_input = prompt.format_prompt(question="what's the capital of france")
output = model(_input.to_string())

output

# ?
#
# ```json
# {
# 	"answer": "Paris",
# 	"source": "https://www.worldatlas.com/articles/what-is-the-capital-of-france.html"
# }
# ```
```

Was fixed by adding a question mark to the prompt
This commit is contained in:
mwinterde 2023-05-25 16:47:25 +02:00 committed by GitHub
parent c7e2151a4b
commit 9c0cb90997
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,7 @@
{ {
"cells": [ "cells": [
{ {
"attachments": {},
"cell_type": "markdown", "cell_type": "markdown",
"id": "91871002", "id": "91871002",
"metadata": {}, "metadata": {},
@ -12,7 +13,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 23,
"id": "b492997a", "id": "b492997a",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -24,6 +25,7 @@
] ]
}, },
{ {
"attachments": {},
"cell_type": "markdown", "cell_type": "markdown",
"id": "09473dce", "id": "09473dce",
"metadata": {}, "metadata": {},
@ -33,7 +35,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 24,
"id": "432ac44a", "id": "432ac44a",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -46,6 +48,7 @@
] ]
}, },
{ {
"attachments": {},
"cell_type": "markdown", "cell_type": "markdown",
"id": "7b92ce96", "id": "7b92ce96",
"metadata": {}, "metadata": {},
@ -55,7 +58,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 25,
"id": "593cfc25", "id": "593cfc25",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -69,6 +72,7 @@
] ]
}, },
{ {
"attachments": {},
"cell_type": "markdown", "cell_type": "markdown",
"id": "0943e783", "id": "0943e783",
"metadata": {}, "metadata": {},
@ -78,7 +82,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": 26,
"id": "106f1ba6", "id": "106f1ba6",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -88,28 +92,29 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7, "execution_count": 27,
"id": "86d9d24f", "id": "86d9d24f",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"_input = prompt.format_prompt(question=\"what's the capital of france\")\n", "_input = prompt.format_prompt(question=\"what's the capital of france?\")\n",
"output = model(_input.to_string())" "output = model(_input.to_string())"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8, "execution_count": 28,
"id": "956bdc99", "id": "956bdc99",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"{'answer': 'Paris', 'source': 'https://en.wikipedia.org/wiki/Paris'}" "{'answer': 'Paris',\n",
" 'source': 'https://www.worldatlas.com/articles/what-is-the-capital-of-france.html'}"
] ]
}, },
"execution_count": 8, "execution_count": 28,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -119,6 +124,7 @@
] ]
}, },
{ {
"attachments": {},
"cell_type": "markdown", "cell_type": "markdown",
"id": "da639285", "id": "da639285",
"metadata": {}, "metadata": {},
@ -128,7 +134,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": 29,
"id": "8f483d7d", "id": "8f483d7d",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -138,7 +144,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10, "execution_count": 30,
"id": "f761cbf1", "id": "f761cbf1",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -154,18 +160,18 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": 31,
"id": "edd73ae3", "id": "edd73ae3",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"_input = prompt.format_prompt(question=\"what's the capital of france\")\n", "_input = prompt.format_prompt(question=\"what's the capital of france?\")\n",
"output = chat_model(_input.to_messages())" "output = chat_model(_input.to_messages())"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12, "execution_count": 32,
"id": "a3c8b91e", "id": "a3c8b91e",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@ -175,7 +181,7 @@
"{'answer': 'Paris', 'source': 'https://en.wikipedia.org/wiki/Paris'}" "{'answer': 'Paris', 'source': 'https://en.wikipedia.org/wiki/Paris'}"
] ]
}, },
"execution_count": 12, "execution_count": 32,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -201,7 +207,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.9.1" "version": "3.10.11"
} }
}, },
"nbformat": 4, "nbformat": 4,