-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 댓글 대댓글 복사 가능 * feat: 중국어(간체) 추가 및 적용 * chore: openai 라이브러리 추가 * feat: community article 번역기능 추가 * feat: 프롬프트 수정, 댓글 대댓글 번역 기능 추가 * refactor: openai 라이브러리 제거, openai 로 직접 요청 * fix: build 오류 수정 * refactor: readme 위치 변경 * feat: readme 수정
- Loading branch information
1 parent
62360c6
commit 66fdcb2
Showing
20 changed files
with
716 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import axios from 'axios'; | ||
|
||
import { Message } from '.'; | ||
|
||
export const postOpenAIAPI = async (messages: Message[]) => { | ||
const response = await axios.post( | ||
'https://api.openai.com/v1/chat/completions', | ||
{ | ||
messages, | ||
model: 'gpt-3.5-turbo', | ||
}, | ||
{ | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${process.env.NEXT_PUBLIC_OPEN_API}`, | ||
}, | ||
} | ||
); | ||
|
||
return JSON.parse(response.data.choices[0].message.content); | ||
}; |
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,3 @@ | ||
export * from './apis'; | ||
export * from './mutations'; | ||
export * from './type'; |
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,42 @@ | ||
import { useMutation } from '@tanstack/react-query'; | ||
|
||
import { Message } from '.'; | ||
import { postOpenAIAPI } from './apis'; | ||
|
||
export const usePostTranslateGPT = () => { | ||
const { mutateAsync, isPending } = useMutation({ | ||
mutationFn: postOpenAIAPI, | ||
}); | ||
|
||
const postTranslate = async ({ | ||
title, | ||
content, | ||
targetLang, | ||
}: { | ||
title?: string; | ||
content: string; | ||
targetLang: string; | ||
}) => { | ||
const userContent = title | ||
? `Translate the following text to ${targetLang} and format the output as requested: { title: "${title}", content: "${content}" }` | ||
: `Translate the following text to ${targetLang} and format the output as requested: { content: "${content}" }`; | ||
|
||
const messages: Message[] = [ | ||
{ | ||
role: 'system', | ||
content: | ||
'You are a translator assistant that provides JSON output. Please ensure the translation output is in the format of {title: "translated text", content: "translated text"} if title is provided, otherwise just {content: "translated text"}.', | ||
}, | ||
{ | ||
role: 'user', | ||
content: userContent, | ||
}, | ||
]; | ||
return mutateAsync(messages); | ||
}; | ||
|
||
return { | ||
postTranslate, | ||
isPending, | ||
}; | ||
}; |
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,29 @@ | ||
export type RoleType = 'system' | 'user' | 'assistant' | 'tool' | 'function'; | ||
|
||
export interface OpenAIResponse { | ||
id: string; | ||
object: string; | ||
created: number; | ||
model: string; | ||
choices: Choice[]; | ||
usage: Usage; | ||
system_fingerprint: string; | ||
} | ||
|
||
export interface Choice { | ||
index: number; | ||
message: Message; | ||
logprobs: null | any; | ||
finish_reason: string; | ||
} | ||
|
||
export interface Message { | ||
role: RoleType; | ||
content: string; | ||
} | ||
|
||
export interface Usage { | ||
prompt_tokens: number; | ||
completion_tokens: number; | ||
total_tokens: number; | ||
} |
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
Oops, something went wrong.