Skip to content

Commit e143fbd

Browse files
Merge pull request #15 from kingjulio8238/add-reranking
[FEAT] reranking base code
2 parents 13efee5 + 060c833 commit e143fbd

36 files changed

Lines changed: 898 additions & 5419 deletions

dev/routing_agent/memARy_tools/get_location.ipynb renamed to dev/legacy_routing_agent/get_location.ipynb

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,18 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 2,
5+
"execution_count": null,
66
"metadata": {},
7-
"outputs": [
8-
{
9-
"name": "stdout",
10-
"output_type": "stream",
11-
"text": [
12-
"Collecting geopy\n",
13-
" Obtaining dependency information for geopy from https://files.pythonhosted.org/packages/e5/15/cf2a69ade4b194aa524ac75112d5caac37414b20a3a03e6865dfe0bd1539/geopy-2.4.1-py3-none-any.whl.metadata\n",
14-
" Downloading geopy-2.4.1-py3-none-any.whl.metadata (6.8 kB)\n",
15-
"Collecting geographiclib<3,>=1.52 (from geopy)\n",
16-
" 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",
17-
" Downloading geographiclib-2.0-py3-none-any.whl.metadata (1.4 kB)\n",
18-
"Downloading geopy-2.4.1-py3-none-any.whl (125 kB)\n",
19-
" ---------------------------------------- 0.0/125.4 kB ? eta -:--:--\n",
20-
" --- ------------------------------------ 10.2/125.4 kB ? eta -:--:--\n",
21-
" ------ -------------------------------- 20.5/125.4 kB 330.3 kB/s eta 0:00:01\n",
22-
" ------------ -------------------------- 41.0/125.4 kB 393.8 kB/s eta 0:00:01\n",
23-
" -------------------------------------- 125.4/125.4 kB 921.6 kB/s eta 0:00:00\n",
24-
"Downloading geographiclib-2.0-py3-none-any.whl (40 kB)\n",
25-
" ---------------------------------------- 0.0/40.3 kB ? eta -:--:--\n",
26-
" ---------------------------------------- 40.3/40.3 kB 1.9 MB/s eta 0:00:00\n",
27-
"Installing collected packages: geographiclib, geopy\n",
28-
"Successfully installed geographiclib-2.0 geopy-2.4.1\n",
29-
"Note: you may need to restart the kernel to use updated packages.\n"
30-
]
31-
}
32-
],
7+
"outputs": [],
338
"source": [
349
"%pip install geopy"
3510
]
3611
},
3712
{
3813
"cell_type": "code",
39-
"execution_count": 4,
14+
"execution_count": null,
4015
"metadata": {},
41-
"outputs": [
42-
{
43-
"name": "stdout",
44-
"output_type": "stream",
45-
"text": [
46-
"An error occurred: Non-successful status code 403\n"
47-
]
48-
}
49-
],
16+
"outputs": [],
5017
"source": [
5118
"import requests\n",
5219
"from geopy.geocoders import Nominatim\n",
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# *This is the old routing agent implementation.* Current implementation of the routing agent can be found in src/agent/base_agent.py
2+
13
Llama Index Tool Specification Example Usage
24
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.
35

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"%pip install pydantic\n",
10+
"%pip install googlemaps"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": null,
16+
"metadata": {},
17+
"outputs": [],
18+
"source": [
19+
"from main import handle_location_question, handle_vision_question, app"
20+
]
21+
},
22+
{
23+
"cell_type": "code",
24+
"execution_count": null,
25+
"metadata": {},
26+
"outputs": [],
27+
"source": [
28+
"%pip install llama_index"
29+
]
30+
},
31+
{
32+
"cell_type": "code",
33+
"execution_count": null,
34+
"metadata": {},
35+
"outputs": [],
36+
"source": [
37+
"# from llama_index.agent.openai import OpenAIAgent\n",
38+
"from llama_index.core.tools.tool_spec.base import BaseToolSpec"
39+
]
40+
},
41+
{
42+
"cell_type": "code",
43+
"execution_count": null,
44+
"metadata": {},
45+
"outputs": [],
46+
"source": [
47+
"class CVToolSpec(BaseToolSpec):\n",
48+
" spec_functions = ['handle_vision_question']\n",
49+
"\n",
50+
" def __init__(self): #, form):\n",
51+
" # self.form = form\n",
52+
" ''''''\n",
53+
"\n",
54+
" def handle_vision_question(request):\n",
55+
" return handle_vision_question(request)"
56+
]
57+
},
58+
{
59+
"cell_type": "code",
60+
"execution_count": null,
61+
"metadata": {},
62+
"outputs": [],
63+
"source": [
64+
"cv_tool = CVToolSpec()\n",
65+
"cv_tool_list = cv_tool.to_tool_list()"
66+
]
67+
},
68+
{
69+
"cell_type": "code",
70+
"execution_count": null,
71+
"metadata": {},
72+
"outputs": [],
73+
"source": [
74+
"class LocationToolSpec(BaseToolSpec):\n",
75+
" spec_functions = ['handle_location_question']\n",
76+
"\n",
77+
" def __init__(self): #, form):\n",
78+
" # self.form = form\n",
79+
" ''''''\n",
80+
"\n",
81+
" def handle_location_question(request): \n",
82+
" return handle_location_question(request)\n",
83+
" "
84+
]
85+
},
86+
{
87+
"cell_type": "code",
88+
"execution_count": null,
89+
"metadata": {},
90+
"outputs": [],
91+
"source": [
92+
"from flask import request \n",
93+
"\n",
94+
"# form_data = request.form\n",
95+
"\n",
96+
"loc_tool = LocationToolSpec()\n",
97+
"loc_tool_list = loc_tool.to_tool_list(['handle_location_question'])"
98+
]
99+
},
100+
{
101+
"cell_type": "code",
102+
"execution_count": null,
103+
"metadata": {},
104+
"outputs": [],
105+
"source": [
106+
"# from {KG repo} import {KG query method}"
107+
]
108+
},
109+
{
110+
"cell_type": "code",
111+
"execution_count": null,
112+
"metadata": {},
113+
"outputs": [],
114+
"source": [
115+
"class SearchToolSpec(BaseToolSpec):\n",
116+
" spec_functions = ['']\n",
117+
"\n",
118+
" def __init__(self):\n",
119+
" ''''''\n",
120+
"\n",
121+
" def handle_search_request(request):\n",
122+
" return handle_search_request(request)"
123+
]
124+
},
125+
{
126+
"cell_type": "markdown",
127+
"metadata": {},
128+
"source": [
129+
"### Experiment with making Agents from Tools"
130+
]
131+
},
132+
{
133+
"cell_type": "code",
134+
"execution_count": null,
135+
"metadata": {},
136+
"outputs": [],
137+
"source": [
138+
"from llama_index.agent.openai import OpenAIAgent\n",
139+
"from llama_index.llms.openai import OpenAI\n",
140+
"\n",
141+
"full_tool_list = cv_tool.to_tool_list() + loc_tool.to_tool_list()\n",
142+
"llm = OpenAI(model=\"gpt-3.5-turbo\")\n",
143+
"agent = OpenAIAgent.from_tools(full_tool_list, verbose=True)"
144+
]
145+
}
146+
],
147+
"metadata": {
148+
"kernelspec": {
149+
"display_name": "base",
150+
"language": "python",
151+
"name": "python3"
152+
},
153+
"language_info": {
154+
"codemirror_mode": {
155+
"name": "ipython",
156+
"version": 3
157+
},
158+
"file_extension": ".py",
159+
"mimetype": "text/x-python",
160+
"name": "python",
161+
"nbconvert_exporter": "python",
162+
"pygments_lexer": "ipython3",
163+
"version": "3.11.5"
164+
}
165+
},
166+
"nbformat": 4,
167+
"nbformat_minor": 2
168+
}

0 commit comments

Comments
 (0)