-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fe): integrate improve reply api (#89)
* feat: add reply improvement and retry APIs * feat: implement reply writing support with improvement and retry functionality * feat: update Popover component text for markdown preview and content type switching
- Loading branch information
Showing
10 changed files
with
337 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
apps/client/src/features/create-update-reply/api/improve-reply-retry.api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import axios from 'axios'; | ||
import { z } from 'zod'; | ||
|
||
export const RetryReplyImprovementRequestSchema = z.object({ | ||
token: z.string(), | ||
sessionId: z.string(), | ||
originalQuestion: z.string(), | ||
original: z.string(), | ||
received: z.string(), | ||
retryMessage: z.string(), | ||
}); | ||
|
||
export const RetryReplyImprovementResponseSchema = z.object({ | ||
result: z.object({ | ||
reply: z.string(), | ||
}), | ||
}); | ||
|
||
export type RetryReplyImprovementRequest = z.infer<typeof RetryReplyImprovementRequestSchema>; | ||
|
||
export type RetryReplyImprovementResponse = z.infer<typeof RetryReplyImprovementResponseSchema>; | ||
|
||
export const postRetryReplyImprovement = (body: RetryReplyImprovementRequest) => | ||
axios | ||
.post<RetryReplyImprovementResponse>('/api/ai/reply-improve-retry', RetryReplyImprovementRequestSchema.parse(body)) | ||
.then((res) => RetryReplyImprovementResponseSchema.parse(res.data)); |
24 changes: 24 additions & 0 deletions
24
apps/client/src/features/create-update-reply/api/improve-reply.api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import axios from 'axios'; | ||
import { z } from 'zod'; | ||
|
||
export const ReplyImprovementRequestSchema = z.object({ | ||
token: z.string(), | ||
sessionId: z.string(), | ||
body: z.string(), | ||
originalQuestion: z.string(), | ||
}); | ||
|
||
export const ReplyImprovementResponseSchema = z.object({ | ||
result: z.object({ | ||
reply: z.string(), | ||
}), | ||
}); | ||
|
||
export type ReplyImprovementRequest = z.infer<typeof ReplyImprovementRequestSchema>; | ||
|
||
export type ReplyImprovementResponse = z.infer<typeof ReplyImprovementResponseSchema>; | ||
|
||
export const postReplyImprovement = (body: ReplyImprovementRequest) => | ||
axios | ||
.post<ReplyImprovementResponse>('/api/ai/reply-improve', ReplyImprovementRequestSchema.parse(body)) | ||
.then((res) => ReplyImprovementResponseSchema.parse(res.data)); |
74 changes: 74 additions & 0 deletions
74
apps/client/src/features/create-update-reply/model/useReplyWritingSupport.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { useState } from 'react'; | ||
|
||
import { AIRequestType, postAIHistory } from '@/features/ai-history'; | ||
import { postRetryReplyImprovement } from '@/features/create-update-reply/api/improve-reply-retry.api'; | ||
import { postReplyImprovement } from '@/features/create-update-reply/api/improve-reply.api'; | ||
|
||
export const useReplyWritingSupport = ({ | ||
questionBody, | ||
body, | ||
handleAccept, | ||
}: { | ||
questionBody: string; | ||
body: string; | ||
handleAccept: (body: string) => void; | ||
}) => { | ||
const [supportResult, setSupportResult] = useState<string | null>(null); | ||
const [supportType, setSupportType] = useState<AIRequestType | null>(null); | ||
|
||
const { mutate: replyImprovement, isPending: isReplyImprovementInProgress } = useMutation({ | ||
mutationFn: postReplyImprovement, | ||
onSuccess: (data) => { | ||
setSupportResult(data.result.reply); | ||
}, | ||
}); | ||
|
||
const { mutate: retryReplyImprovement, isPending: isRetryReplyImprovementInProgress } = useMutation({ | ||
mutationFn: postRetryReplyImprovement, | ||
onSuccess: (data) => { | ||
setSupportResult(data.result.reply); | ||
}, | ||
}); | ||
|
||
const request = `# Q)\n${questionBody}\n\n# A)\n${body}`; | ||
|
||
const accept = () => { | ||
if (supportResult && supportType) { | ||
handleAccept(supportResult); | ||
postAIHistory({ | ||
promptName: supportType, | ||
request, | ||
response: supportResult, | ||
result: 'ACCEPT', | ||
}); | ||
setSupportResult(null); | ||
} | ||
}; | ||
|
||
const reject = () => { | ||
if (supportResult && supportType) { | ||
postAIHistory({ | ||
promptName: supportType, | ||
request, | ||
response: supportResult, | ||
result: 'REJECT', | ||
}); | ||
setSupportResult(null); | ||
} | ||
}; | ||
|
||
const requestEnable = !isReplyImprovementInProgress && !isRetryReplyImprovementInProgress; | ||
|
||
return { | ||
replyImprovement, | ||
retryReplyImprovement, | ||
supportResult, | ||
setSupportResult, | ||
supportType, | ||
setSupportType, | ||
accept, | ||
reject, | ||
requestEnable, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.