Skip to content

Commit 793cf89

Browse files
committed
Improve user prompt and make resource_type a list in the search tool schema
1 parent d5dd5af commit 793cf89

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

ai_chat/agents.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,10 @@ class SearchAgentService(BaseChatAgentService):
157157
dictionary: {OfferedBy.as_dict()} DO NOT USE THE offered_by FILTER OTHERWISE.
158158
159159
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.
160+
the search by resource_type. DO NOT USE THE resource_type FILTER OTHERWISE.
161+
You MUST combine multiple resource types in one request like this:
162+
"resource_type=course&resource_type=program". Do not attempt more than one query per
163+
user message.
161164
162165
If the user asks what other courses are taught by a particular instructor,
163166
search the catalog for courses taught by that instructor.
@@ -175,7 +178,9 @@ class SearchToolSchema(pydantic.BaseModel):
175178
"""Schema for the search_courses function tool"""
176179

177180
q: str
178-
resource_type: Optional[enum_zip("resource_type", LearningResourceType.names())]
181+
resource_type: Optional[
182+
list[enum_zip("resource_type", LearningResourceType.names())]
183+
]
179184
level: Optional[enum_zip("level", LevelType.names())]
180185
free: Optional[bool]
181186
certificate: Optional[bool]
@@ -205,6 +210,7 @@ def __init__( # noqa: PLR0913
205210
)
206211
self.temperature = temperature
207212
self.search_parameters = []
213+
self.search_results = []
208214
self.agent = self.create_agent()
209215
self.create_agent()
210216

@@ -247,6 +253,7 @@ def search_courses(self, q: str, **kwargs) -> str:
247253
{k: result.get(k) for k in main_properties}
248254
for result in response.json().get("results", [])
249255
]
256+
self.search_results.append(results)
250257
return json.dumps(results)
251258
except requests.exceptions.RequestException as e:
252259
log.exception("Error querying MIT API")
@@ -289,6 +296,7 @@ def get_comment_metadata(self):
289296
metadata = {
290297
"metadata": {
291298
"search_parameters": self.search_parameters,
299+
"search_results": self.search_results,
292300
"system_prompt": self.instructions,
293301
}
294302
}

frontends/ol-components/src/components/Nlux-AiChat/AiChat.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { personas } from "./personas"
1111

1212
import "@nlux/themes/unstyled.css"
1313
import "./nlux-theme.css"
14+
import { styled } from "ol-components"
1415

1516
type NluxAiChatProps = Pick<
1617
AiChatProps,
@@ -19,6 +20,11 @@ type NluxAiChatProps = Pick<
1920
send: StreamSend
2021
}
2122

23+
const StyledDebugPre = styled.pre({
24+
width: "80%",
25+
"white-space": "pre-wrap",
26+
})
27+
2228
const NluxAiChat: React.FC<NluxAiChatProps> = (props) => {
2329
const adapter = useAsStreamAdapter(props.send, [])
2430
const [lastMessageReceived, setLastMessageReceived] = useState("")
@@ -42,9 +48,9 @@ const NluxAiChat: React.FC<NluxAiChatProps> = (props) => {
4248
{...props}
4349
/>
4450
{lastMessageReceived ? (
45-
<>
51+
<div>
4652
<p>Debug Info:</p>
47-
<pre>
53+
<StyledDebugPre>
4854
{lastMessageReceived
4955
? lastMessageReceived.toString()?.includes('{"error":')
5056
? JSON.stringify(
@@ -64,8 +70,8 @@ const NluxAiChat: React.FC<NluxAiChatProps> = (props) => {
6470
)
6571
: ""
6672
: ""}
67-
</pre>
68-
</>
73+
</StyledDebugPre>
74+
</div>
6975
) : null}
7076
</>
7177
)

0 commit comments

Comments
 (0)