Skip to content

Commit

Permalink
Fix certification parameter, update prompts, catch json parsing error… (
Browse files Browse the repository at this point in the history
  • Loading branch information
mbertrand authored Dec 20, 2024
1 parent 35dcfcd commit 90bdbba
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
15 changes: 7 additions & 8 deletions ai_chat/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ class SearchAgent(BaseChatAgent):
you should include this parameter based on the following
dictionary: {OfferedBy.as_dict()} DO NOT USE THE offered_by FILTER OTHERWISE.
certificate: true if the user is interested in resources that offer certificates, false
if the user does not want resources with a certificate offered. Do not used this filter
if the user does not indicate a preference.
certification: true if the user is interested in resources that offer certificates,
false if the user does not want resources with a certificate offered. Do not use
this filter if the user does not indicate a preference.
free: true if the user is interested in free resources, false if the user is only
interested in paid resources. Do not used this filter if the user does not indicate
Expand Down Expand Up @@ -282,7 +282,7 @@ class SearchToolSchema(pydantic.BaseModel):
q: The search query string
resource_type: Filter by type of resource (course, program, etc)
free: Filter for free resources only
certificate: Filter for resources offering certificates
certification: Filter for resources offering certificates
offered_by: Filter by institution offering the resource
"""

Expand All @@ -301,7 +301,7 @@ class SearchToolSchema(pydantic.BaseModel):
default=None,
description="Whether the resource is free to access, true|false",
)
certificate: Optional[bool] = Field(
certification: Optional[bool] = Field(
default=None,
description=(
"Whether the resource offers a certificate upon completion, true|false"
Expand All @@ -319,7 +319,7 @@ class SearchToolSchema(pydantic.BaseModel):
"q": "machine learning",
"resource_type": ["course"],
"free": True,
"certificate": False,
"certification": False,
"offered_by": "MIT",
}
]
Expand Down Expand Up @@ -366,7 +366,7 @@ def search_courses(self, q: str, **kwargs) -> str:
"resource_type": kwargs.get("resource_type"),
"free": kwargs.get("free"),
"offered_by": kwargs.get("offered_by"),
"certificate": kwargs.get("certificate"),
"certification": kwargs.get("certification"),
}
params.update({k: v for k, v in valid_params.items() if v is not None})
self.search_parameters.append(params)
Expand Down Expand Up @@ -461,7 +461,6 @@ def get_comment_metadata(self) -> str:
"metadata": {
"search_parameters": self.search_parameters,
"search_results": self.search_results,
"system_prompt": self.instructions,
}
}
return json.dumps(metadata)
2 changes: 1 addition & 1 deletion ai_chat/agents_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def test_search_agent_tool(settings, mocker):
"q": "physics",
"resource_type": ["course", "program"],
"free": False,
"certificate": True,
"certification": True,
"offered_by": "xpro",
"limit": 5,
}
Expand Down
23 changes: 18 additions & 5 deletions frontends/main/src/app-pages/ChatPage/ChatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,24 @@ import { NluxAiChat } from "@/page-components/Nlux-AiChat/AiChat"
import { FeatureFlags } from "@/common/feature_flags"
import { useFeatureFlagEnabled } from "posthog-js/react"

const CONVERSATION_OPTTIONS = {
const CONVERSATION_OPTIONS = {
conversationStarters: [
{ prompt: "I'm interested in quantum computing." },
{ prompt: "I want to learn about global warming." },
{ prompt: "I am curious about AI applications for business." },
{
prompt:
"I'm interested in courses on quantum computing that offer certificates.",
},
{
prompt:
"I want to learn about global warming, can you recommend any videos?",
},
{
prompt:
"I am curious about AI applications for business. Do you have any free courses about that?",
},
{
prompt:
"I would like to learn about linear regression, preferably at no cost.",
},
],
}

Expand Down Expand Up @@ -41,7 +54,7 @@ const ChatPage = () => {
<StyledChat
key={"agent"}
send={sends["agent"]}
conversationOptions={CONVERSATION_OPTTIONS}
conversationOptions={CONVERSATION_OPTIONS}
/>
) : (
<></>
Expand Down
7 changes: 6 additions & 1 deletion frontends/ol-utilities/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,10 @@ export const pluralize = (singular: string, count: number, plural?: string) => {
*/
export const extractJSONFromComment = (comment: string) => {
const jsonStr = comment.toString().match(/<!-{2}(.*)-{2}>/)?.[1] || "{}"
return JSON.parse(jsonStr)
try {
return JSON.parse(jsonStr)
} catch (e) {
console.error("error parsing JSON from comment", comment, e)
return {}
}
}

0 comments on commit 90bdbba

Please sign in to comment.