Skip to content

Commit

Permalink
add json_mode example in notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
raspawar committed Oct 25, 2024
1 parent ed2a69a commit 60c5e6a
Showing 1 changed file with 45 additions and 3 deletions.
48 changes: 45 additions & 3 deletions libs/ai-endpoints/docs/chat/nvidia_ai_endpoints.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "686c4d2f",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -814,6 +814,48 @@
"response"
]
},
{
"cell_type": "markdown",
"id": "b5476b50",
"metadata": {},
"source": [
"### JSON Schema"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6fb3e5cb",
"metadata": {},
"outputs": [],
"source": [
"json_schema = {\n",
" \"title\": \"joke\",\n",
" \"description\": \"Joke to tell user.\",\n",
" \"type\": \"object\",\n",
" \"properties\": {\n",
" \"setup\": {\n",
" \"type\": \"string\",\n",
" \"description\": \"The setup of the joke\",\n",
" },\n",
" \"punchline\": {\n",
" \"type\": \"string\",\n",
" \"description\": \"The punchline to the joke\",\n",
" },\n",
" \"rating\": {\n",
" \"type\": \"integer\",\n",
" \"description\": \"How funny the joke is, from 1 to 10\",\n",
" \"default\": None,\n",
" },\n",
" },\n",
" \"required\": [\"setup\", \"punchline\"],\n",
"}\n",
"llm = ChatNVIDIA(model=structured_models[0].id)\n",
"structured_llm = llm.with_structured_output(json_schema)\n",
"\n",
"structured_llm.invoke(\"Tell me a joke about cats\")"
]
},
{
"cell_type": "markdown",
"id": "c8893046",
Expand Down Expand Up @@ -870,7 +912,7 @@
"provenance": []
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": ".venv",
"language": "python",
"name": "python3"
},
Expand All @@ -884,7 +926,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 60c5e6a

Please sign in to comment.