Skip to content

Commit d5dd5af

Browse files
committed
AI should always search for n results (n determing by env setting) and pick the best 1 or 2
1 parent 39c6e1a commit d5dd5af

File tree

8 files changed

+65
-34
lines changed

8 files changed

+65
-34
lines changed

ai_chat/agents.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -142,31 +142,33 @@ class SearchAgentService(BaseChatAgentService):
142142
TASK_NAME = "SEARCH_TASK"
143143

144144
INSTRUCTIONS = f"""You are a helpful MIT learning resource recommendation
145-
assistant. Use the provided tool to search the MIT catalog and provide relevant
146-
recommendations based on the user's message. If the user asks subsequent questions
147-
about those results, answer using the information provided in that response.
145+
assistant. Use the provided tool to search the MIT catalog for results then
146+
recommend the best 1 or 2 based on the user's message. Make the title of the
147+
resource a clickable link to the resource's URL. If the user asks subsequent
148+
questions about those results, answer using the information provided in that
149+
response.
148150
149-
Always run the tool to answer questions only based on the function search results.
150-
VERY IMPORTANT: NEVER USE ANY INFORMATION OUTSIDE OF THE FUNCTION RESULTS TO
151-
ANSWER QUESTIONS.
151+
Always run the tool to answer questions only based on the function search results.
152+
VERY IMPORTANT: NEVER USE ANY INFORMATION OUTSIDE OF THE FUNCTION RESULTS TO
153+
ANSWER QUESTIONS.
152154
153-
If a user asks for resources "offered by" or "from" an institution,
154-
you should include the offered_by parameter based on the following
155-
dictionary: {OfferedBy.as_dict()} DO NOT USE THE offered_by FILTER OTHERWISE.
155+
If a user asks for resources "offered by" or "from" an institution,
156+
you should include the offered_by parameter based on the following
157+
dictionary: {OfferedBy.as_dict()} DO NOT USE THE offered_by FILTER OTHERWISE.
156158
157-
If the user mentions courses, programs, videos, or podcasts in particular, filter
158-
the search by resource_category. DO NOT USE THE resource_type FILTER OTHERWISE.
159+
If the user mentions courses, programs, videos, or podcasts in particular, filter
160+
the search by resource_category. DO NOT USE THE resource_type FILTER OTHERWISE.
159161
160-
If the user asks what other courses are taught by a particular instructor,
161-
search the catalog for courses taught by that instructor.
162+
If the user asks what other courses are taught by a particular instructor,
163+
search the catalog for courses taught by that instructor.
162164
163-
If the user asks for introductory, intermediate, or advanced courses,
164-
use the level filter. DO NOT USE THE level FILTER OTHERWISE.
165+
If the user asks for introductory, intermediate, or advanced courses,
166+
use the level filter. DO NOT USE THE level FILTER OTHERWISE.
165167
166-
Do not use the certificate filer unless the user specifically asks for
167-
resources that do or do not offer certificates.
168+
Do not use the certificate filer unless the user specifically asks for
169+
resources that do or do not offer certificates.
168170
169-
Always explain your reasoning for recommending specific resources.
171+
Always explain your reasoning for recommending specific resources.
170172
"""
171173

172174
class SearchToolSchema(pydantic.BaseModel):
@@ -178,7 +180,6 @@ class SearchToolSchema(pydantic.BaseModel):
178180
free: Optional[bool]
179181
certificate: Optional[bool]
180182
offered_by: Optional[enum_zip("offered_by", OfferedBy.names())]
181-
limit: Optional[int]
182183

