File tree Expand file tree Collapse file tree 3 files changed +25
-7
lines changed Expand file tree Collapse file tree 3 files changed +25
-7
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ export function PromptList({ prompts }: { prompts: Prompt[] }) {
12
12
const { currentPromptId, setCurrentPromptId } = usePromptsStore ( ) ;
13
13
14
14
const groupedPrompts = groupPromptsByRelativeDate ( prompts ) ;
15
+
15
16
return (
16
17
< div className = "mx-2" >
17
18
{ Object . entries ( groupedPrompts ) . map ( ( [ group , prompts ] ) => (
Original file line number Diff line number Diff line change 1
- import { extractTitleFromMessage } from "@/lib/utils" ;
1
+ import { extractTitleFromMessage , sanitizeQuestionPrompt } from "@/lib/utils" ;
2
2
import { useLocation } from "react-router-dom" ;
3
3
import { usePromptsStore } from "./usePromptsStore" ;
4
4
@@ -20,7 +20,12 @@ export function useBreadcrumb() {
20
20
try {
21
21
const chat = prompts . find ( ( prompt ) => prompt . chat_id === currentPromptId ) ;
22
22
const title = chat ?. question_answers ?. [ 0 ] . question . message ?? "" ;
23
- return extractTitleFromMessage ( title ) ?? "" ;
23
+
24
+ const sanitized = sanitizeQuestionPrompt ( {
25
+ question : title ,
26
+ answer : chat ?. question_answers ?. [ 0 ] ?. answer ?. message ?? "" ,
27
+ } ) ;
28
+ return extractTitleFromMessage ( sanitized ) ?? "" ;
24
29
} catch {
25
30
return "" ;
26
31
}
Original file line number Diff line number Diff line change @@ -20,7 +20,6 @@ export function extractTitleFromMessage(message: string) {
20
20
if ( match ) {
21
21
const beforeMarkdown = match [ 1 ] . trim ( ) ;
22
22
const afterMarkdown = match [ 2 ] . trim ( ) ;
23
-
24
23
const title = beforeMarkdown || afterMarkdown ;
25
24
return title ;
26
25
}
@@ -121,12 +120,25 @@ export function sanitizeQuestionPrompt({
121
120
answer : string ;
122
121
} ) {
123
122
try {
123
+ // Check if 'answer' is truthy; if so, try to find and return the text after "Query:"
124
124
if ( answer ) {
125
- return question . split ( "Query:" ) . pop ( ) ?? "" ;
125
+ const index = question . indexOf ( "Query:" ) ;
126
+ if ( index !== - 1 ) {
127
+ // Return the substring starting right after the first occurrence of "Query:"
128
+ // Adding the length of "Query:" to the index to start after it
129
+ return question . substring ( index + "Query:" . length ) . trim ( ) ;
130
+ } else {
131
+ // If there is no "Query:" in the string, log the condition and return an empty string
132
+ console . log ( "No 'Query:' found in the question." ) ;
133
+ return "" ;
134
+ }
135
+ } else {
136
+ // If 'answer' is not provided or falsy, return the original question
137
+ return question ;
126
138
}
127
-
128
- return question ;
129
- } catch {
139
+ } catch ( error ) {
140
+ // Log the error and return the original question as a fallback
141
+ console . error ( "Error processing the question:" , error ) ;
130
142
return question ;
131
143
}
132
144
}
You can’t perform that action at this time.
0 commit comments