Skip to content

Commit

Permalink
Merge pull request MSUSAzureAccelerators#77 from MSUSAzureAccelerator…
Browse files Browse the repository at this point in the history
…s/main

sync with MSUS repo
  • Loading branch information
pablomarin authored Mar 7, 2024
2 parents 067da0b + e27d53b commit 55ce3fc
Show file tree
Hide file tree
Showing 10 changed files with 431 additions and 289 deletions.
76 changes: 45 additions & 31 deletions 10-API-Search.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"id": "c1fb79a3-4856-4721-988c-112813690a90",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -64,7 +64,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 2,
"id": "258a6e99-2d4f-4147-b8ee-c64c85296181",
"metadata": {},
"outputs": [],
Expand All @@ -75,7 +75,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"id": "9d3daf03-77e2-466e-a255-2f06bee3561b",
"metadata": {},
"outputs": [],
Expand All @@ -85,6 +85,8 @@
"\n",
"COMPLETION_TOKENS = 2000\n",
"\n",
"\n",
"# This notebook needs GPT-4-Turbo (context size of 128k tokens)\n",
"llm = AzureChatOpenAI(deployment_name=os.environ[\"GPT4_DEPLOYMENT_NAME\"], \n",
" temperature=0.5, max_tokens=COMPLETION_TOKENS, \n",
" streaming=True, callback_manager=cb_manager)"
Expand Down Expand Up @@ -137,7 +139,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 4,
"id": "8efd8698-aea1-4de3-b810-e9c4782f04c4",
"metadata": {},
"outputs": [],
Expand All @@ -163,7 +165,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 5,
"id": "94503afc-c398-458a-b369-610c5dbe682d",
"metadata": {},
"outputs": [],
Expand All @@ -174,7 +176,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 6,
"id": "57d77e9b-6f3f-4ec4-bc01-baac18984937",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -202,6 +204,14 @@
"Sometimes it makes sense to reduce the size of the API Specs by using the `reduce_openapi_spec` function. It's optional."
]
},
{
"cell_type": "markdown",
"id": "cd8c3b3e-959e-4b19-b34d-66de3501b1b1",
"metadata": {},
"source": [
"#### NOTE: As you can see, a large context LLM is needed. `GPT4-turbo` is necessary for this notebook to run succesfully."
]
},
{
"cell_type": "markdown",
"id": "9a945386-39eb-405d-9310-3b67c9af77bb",
Expand All @@ -213,7 +223,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 7,
"id": "d020b5de-7ebe-4fb9-9b71-f6c71956149d",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -242,7 +252,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 8,
"id": "96731b5f-988b-49ec-a5c3-3a344b7085da",
"metadata": {},
"outputs": [],
Expand All @@ -253,17 +263,9 @@
"requests_wrapper = RequestsWrapper(headers=headers)"
]
},
{
"cell_type": "markdown",
"id": "1fd6a140-f675-40db-98ad-b5c955a4f7b6",
"metadata": {},
"source": [
"**Note**: Notice that we are using GPT-3.5 (llm_2) below for this chain since it doesn't need too many instructions or reasoning"
]
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 9,
"id": "426fab6f-ea04-4c07-8211-d9cc5c70ac8e",
"metadata": {},
"outputs": [],
Expand All @@ -283,12 +285,12 @@
"id": "1707e590-809b-4391-bdcd-c7d285ec8fb1",
"metadata": {},
"source": [
"These are the prompts on the APIChain class (on to create the URL endpoint and the other one to use it and get the answer):"
"These are the prompts on the APIChain class (one to create the URL endpoint and the other one to use it and get the answer):"
]
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 10,
"id": "9f80d2bb-e285-4d30-88c8-5677e86cebe2",
"metadata": {},
"outputs": [
Expand All @@ -298,7 +300,7 @@
"'You are given the below API Documentation:\\n{api_docs}\\nUsing this documentation, generate the full API url to call for answering the user question.\\nYou should build the API url in order to get a response that is as short as possible, while still getting the necessary information to answer the question. Pay attention to deliberately exclude any unnecessary pieces of data in the API call.\\n\\nQuestion:{question}\\nAPI url:'"
]
},
"execution_count": 15,
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -309,7 +311,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 11,
"id": "ccc7e9dc-f36b-45e1-867a-1b92d639e941",
"metadata": {},
"outputs": [
Expand All @@ -319,7 +321,7 @@
"'You are given the below API Documentation:\\n{api_docs}\\nUsing this documentation, generate the full API url to call for answering the user question.\\nYou should build the API url in order to get a response that is as short as possible, while still getting the necessary information to answer the question. Pay attention to deliberately exclude any unnecessary pieces of data in the API call.\\n\\nQuestion:{question}\\nAPI url: {api_url}\\n\\nHere is the response from the API:\\n\\n{api_response}\\n\\nSummarize this response to answer the original question.\\n\\nSummary:'"
]
},
"execution_count": 16,
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -330,26 +332,38 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 12,
"id": "d7f60335-5551-4ee0-ba4e-1cd84f3a9f48",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"To answer the user's question, we need to make three separate API calls to get the price of Bitcoin against USD, the latest OHLC values for Ethereum, and the bid and ask for Euro. Here are the API URLs for the required information:\n",
"To get the price of Bitcoin against USD, we will use the `Ticker` endpoint. The `pair` parameter should specify `XXBTZUSD` which is the pair for Bitcoin against USD.\n",
"\n",
"For the latest OHLC values for Ethereum, we will use the `OHLC` endpoint. The `pair` parameter should specify `XETHZUSD` which is the pair for Ethereum against USD.\n",
"\n",
"1. Price of Bitcoin against USD:\n",
" `GET https://api.kraken.com/0/public/Ticker?pair=XBTUSD`\n",
"For the bid and ask for Euro, we will use the `Ticker` endpoint again. The `pair` parameter should specify `ZEURZUSD` which is the pair for Euro against USD.\n",
"\n",
"2. Latest OHLC values for Ethereum:\n",
" `GET https://api.kraken.com/0/public/OHLC?pair=ETHUSD`\n",
"Since we want to make the response as short as possible, we will only include the necessary pairs in the `pair` parameter for each call.\n",
"\n",
"3. Bid and ask for Euro:\n",
" `GET https://api.kraken.com/0/public/Ticker?pair=EURUSD`\n",
"API url for Bitcoin price against USD (Ticker):\n",
"```\n",
"https://api.kraken.com/0/public/Ticker?pair=XXBTZUSD\n",
"```\n",
"\n",
"API url for the latest OHLC values for Ethereum (OHLC):\n",
"```\n",
"https://api.kraken.com/0/public/OHLC?pair=XETHZUSD&interval=1\n",
"```\n",
"\n",
"API url for the bid and ask for Euro (Ticker):\n",
"```\n",
"https://api.kraken.com/0/public/Ticker?pair=ZEURZUSD\n",
"```\n",
"\n",
"Please note that the pair names (`XBTUSD`, `ETHUSD`, and `EURUSD`) are based on the common naming convention used by Kraken and may need to be adjusted if Kraken uses different identifiers for these pairs."
"Please note that these URLs should be used with a `GET` request."
]
}
],
Expand Down
Loading

0 comments on commit 55ce3fc

Please sign in to comment.