183184
def __init__( # noqa: PLR0913
184185
self,
@@ -213,14 +214,13 @@ def search_courses(self, q: str, **kwargs) -> str:
213214
return simplified results as a JSON string
214215
"""
215216

216-
params = {"q": q}
217+
params = {"q": q, "limit": settings.AI_MIT_SEARCH_LIMIT}
217218

218219
valid_params = {
219220
"level": kwargs.get("level"),
220221
"resource_type": kwargs.get("resource_type"),
221222
"free": kwargs.get("free"),
222223
"offered_by": kwargs.get("offered_by"),
223-
"limit": kwargs.get("limit"),
224224
"certificate": kwargs.get("certificate"),
225225
}
226226
params.update({k: v for k, v in valid_params.items() if v is not None})

ai_chat/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
log = logging.getLogger(__name__)
77

88

9-
def enum_zip(label: str, names: tuple[str]) -> type[Enum]:
9+
def enum_zip(label: str, names: tuple[str or int]) -> type[Enum]:
1010
"""Create a new enum from a tuple"""
1111
return Enum(label, dict(zip(names, names)))

app.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,46 @@
3535
"description": "The API used for the AI model",
3636
"required": false
3737
},
38+
"AI_PROXY_CLASS": {
39+
"description": "Proxy class for AI functionality",
40+
"required": false
41+
},
42+
"AI_PROXY_URL": {
43+
"description": "URL for AI proxy",
44+
"required": false
45+
},
46+
"AI_PROXY_AUTH_TOKEN": {
47+
"description": "Auth token for AI proxy",
48+
"required": false
49+
},
50+
"AI_MAX_PARALLEL_REQUESTS": {
51+
"description": "Max parallel requests/user for AI functionality",
52+
"required": false
53+
},
54+
"AI_TPM_LIMIT": {
55+
"description": "Tokens/minute limit per user for AI functionality",
56+
"required": false
57+
},
58+
"AI_RPM_LIMIT": {
59+
"description": "Requests/minute limit per user for AI functionality",
60+
"required": false
61+
},
62+
"AI_BUDGET_DURATION": {
63+
"description": "Length of time before a user's budget usage resets",
64+
"required": false
65+
},
66+
"AI_MAX_BUDGET": {
67+
"description": "Max budget per user for AI functionality",
68+
"required": false
69+
},
70+
"AI_ANON_LIMIT_MULTIPLIER": {
71+
"description": "Multiplier for per-user limit/budget shared by anonymous users",
72+
"required": false
73+
},
74+
"AI_MIT_SEARCH_LIMIT": {
75+
"description": "Limit parameter value for AI search agent",
76+
"required": false
77+
},
3878
"ALLOWED_HOSTS": {
3979
"description": "",
4080
"required": false

frontends/api/src/generated/v0/api.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -528,12 +528,6 @@ export interface ChatRequestRequest {
528528
* @memberof ChatRequestRequest
529529
*/
530530
message: string
531-
/**
532-
*
533-
* @type {string}
534-
* @memberof ChatRequestRequest
535-
*/
536-
ai?: string
537531
/**
538532
*
539533
* @type {string}

frontends/api/src/generated/v0/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export const createRequestFunction = function (
194194
const axiosRequestArgs = {
195195
...axiosArgs.options,
196196
url:
197-
(axios.defaults.baseURL ? "" : (configuration?.basePath ?? basePath)) +
197+
(axios.defaults.baseURL ? "" : configuration?.basePath ?? basePath) +
198198
axiosArgs.url,
199199
}
200200
return axios.request<T, R>(axiosRequestArgs)

frontends/api/src/generated/v1/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export const createRequestFunction = function (
194194
const axiosRequestArgs = {
195195
...axiosArgs.options,
196196
url:
197-
(axios.defaults.baseURL ? "" : (configuration?.basePath ?? basePath)) +
197+
(axios.defaults.baseURL ? "" : configuration?.basePath ?? basePath) +
198198
axiosArgs.url,
199199
}
200200
return axios.request<T, R>(axiosRequestArgs)

main/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,3 +828,4 @@ def get_all_config_keys():
828828
AI_BUDGET_DURATION = get_string(name="AI_BUDGET_DURATION", default="60m")
829829
AI_MAX_BUDGET = get_float(name="AI_MAX_BUDGET", default=0.05)
830830
AI_ANON_LIMIT_MULTIPLIER = get_float(name="AI_ANON_LIMIT_MULTIPLIER", default=10.0)
831+
AI_MIT_SEARCH_LIMIT = get_int(name="AI_MIT_SEARCH_LIMIT", default=10)

openapi/specs/v0.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,10 +1278,6 @@ components:
12781278
message:
12791279
type: string
12801280
minLength: 1
1281-
ai:
1282-
type: string
1283-
minLength: 1
1284-
default: openai
12851281
model:
12861282
type: string
12871283
minLength: 1

0 commit comments

Comments
 (0)