Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: fixed followup questions issues #3095

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clients/search-component/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"import": "./dist/vanilla/index.js"
}
},
"version": "0.3.6",
"version": "0.3.7",
"license": "MIT",
"homepage": "https://github.com/devflowinc/trieve/tree/main/clients/search-component",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export const Message = ({
: null}
{props.followupQuestions && messages.length == idx + 1 &&
<FollowupQueries /> }
{isDoneReading && <div className="feedback-wrapper">
{isDoneReading && messages.length == idx + 1 && <div className="feedback-wrapper">
<span className="spacer"></span>
<div className="feedback-icons">
{copied ? (
Expand Down
2 changes: 2 additions & 0 deletions clients/search-component/src/utils/hooks/modal-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export type ModalProps = {
showFloatingSearchIcon?: boolean;
showFloatingInput?: boolean;
inlineHeader?: string;
suggestedQueriesContext: string;
};

const defaultProps = {
Expand Down Expand Up @@ -152,6 +153,7 @@ const defaultProps = {
showFloatingInput: false,
inline: false,
inlineHeader: "AI Assistant by Trieve",
suggestedQueriesContext: "You are an ecommerce sales assistant to help people buy items."
};

const ModalContext = createContext<{
Expand Down
20 changes: 7 additions & 13 deletions clients/search-component/src/utils/hooks/useFollowupQuestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { useEffect, useState } from "react";
import { SuggestedQueriesResponse } from "trieve-ts-sdk";
import { getSuggestedQuestions } from "../trieve";
import { useModalState } from "./modal-context";
import { useChatState } from "./chat-context";

export const useFollowupQuestions = () => {
const { query, trieveSDK, currentGroup, props } = useModalState();
const { trieveSDK, currentGroup, props } = useModalState();
const { currentQuestion } = useChatState();
const [isLoading, setIsLoading] = useState(false);
const [suggestedQuestions, setSuggestedQuestions] = useState<
SuggestedQueriesResponse["queries"]
Expand All @@ -14,11 +16,12 @@ export const useFollowupQuestions = () => {
setIsLoading(true);
const queries = await getSuggestedQuestions({
trieve: trieveSDK,
query,
query: currentQuestion,
count: props.numberOfSuggestions ?? 3,
context: props.suggestedQueriesContext,
group: currentGroup
});
setSuggestedQuestions(queries.queries.splice(0, 3));
setSuggestedQuestions(queries.queries);
setIsLoading(false);
};

Expand All @@ -31,16 +34,7 @@ export const useFollowupQuestions = () => {
const abortController = new AbortController();

const timeoutId = setTimeout(async () => {
const queries = await getSuggestedQuestions({
trieve: trieveSDK,
abortController,
group: currentGroup,
query,
count: props.numberOfSuggestions ?? 3,
context: "You are an assistant searching through a docs website"
});
setSuggestedQuestions(queries.queries);
setIsLoading(false);
getQuestions();
});

return () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const useSuggestedQueries = () => {
trieve: trieveSDK,
query,
count: props.numberOfSuggestions ?? 3,
context: props.suggestedQueriesContext,
abortController,
});
setSuggestedQueries(queries.queries);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const useSuggestedQuestions = () => {
const queries = await getSuggestedQuestions({
trieve: trieveSDK,
count: props.numberOfSuggestions ?? 3,
context: props.suggestedQueriesContext,
query,
});
setSuggestedQuestions(queries.queries);
Expand All @@ -38,6 +39,7 @@ export const useSuggestedQuestions = () => {
const queries = await getSuggestedQuestions({
trieve: trieveSDK,
count: props.numberOfSuggestions ?? 3,
context: props.suggestedQueriesContext,
abortController,
query,
});
Expand Down
13 changes: 5 additions & 8 deletions clients/search-component/src/utils/trieve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,13 @@ export const getSuggestedQueries = async ({
trieve,
query,
count,
context,
abortController,
}: {
query: string;
trieve: TrieveSDK;
count: number;
context: string;
abortController?: AbortController;
}) => {
return trieve.suggestedQueries(
Expand All @@ -272,7 +274,7 @@ export const getSuggestedQueries = async ({
suggestion_type: "keyword",
suggestions_to_create: count,
search_type: "semantic",
context: "You are a user searching through a docs website",
context: context
},
abortController?.signal
);
Expand All @@ -288,22 +290,17 @@ export const getSuggestedQuestions = async ({
}: {
trieve: TrieveSDK;
abortController?: AbortController;
context?: string;
context: string;
query?: string;
count: number;
group?: ChunkGroup | null;
}) => {
let suggestedQueriesContext =
"You are a user searching through a docs website";
if (context) {
suggestedQueriesContext = context;
}
return trieve.suggestedQueries(
{
...(query && { query }),
suggestion_type: "question",
search_type: "semantic",
context: suggestedQueriesContext,
context: context,
suggestions_to_create: count,
...(group &&
group?.tracking_id && {
Expand Down
4 changes: 4 additions & 0 deletions clients/ts-sdk/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -12718,6 +12718,10 @@
"type": "boolean",
"nullable": true
},
"suggestedQueriesContext": {
"type": "string",
"nullable": true
},
"tabMessages": {
"type": "array",
"items": {
Expand Down
1 change: 1 addition & 0 deletions clients/ts-sdk/src/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2119,6 +2119,7 @@ export type PublicPageParameters = {
showFloatingSearchIcon?: (boolean) | null;
singleProductOptions?: ((SingleProductOptions) | null);
suggestedQueries?: (boolean) | null;
suggestedQueriesContext?: (string) | null;
tabMessages?: Array<PublicPageTabMessage> | null;
tags?: Array<PublicPageTag> | null;
theme?: ((PublicPageTheme) | null);
Expand Down
15 changes: 15 additions & 0 deletions frontends/dashboard/src/pages/dataset/PublicPageSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,21 @@ const PublicPageControls = () => {
/>
</div>

<div class="flex gap-4 pb-2 pt-2">
<div class="grow">
<label class="block">Suggested Queries Context</label>
<textarea
cols={2}
placeholder="You are an ecommerce sales assistant to help people buy items."
value={ extraParams.suggestedQueriesContext || ""}
onInput={(e) => {
setExtraParams("suggestedQueriesContext", e.currentTarget.value)
}}
class="block w-full rounded border border-neutral-300 px-3 py-1.5 shadow-sm placeholder:text-neutral-400 focus:outline-magenta-500 sm:text-sm sm:leading-6"
/>
</div>
</div>

<div class="grid grid-cols-2 gap-4">
<div class="flex gap-2">
<div class="flex items-center gap-1">
Expand Down
3 changes: 3 additions & 0 deletions server/src/data/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3297,6 +3297,9 @@ impl DatasetConfigurationDTO {
inline_header: page_parameters_self
.inline_header
.or(page_parameters_curr.inline_header),
suggested_queries_context: page_parameters_self
.suggested_queries_context
.or(page_parameters_curr.suggested_queries_context),
}),
},
DISABLE_ANALYTICS: self
Expand Down
2 changes: 2 additions & 0 deletions server/src/handlers/page_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ pub struct PublicPageParameters {
pub number_of_suggestions: Option<usize>,
#[serde(skip_serializing_if = "Option::is_none")]
pub inline_header: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub suggested_queries_context: Option<String>,
}

#[utoipa::path(
Expand Down
9 changes: 9 additions & 0 deletions server/src/public/search-component-code.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,18 @@
{% if params.type -%}
type: "{{ params.type }}",
{% endif -%}
{% if params.suggestedQueries -%}
suggestedQueries: {{ params.suggestedQueries }},
{% endif -%}
{% if params.followupQuestions -%}
followupQuestions: {{ params.followupQuestions }},
{% endif -%}
{% if params.inline -%}
inline: {{ params.inline }},
{% endif -%}
{% if params.suggestedQueriesContext -%}
suggestedQueriesContext: "{{ params.suggestedQueriesContext }}",
{% endif -%}
{% if params.analytics -%}
analytics: {{ params.analytics }},
{% endif -%}
Expand Down