Skip to content

Commit

Permalink
Merge pull request #15 from kingjulio8238/add-reranking
Browse files Browse the repository at this point in the history
[FEAT] reranking base code
  • Loading branch information
aishwarya-balaji authored May 1, 2024
2 parents 13efee5 + 060c833 commit e143fbd
Show file tree
Hide file tree
Showing 36 changed files with 898 additions and 5,419 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,18 @@
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Collecting geopy\n",
" Obtaining dependency information for geopy from https://files.pythonhosted.org/packages/e5/15/cf2a69ade4b194aa524ac75112d5caac37414b20a3a03e6865dfe0bd1539/geopy-2.4.1-py3-none-any.whl.metadata\n",
" Downloading geopy-2.4.1-py3-none-any.whl.metadata (6.8 kB)\n",
"Collecting geographiclib<3,>=1.52 (from geopy)\n",
" Obtaining dependency information for geographiclib<3,>=1.52 from https://files.pythonhosted.org/packages/9f/5a/a26132406f1f40cf51ea349a5f11b0a46cec02a2031ff82e391c2537247a/geographiclib-2.0-py3-none-any.whl.metadata\n",
" Downloading geographiclib-2.0-py3-none-any.whl.metadata (1.4 kB)\n",
"Downloading geopy-2.4.1-py3-none-any.whl (125 kB)\n",
" ---------------------------------------- 0.0/125.4 kB ? eta -:--:--\n",
" --- ------------------------------------ 10.2/125.4 kB ? eta -:--:--\n",
" ------ -------------------------------- 20.5/125.4 kB 330.3 kB/s eta 0:00:01\n",
" ------------ -------------------------- 41.0/125.4 kB 393.8 kB/s eta 0:00:01\n",
" -------------------------------------- 125.4/125.4 kB 921.6 kB/s eta 0:00:00\n",
"Downloading geographiclib-2.0-py3-none-any.whl (40 kB)\n",
" ---------------------------------------- 0.0/40.3 kB ? eta -:--:--\n",
" ---------------------------------------- 40.3/40.3 kB 1.9 MB/s eta 0:00:00\n",
"Installing collected packages: geographiclib, geopy\n",
"Successfully installed geographiclib-2.0 geopy-2.4.1\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"outputs": [],
"source": [
"%pip install geopy"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"An error occurred: Non-successful status code 403\n"
]
}
],
"outputs": [],
"source": [
"import requests\n",
"from geopy.geocoders import Nominatim\n",
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# *This is the old routing agent implementation.* Current implementation of the routing agent can be found in src/agent/base_agent.py

Llama Index Tool Specification Example Usage
This document provides an overview of how to utilize custom tool specifications with the Llama Index framework to handle specialized tasks like vision and location-based queries.

Expand Down
168 changes: 168 additions & 0 deletions dev/legacy_routing_agent/tool_spec.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%pip install pydantic\n",
"%pip install googlemaps"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from main import handle_location_question, handle_vision_question, app"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%pip install llama_index"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# from llama_index.agent.openai import OpenAIAgent\n",
"from llama_index.core.tools.tool_spec.base import BaseToolSpec"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class CVToolSpec(BaseToolSpec):\n",
" spec_functions = ['handle_vision_question']\n",
"\n",
" def __init__(self): #, form):\n",
" # self.form = form\n",
" ''''''\n",
"\n",
" def handle_vision_question(request):\n",
" return handle_vision_question(request)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"cv_tool = CVToolSpec()\n",
"cv_tool_list = cv_tool.to_tool_list()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class LocationToolSpec(BaseToolSpec):\n",
" spec_functions = ['handle_location_question']\n",
"\n",
" def __init__(self): #, form):\n",
" # self.form = form\n",
" ''''''\n",
"\n",
" def handle_location_question(request): \n",
" return handle_location_question(request)\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from flask import request \n",
"\n",
"# form_data = request.form\n",
"\n",
"loc_tool = LocationToolSpec()\n",
"loc_tool_list = loc_tool.to_tool_list(['handle_location_question'])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# from {KG repo} import {KG query method}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class SearchToolSpec(BaseToolSpec):\n",
" spec_functions = ['']\n",
"\n",
" def __init__(self):\n",
" ''''''\n",
"\n",
" def handle_search_request(request):\n",
" return handle_search_request(request)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Experiment with making Agents from Tools"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from llama_index.agent.openai import OpenAIAgent\n",
"from llama_index.llms.openai import OpenAI\n",
"\n",
"full_tool_list = cv_tool.to_tool_list() + loc_tool.to_tool_list()\n",
"llm = OpenAI(model=\"gpt-3.5-turbo\")\n",
"agent = OpenAIAgent.from_tools(full_tool_list, verbose=True)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
File renamed without changes.
Loading

0 comments on commit e143fbd

Please sign in to comment.