Skip to content

Commit

Permalink
Add OCI Generative AI tool calling support (#16888)
Browse files Browse the repository at this point in the history
  • Loading branch information
LejianLeoHe7 authored Dec 19, 2024
1 parent fc561a3 commit ff661ea
Show file tree
Hide file tree
Showing 5 changed files with 789 additions and 141 deletions.
59 changes: 50 additions & 9 deletions docs/docs/examples/llm/oci_genai.ipynb
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"id": "6d1ca9ac",
"metadata": {},
"source": [
"<a href=\"https://colab.research.google.com/github/run-llama/llama_index/blob/main/docs/docs/examples/llm/bedrock.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"id": "9e3a8796-edc8-43f2-94ad-fe4fb20d70ed",
Expand Down Expand Up @@ -360,6 +351,56 @@
"resp = llm.chat(messages)\n",
"print(resp)"
]
},
{
"cell_type": "markdown",
"id": "acd73b3d",
"metadata": {},
"source": [
"## Basic tool calling in llamaindex \n",
"\n",
"Only Cohere supports tool calling for now"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5546c661",
"metadata": {},
"outputs": [],
"source": [
"from llama_index.llms.oci_genai import OCIGenAI\n",
"from llama_index.core.tools import FunctionTool\n",
"\n",
"llm = OCIGenAI(\n",
" model=\"MY_MODEL\",\n",
" service_endpoint=\"https://inference.generativeai.us-chicago-1.oci.oraclecloud.com\",\n",
" compartment_id=\"MY_OCID\",\n",
")\n",
"\n",
"\n",
"def multiply(a: int, b: int) -> int:\n",
" \"\"\"Multiple two integers and returns the result integer\"\"\"\n",
" return a * b\n",
"\n",
"\n",
"def add(a: int, b: int) -> int:\n",
" \"\"\"Addition function on two integers.\"\"\"\n",
" return a + b\n",
"\n",
"\n",
"add_tool = FunctionTool.from_defaults(fn=add)\n",
"multiply_tool = FunctionTool.from_defaults(fn=multiply)\n",
"\n",
"response = llm.chat_with_tools(\n",
" tools=[add_tool, multiply_tool],\n",
" user_msg=\"What is 3 * 12? Also, what is 11 + 49?\",\n",
")\n",
"\n",
"print(response)\n",
"tool_calls = response.message.additional_kwargs.get(\"tool_calls\", [])\n",
"print(tool_calls)"
]
}
],
"metadata": {
Expand Down
Loading

0 comments on commit ff661ea

Please sign in to comment.