-
Notifications
You must be signed in to change notification settings - Fork 1
[BAK-62] [기능]AIChatMessage 사용자질의(AI연결) #56
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b6ca7a7
feat: chat_message API 로직 추가
apaals2 698f771
feat: chat_message 상태코드 추가
apaals2 bd0ff9b
feat: chat_message enum 추가
apaals2 14b952c
feat: chat_message 스키마 모델 추가
apaals2 26240b0
feat: chat_message 서비스 로직 추가
apaals2 240a65b
feat: chat_message repository 로직 추가
apaals2 8f83e3e
refactor: chat_tab에 남아있던 chat_message 로직 분리
apaals2 721de87
refactor: prefix_name 하이픈(-) 수정
apaals2 5398a1b
refactor: AI서버주소 환경변수 처리
apaals2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,39 @@ | ||
| from fastapi import APIRouter, Depends | ||
|
|
||
| from app.core.enum.sender import SenderEnum | ||
| from app.core.response import ResponseMessage | ||
| from app.core.status import CommonCode | ||
| from app.schemas.chat_message.request_model import ChatMessagesReqeust | ||
| from app.schemas.chat_message.response_model import ChatMessagesResponse | ||
| from app.services.chat_message_service import ChatMessageService, chat_message_service | ||
|
|
||
| chat_message_service_dependency = Depends(lambda: chat_message_service) | ||
|
|
||
| router = APIRouter() | ||
|
|
||
|
|
||
| @router.post( | ||
| "/create", | ||
| response_model=ResponseMessage[ChatMessagesResponse], | ||
| summary="새로운 사용자 질의 생성", | ||
| ) | ||
| async def create_chat_message( | ||
| request: ChatMessagesReqeust, service: ChatMessageService = chat_message_service_dependency | ||
| ) -> ResponseMessage[ChatMessagesResponse]: | ||
| """ | ||
| `tabId`, `message`를 받아 DB에 저장하고 AI를 통해 사용자 질의를 분석하고 답변을 생성하여 반환합니다. | ||
| """ | ||
| new_messages = await service.create_chat_message(request) | ||
|
|
||
| print(ChatMessagesResponse.model_json_schema()) | ||
|
|
||
| response_data = ChatMessagesResponse( | ||
| id=new_messages.id, | ||
| chat_tab_id=new_messages.chat_tab_id, | ||
| sender=SenderEnum(new_messages.sender), | ||
| message=new_messages.message, | ||
| created_at=new_messages.created_at, | ||
| updated_at=new_messages.updated_at, | ||
| ) | ||
|
|
||
| return ResponseMessage.success(value=response_data, code=CommonCode.SUCCESS_CREATE_CHAT_MESSAGES) |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,8 @@ | ||
| from enum import Enum | ||
|
|
||
|
|
||
| class SenderEnum(str, Enum): | ||
| """채팅 메시지 발신자 구분""" | ||
|
|
||
| user = "U" | ||
| ai = "A" |
This file contains hidden or 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 hidden or 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 hidden or 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 @@ | ||
| from datetime import datetime | ||
|
|
||
| from pydantic import BaseModel, Field | ||
|
|
||
| from app.core.enum.db_key_prefix_name import DBSaveIdEnum | ||
| from app.core.exceptions import APIException | ||
| from app.core.status import CommonCode | ||
|
|
||
|
|
||
| class ChatMessagesBase(BaseModel): | ||
| id: str = Field(..., description="고유 ID") | ||
| created_at: datetime = Field(..., description="생성 시각") | ||
| updated_at: datetime = Field(..., description="마지막 수정 시각") | ||
|
|
||
|
|
||
| class RequestBase(BaseModel): | ||
| """요청 스키마의 기본 모델""" | ||
|
|
||
| def validate_chat_tab_id(self) -> None: | ||
| """채팅 탭 ID에 대한 유효성 검증 로직을 수행합니다.""" | ||
|
|
||
| required_prefix = DBSaveIdEnum.chat_tab.value + "-" | ||
| if not self.chat_tab_id.startswith(required_prefix): | ||
| raise APIException(CommonCode.INVALID_CHAT_TAB_ID_FORMAT) |
This file contains hidden or 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,13 @@ | ||
| from pydantic import Field | ||
|
|
||
| from app.core.enum.sender import SenderEnum | ||
| from app.schemas.chat_message.base_model import ChatMessagesBase | ||
|
|
||
|
|
||
| class ChatMessageInDB(ChatMessagesBase): | ||
| chat_tab_id: str = Field(..., description="해당 메시지가 속한 채팅 탭의 ID") | ||
| sender: SenderEnum = Field(..., description="메시지 발신자 ('A' 또는 'U')") | ||
| message: str = Field(..., description="메시지 내용") | ||
|
|
||
| class Config: | ||
| use_enum_values = True |
This file contains hidden or 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,13 @@ | ||
| from pydantic import Field | ||
|
|
||
| from app.schemas.chat_message.base_model import RequestBase | ||
|
|
||
|
|
||
| class ChatMessagesReqeust(RequestBase): | ||
| """채팅 메시지 생성 요청 스키마""" | ||
|
|
||
| chat_tab_id: str = Field(..., description="채팅 탭의 고유 ID") | ||
| message: str = Field(..., description="메시지 내용") | ||
|
|
||
| def validate(self): | ||
| self.validate_chat_tab_id() |
This file contains hidden or 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,13 @@ | ||
| from pydantic import Field | ||
|
|
||
| from app.core.enum.sender import SenderEnum | ||
| from app.schemas.chat_message.base_model import ChatMessagesBase | ||
|
|
||
|
|
||
| class ChatMessagesResponse(ChatMessagesBase): | ||
| chat_tab_id: str = Field(..., description="해당 메시지가 속한 채팅 탭의 ID") | ||
| sender: SenderEnum = Field(..., description="메시지 발신자 ('AI' 또는 'User')") | ||
| message: str = Field(..., description="메시지 내용") | ||
|
|
||
| class Config: | ||
| use_enum_values = True |
This file contains hidden or 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 hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
언더바 말고 중간바로 수정해주실 수 있나여?
AS-IS
chat_message = "CHAT_MESSAGE"
chat_tab = "CHAT_TAB"
TO-BE
chat_message = "CHAT-MESSAGE"
chat_tab = "CHAT-TAB"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
반영했습니다