Commit 5b9dbdd 1 parent 7b70afe commit 5b9dbdd Copy full SHA for 5b9dbdd
File tree 3 files changed +45
-12
lines changed
3 files changed +45
-12
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import { useParams } from "react-router-dom";
8
8
import { usePromptsStore } from "@/hooks/usePromptsStore" ;
9
9
import { Markdown } from "./Markdown" ;
10
10
import { useEffect } from "react" ;
11
+ import { sanitizeQuestionPrompt } from "@/lib/utils" ;
11
12
12
13
export function Chat ( ) {
13
14
const { id } = useParams ( ) ;
@@ -31,7 +32,10 @@ export function Chat() {
31
32
< ChatBubbleAvatar fallback = "User" className = "w-14" />
32
33
< ChatBubbleMessage variant = "sent" className = "bg-zinc-700" >
33
34
< Markdown className = "text-gray-300" >
34
- { question ?. message }
35
+ { sanitizeQuestionPrompt ( {
36
+ question : question ?. message ,
37
+ answer : answer ?. message ,
38
+ } ) }
35
39
</ Markdown >
36
40
</ ChatBubbleMessage >
37
41
</ ChatBubble >
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { Link } from "react-router-dom";
3
3
import {
4
4
extractTitleFromMessage ,
5
5
groupPromptsByRelativeDate ,
6
+ sanitizeQuestionPrompt ,
6
7
} from "@/lib/utils" ;
7
8
import { usePromptsStore } from "@/hooks/usePromptsStore" ;
8
9
import clsx from "clsx" ;
@@ -28,8 +29,14 @@ export function PromptList({ prompts }: { prompts: Prompt[] }) {
28
29
) }
29
30
>
30
31
{ extractTitleFromMessage (
31
- prompt . question_answers ?. [ 0 ] . question . message ??
32
- `Prompt ${ prompt . conversation_timestamp } `
32
+ prompt . question_answers ?. [ 0 ] . question . message
33
+ ? sanitizeQuestionPrompt ( {
34
+ question :
35
+ prompt . question_answers ?. [ 0 ] . question . message ,
36
+ answer :
37
+ prompt . question_answers ?. [ 0 ] ?. answer ?. message ?? "" ,
38
+ } )
39
+ : `Prompt ${ prompt . conversation_timestamp } `
33
40
) }
34
41
</ Link >
35
42
</ li >
Original file line number Diff line number Diff line change @@ -13,18 +13,22 @@ export function cn(...inputs: ClassValue[]) {
13
13
}
14
14
15
15
export function extractTitleFromMessage ( message : string ) {
16
- const regex = / ^ ( .* ) ` ` ` [ \s \S ] * ?` ` ` ( .* ) $ / s;
17
- const match = message . match ( regex ) ;
16
+ try {
17
+ const regex = / ^ ( .* ) ` ` ` [ \s \S ] * ?` ` ` ( .* ) $ / s;
18
+ const match = message . match ( regex ) ;
18
19
19
- if ( match ) {
20
- const beforeMarkdown = match [ 1 ] . trim ( ) ;
21
- const afterMarkdown = match [ 2 ] . trim ( ) ;
20
+ if ( match ) {
21
+ const beforeMarkdown = match [ 1 ] . trim ( ) ;
22
+ const afterMarkdown = match [ 2 ] . trim ( ) ;
22
23
23
- const title = beforeMarkdown || afterMarkdown ;
24
- return title ;
25
- }
24
+ const title = beforeMarkdown || afterMarkdown ;
25
+ return title ;
26
+ }
26
27
27
- return message . trim ( ) ;
28
+ return message . trim ( ) ;
29
+ } catch {
30
+ return message . trim ( ) ;
31
+ }
28
32
}
29
33
30
34
function getGroup ( differenceInMs : number , promptDate : Date ) : string {
@@ -108,3 +112,21 @@ export function getMaliciousPackages() {
108
112
109
113
return chartData ;
110
114
}
115
+
116
+ export function sanitizeQuestionPrompt ( {
117
+ question,
118
+ answer,
119
+ } : {
120
+ question : string ;
121
+ answer : string ;
122
+ } ) {
123
+ try {
124
+ if ( answer ) {
125
+ return question . split ( "Query:" ) . pop ( ) ?? "" ;
126
+ }
127
+
128
+ return question ;
129
+ } catch {
130
+ return question ;
131
+ }
132
+ }
You can’t perform that action at this time.
0 commit comments