Skip to content

Commit

Permalink
feat(docs): add json invocation block to groq docs
Browse files Browse the repository at this point in the history
  • Loading branch information
allohamora committed Sep 14, 2024
1 parent 7c6250a commit 20cda2c
Showing 1 changed file with 53 additions and 14 deletions.
67 changes: 53 additions & 14 deletions docs/core_docs/docs/integrations/chat/groq.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,7 @@
" maxTokens: undefined,\n",
" maxRetries: 2,\n",
" // other params...\n",
"})\n",
"\n",
"// if you need a response format other than the default\n",
"const llmWithResponseFormat = llm.bind({ response_format: { type: \"json_object\" } });"
"})"
]
},
{
Expand Down Expand Up @@ -177,6 +174,50 @@
"console.log(aiMsg.content)"
]
},
{
"cell_type": "markdown",
"id": "ce0414fe",
"metadata": {},
"source": [
"## Json invocation"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "3f0a7a2a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\n",
" aiInvokeMsgContent: '{\\n\"result\": 6\\n}',\n",
" aiBindMsg: '{\\n\"result\": 6\\n}'\n",
"}\n"
]
}
],
"source": [
"const messages = [\n",
" [\n",
" \"system\",\n",
" \"You are a math tutor that handles math exercises and makes output in json in format { result: number }.\",\n",
" ],\n",
" [\"human\", \"2 + 2 * 2\"],\n",
"];\n",
"\n",
"const aiInvokeMsg = await llm.invoke(messages, { response_format: { type: \"json_object\" } });\n",
"\n",
"// if you want not to pass response_format in every invoke, you can bind it to the instance\n",
"const llmWithResponseFormat = llm.bind({ response_format: { type: \"json_object\" } });\n",
"const aiBindMsg = await llmWithResponseFormat.invoke(messages);\n",
"\n",
"// they are the same\n",
"console.log({ aiInvokeMsgContent: aiInvokeMsg.content, aiBindMsg: aiBindMsg.content });"
]
},
{
"cell_type": "markdown",
"id": "18e2bfc0-7e78-4528-a73f-499ac150dca8",
Expand All @@ -189,7 +230,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"id": "e197d1d7-a070-4c96-9f8a-a0e86d046e0b",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -250,20 +291,18 @@
],
"metadata": {
"kernelspec": {
"display_name": "TypeScript",
"display_name": "Deno",
"language": "typescript",
"name": "tslab"
"name": "deno"
},
"language_info": {
"codemirror_mode": {
"mode": "typescript",
"name": "javascript",
"typescript": true
},
"codemirror_mode": "typescript",
"file_extension": ".ts",
"mimetype": "text/typescript",
"mimetype": "text/x.typescript",
"name": "typescript",
"version": "3.7.2"
"nbconvert_exporter": "script",
"pygments_lexer": "typescript",
"version": "5.5.2"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 20cda2c

Please sign in to comment.