Conversation
응답형식 변경 프롬프트 블록 별도 파일에 작성
|
""" WalkthroughGPT API 연동을 위한 주요 백엔드 기능이 추가되었습니다. FastAPI 엔드포인트, 서비스 레이어, 프롬프트 생성, 예시 데이터, 설정 관리, 모델 정의 등이 신규로 도입되었고, 배포 워크플로와 의존성도 보강되었습니다. 기존 라우터는 삭제 및 경로가 변경되었습니다. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant FastAPI (fraud_analysis)
participant GPTService
participant OpenAI API
Client->>FastAPI (fraud_analysis): POST /api/fraud-analysis (FraudRequest)
FastAPI (fraud_analysis)->>GPTService: call_gpt(request)
GPTService->>OpenAI API: GPT-4o-mini 모델로 프롬프트 요청
OpenAI API-->>GPTService: JSON 응답 반환
GPTService-->>FastAPI (fraud_analysis): FraudResponse 파싱/반환
FastAPI (fraud_analysis)-->>Client: FraudResponse 반환
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~18 minutes Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (6)
🚧 Files skipped from review as they are similar to previous changes (6)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 9
🧹 Nitpick comments (8)
app/models/fraud_request.py (1)
8-8: imageContent 필드에 대한 검증 추가를 고려하세요.
imageContent가 문자열로 정의되어 있지만 base64 인코딩된 이미지 데이터인지 URL인지 명확하지 않습니다. 적절한 검증을 추가하는 것을 권장합니다.from pydantic import BaseModel, Field, validator from typing import List, Optional import base64 class FraudRequest(BaseModel): messageContent: str keywords: List[str] additionalDescription: Optional[str] = None - imageContent: Optional[str] = None + imageContent: Optional[str] = Field(None, description="Base64 encoded image or image URL") + + @validator('imageContent') + def validate_image_content(cls, v): + if v and not (v.startswith('data:image/') or v.startswith('http')): + # Check if it's valid base64 + try: + base64.b64decode(v) + except Exception: + raise ValueError('imageContent must be base64 encoded image, data URL, or HTTP URL') + return v.coderabbit/config.yml (1)
1-2: 파일 끝에 개행 문자를 추가하세요.YAML 파일의 모범 사례에 따라 파일 끝에 개행 문자가 필요합니다.
features: - docstrings: false + docstrings: false +.github/workflows/deploy.yml (1)
64-64: 파일 끝에 개행 문자를 추가하세요.YAML 파일의 모범 사례에 따라 파일 끝에 개행 문자가 필요합니다.
-e GPT_API_KEY="${{ env.GPT_API_KEY }}" \ - ${{ env.DOCKER_REPO }}:latest + ${{ env.DOCKER_REPO }}:latest +app/config/setting.py (1)
9-9: 설정 인스턴스 초기화 시 예외 처리 고려환경변수가 누락되거나 잘못된 경우를 대비한 예외 처리를 추가하는 것이 좋습니다.
다음과 같이 개선할 수 있습니다:
-settings = Settings() +try: + settings = Settings() +except Exception as e: + raise RuntimeError(f"설정 초기화 실패: {e}")app/models/fraud_response.py (1)
1-1: 사용하지 않는 import 제거
conint가 import되었지만 사용되지 않습니다.-from pydantic import BaseModel, conint +from pydantic import BaseModel, Field, validatorapp/prompts/fraud_example.py (1)
4-9: 필드 검증 및 문서화 개선현재 모든 필드가 기본 타입으로만 정의되어 있어 검증이 부족합니다. 특히 빈 값이나 잘못된 데이터에 대한 처리가 필요합니다.
다음과 같이 개선할 수 있습니다:
-from pydantic import BaseModel +from pydantic import BaseModel, Field, validator from typing import List class FraudExample(BaseModel): - type_name: str - message_content: str - keywords: List[str] - additional_description: str - image_content: str + type_name: str = Field(..., min_length=1, description="사기 유형명") + message_content: str = Field(..., min_length=1, description="메시지 내용") + keywords: List[str] = Field(..., min_items=1, description="키워드 목록") + additional_description: str = Field(default="", description="추가 설명") + image_content: str = Field(default="", description="이미지 내용") + + @validator('type_name', 'message_content') + def validate_required_fields(cls, v): + if not v.strip(): + raise ValueError('필수 필드는 빈 값일 수 없습니다') + return v.strip()app/services/gpt_service.py (1)
6-8: OpenAI 클라이언트 비동기 초기화 고려현재 동기 클라이언트를 사용하고 있지만, 비동기 함수에서 사용하므로
AsyncOpenAI를 사용하는 것이 더 적절합니다.-from openai import OpenAI, OpenAIError +from openai import AsyncOpenAI, OpenAIError -client = OpenAI( +client = AsyncOpenAI( api_key = settings.gpt_api_key )app/prompts/fraud_prompts.py (1)
10-10: 대량의 예시 데이터 처리 시 성능을 고려하세요.기본값으로
FRAUD_EXAMPLES전체를 사용하고 있는데, 향후 60-70개 예시가 모두 추가되면 토큰 사용량이 크게 증가할 수 있습니다. PR 목표에서도 언급된 우려사항입니다.예시 개수를 제한하는 매개변수를 추가하는 것을 고려해 보세요:
def get_fraud_detection_prompt( message_content: str, additional_description: str, keywords: List[str], image_content: str, examples: List[FraudExample] = FRAUD_EXAMPLES, max_examples: int = 10 # 예시 개수 제한 ) -> List[Dict[str, str]]: # 예시 개수 제한 로직 추가 limited_examples = examples[:max_examples] if max_examples else examples
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (13)
.coderabbit/config.yml(1 hunks).github/workflows/deploy.yml(2 hunks)app/api/fraud_analysis.py(1 hunks)app/config/setting.py(1 hunks)app/main.py(1 hunks)app/models/fraud_request.py(1 hunks)app/models/fraud_response.py(1 hunks)app/prompts/data/fraud_examples.py(1 hunks)app/prompts/fraud_example.py(1 hunks)app/prompts/fraud_prompts.py(1 hunks)app/routers/fraud_analysis.py(0 hunks)app/services/gpt_service.py(1 hunks)requirements.txt(1 hunks)
💤 Files with no reviewable changes (1)
- app/routers/fraud_analysis.py
🧰 Additional context used
🧬 Code Graph Analysis (5)
app/main.py (1)
app/api/fraud_analysis.py (1)
fraud_analysis(13-20)
app/services/gpt_service.py (2)
app/models/fraud_request.py (1)
FraudRequest(4-8)app/prompts/fraud_prompts.py (1)
get_fraud_detection_prompt(5-52)
app/prompts/data/fraud_examples.py (1)
app/prompts/fraud_example.py (1)
FraudExample(4-9)
app/api/fraud_analysis.py (3)
app/services/gpt_service.py (1)
call_gpt(10-32)app/models/fraud_request.py (1)
FraudRequest(4-8)app/models/fraud_response.py (1)
FraudResponse(4-8)
app/prompts/fraud_prompts.py (1)
app/prompts/fraud_example.py (1)
FraudExample(4-9)
🪛 YAMLlint (1.37.1)
.coderabbit/config.yml
[error] 2-2: no new line character at the end of file
(new-line-at-end-of-file)
.github/workflows/deploy.yml
[error] 64-64: no new line character at the end of file
(new-line-at-end-of-file)
🪛 Ruff (0.12.2)
app/services/gpt_service.py
28-28: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
(B904)
app/models/fraud_response.py
1-1: pydantic.conint imported but unused
Remove unused import: pydantic.conint
(F401)
app/api/fraud_analysis.py
20-20: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
(B904)
🪛 GitHub Actions: CI/CD pipeline test
requirements.txt
[error] 4-4: pip install failed: No matching distribution found for click==8.2.1. The required version requires Python >=3.10 but the environment uses Python 3.9.
🔇 Additional comments (10)
app/main.py (2)
2-2: LGTM! 모듈 구조 개선이 잘 반영되었습니다.
app.routers에서app.api로의 import 경로 변경이 새로운 프로젝트 구조를 잘 반영하고 있습니다.
7-7: LGTM! REST API 명명 규칙을 준수합니다.라우터 prefix와 tag에서 언더스코어를 하이픈으로 변경한 것이 REST API 모범 사례를 잘 따르고 있습니다.
requirements.txt (1)
3-22: 검증 결과: 모든 새 패키지는 Python 3.9와 호환됩니다.
- certifi
- distro
- dotenv
- httpcore
- httpx
- jiter
- openai
- pydantic-settings
- tqdm
위 패키지들 모두 Python 3.9에서 요구사항 오류 없이 설치 가능함을 확인했습니다.
따라서 추가 조치는 필요하지 않습니다..github/workflows/deploy.yml (2)
17-17: LGTM! API 키 보안 처리가 적절합니다.GitHub Secrets를 통한 GPT API 키 관리가 보안 모범 사례를 잘 따르고 있습니다.
60-64: LGTM! Docker 컨테이너에 환경 변수 전달이 올바릅니다.Docker run 명령어에서 환경 변수를 안전하게 전달하는 방식이 적절합니다.
app/prompts/data/fraud_examples.py (2)
5-28: 사기 예시 데이터 구조가 잘 설계되었습니다.각 사기 유형별로 적절한 예시 데이터가 제공되고 있으며, 한국어 컨텍스트에 맞는 현실적인 사기 시나리오를 반영하고 있습니다. 키워드와 추가 설명이 프롬프트 엔지니어링에 유용한 컨텍스트를 제공할 것으로 보입니다.
27-27: 데이터 완성도 확인이 필요합니다.주석에서 언급된 18개 유형 × 3
4개 예시 (총 6070개 항목)가 아직 완성되지 않은 상태입니다.전체 데이터셋 완성 계획과 타임라인을 확인해 주세요. 현재 3개 예시만으로는 GPT 모델의 성능이 제한될 수 있습니다.
app/prompts/fraud_prompts.py (3)
5-11: 함수 시그니처가 잘 설계되었습니다.매개변수 타입 힌트와 기본값 설정이 적절하며, 반환 타입도 명확하게 정의되어 있습니다.
13-28: 시스템 프롬프트가 명확하고 구체적입니다.JSON 출력 형식을 명시하고 한국어로 명확한 지시사항을 제공하고 있어 GPT 모델이 일관된 응답을 생성할 수 있을 것으로 보입니다.
54-68: 예시 데이터 포맷팅 로직이 효율적입니다.
build_example_lines함수가 예시 데이터를 일관된 형식으로 변환하고 있으며, JSON 예시도 포함하여 모델의 이해를 돕고 있습니다.
app/api/fraud_analysis.py
Outdated
| try: | ||
| answer = await call_gpt(request) | ||
| response = FraudResponse.model_validate_json(answer) | ||
| return response | ||
|
|
||
| except Exception as e: | ||
| raise HTTPException(status_code=500, detail=f"사기분석 실패: {e}") |
There was a problem hiding this comment.
예외 처리 및 오류 로깅 개선 필요
현재 예외 처리에서 원본 예외 정보가 손실되고, 로깅이 없어 디버깅이 어렵습니다. 또한 JSON 파싱 실패와 GPT API 호출 실패를 구분하여 처리하는 것이 좋습니다.
다음과 같이 개선할 수 있습니다:
+import logging
+
+logger = logging.getLogger(__name__)
+
async def fraud_analysis(request: FraudRequest):
try:
answer = await call_gpt(request)
+ logger.info(f"GPT 응답 수신: {len(answer)} 글자")
+ except Exception as e:
+ logger.error(f"GPT API 호출 실패: {e}", exc_info=True)
+ raise HTTPException(status_code=500, detail=f"GPT API 호출 실패: {e}") from e
+
+ try:
response = FraudResponse.model_validate_json(answer)
return response
-
except Exception as e:
- raise HTTPException(status_code=500, detail=f"사기분석 실패: {e}")
+ logger.error(f"응답 파싱 실패: {e}, 원본 응답: {answer}", exc_info=True)
+ raise HTTPException(status_code=500, detail=f"응답 파싱 실패: {e}") from e📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| try: | |
| answer = await call_gpt(request) | |
| response = FraudResponse.model_validate_json(answer) | |
| return response | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=f"사기분석 실패: {e}") | |
| import logging | |
| logger = logging.getLogger(__name__) | |
| async def fraud_analysis(request: FraudRequest): | |
| try: | |
| answer = await call_gpt(request) | |
| logger.info(f"GPT 응답 수신: {len(answer)} 글자") | |
| except Exception as e: | |
| logger.error(f"GPT API 호출 실패: {e}", exc_info=True) | |
| raise HTTPException(status_code=500, detail=f"GPT API 호출 실패: {e}") from e | |
| try: | |
| response = FraudResponse.model_validate_json(answer) | |
| return response | |
| except Exception as e: | |
| logger.error(f"응답 파싱 실패: {e}, 원본 응답: {answer}", exc_info=True) | |
| raise HTTPException(status_code=500, detail=f"응답 파싱 실패: {e}") from e |
🧰 Tools
🪛 Ruff (0.12.2)
20-20: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
(B904)
🤖 Prompt for AI Agents
In app/api/fraud_analysis.py around lines 14 to 20, the current exception
handling loses the original error details and lacks logging, making debugging
difficult. Improve this by adding proper logging of the caught exceptions and
differentiate between JSON parsing errors and GPT API call failures using
separate except blocks. This will help provide clearer error context and
maintain the original exception information in the HTTPException detail.
| from pydantic_settings import BaseSettings | ||
|
|
||
| class Settings(BaseSettings): | ||
| gpt_api_key: str |
There was a problem hiding this comment.
🛠️ Refactor suggestion
API 키 필드에 대한 검증 강화 필요
API 키는 필수 필드이므로 명시적으로 설정하고 기본값을 제거하는 것이 좋습니다. 또한 빈 문자열 검증도 추가해야 합니다.
다음과 같이 개선할 수 있습니다:
+from pydantic import Field, validator
+
class Settings(BaseSettings):
- gpt_api_key: str
+ gpt_api_key: str = Field(..., min_length=1, description="OpenAI GPT API 키")
+
+ @validator('gpt_api_key')
+ def validate_api_key(cls, v):
+ if not v or not v.strip():
+ raise ValueError('API 키는 필수입니다')
+ return v.strip()📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| gpt_api_key: str | |
| from pydantic import Field, validator | |
| class Settings(BaseSettings): | |
| gpt_api_key: str = Field(..., min_length=1, description="OpenAI GPT API 키") | |
| @validator('gpt_api_key') | |
| def validate_api_key(cls, v): | |
| if not v or not v.strip(): | |
| raise ValueError('API 키는 필수입니다') | |
| return v.strip() |
🤖 Prompt for AI Agents
In app/config/setting.py at line 4, the gpt_api_key field currently lacks
validation and a default value. To fix this, explicitly mark gpt_api_key as a
required field without a default and add validation to ensure it is not an empty
string. This will enforce that the API key must be provided and cannot be empty.
app/models/fraud_request.py
Outdated
| class FraudRequest(BaseModel): | ||
| messageContent: str | ||
| keywords: List[str] | ||
| additionalDescription: str | ||
| imageContent: str No newline at end of file |
There was a problem hiding this comment.
🛠️ Refactor suggestion
필드 검증 및 선택적 필드 고려가 필요합니다.
현재 모든 필드가 필수로 설정되어 있어 API 사용성이 제한될 수 있습니다. 특히 additionalDescription과 imageContent는 선택적으로 만드는 것을 고려해보세요.
from pydantic import BaseModel
from typing import List
+from typing import Optional
class FraudRequest(BaseModel):
messageContent: str
keywords: List[str]
- additionalDescription: str
- imageContent: str
+ additionalDescription: Optional[str] = None
+ imageContent: Optional[str] = None📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| class FraudRequest(BaseModel): | |
| messageContent: str | |
| keywords: List[str] | |
| additionalDescription: str | |
| imageContent: str | |
| from pydantic import BaseModel | |
| from typing import List | |
| from typing import Optional | |
| class FraudRequest(BaseModel): | |
| messageContent: str | |
| keywords: List[str] | |
| additionalDescription: Optional[str] = None | |
| imageContent: Optional[str] = None |
🤖 Prompt for AI Agents
In app/models/fraud_request.py around lines 4 to 8, all fields in the
FraudRequest model are currently required, which limits API usability. Modify
the model to make additionalDescription and imageContent optional by using
typing.Optional and providing default values such as None. Also, consider adding
validation to ensure required fields are properly checked while allowing these
two fields to be omitted.
app/models/fraud_response.py
Outdated
| class FraudResponse(BaseModel): | ||
| estimatedFraudType: str # 분류된 사기 유형 | ||
| keywords: List[str] # 주요 위험 키워드 (최대 3개) | ||
| explanation: str # 해당 유형으로 판단한 이유 | ||
| score: float # 위험도(0~100) No newline at end of file |
There was a problem hiding this comment.
🛠️ Refactor suggestion
필드 검증 로직 강화 필요
주요 필드들에 대한 검증이 부족합니다. 특히 score는 0-100 범위여야 하고, keywords는 최대 3개로 제한되어야 합니다.
다음과 같이 검증을 추가할 수 있습니다:
class FraudResponse(BaseModel):
estimatedFraudType: str # 분류된 사기 유형
- keywords: List[str] # 주요 위험 키워드 (최대 3개)
+ keywords: List[str] = Field(..., min_items=1, max_items=3, description="주요 위험 키워드 (최대 3개)")
explanation: str # 해당 유형으로 판단한 이유
- score: float # 위험도(0~100)
+ score: float = Field(..., ge=0, le=100, description="위험도(0~100)")
+
+ @validator('estimatedFraudType')
+ def validate_fraud_type(cls, v):
+ if not v.strip():
+ raise ValueError('사기 유형은 필수입니다')
+ return v.strip()
+
+ @validator('explanation')
+ def validate_explanation(cls, v):
+ if not v.strip():
+ raise ValueError('설명은 필수입니다')
+ return v.strip()📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| class FraudResponse(BaseModel): | |
| estimatedFraudType: str # 분류된 사기 유형 | |
| keywords: List[str] # 주요 위험 키워드 (최대 3개) | |
| explanation: str # 해당 유형으로 판단한 이유 | |
| score: float # 위험도(0~100) | |
| class FraudResponse(BaseModel): | |
| estimatedFraudType: str # 분류된 사기 유형 | |
| keywords: List[str] = Field( | |
| ..., | |
| min_items=1, | |
| max_items=3, | |
| description="주요 위험 키워드 (최대 3개)" | |
| ) | |
| explanation: str # 해당 유형으로 판단한 이유 | |
| score: float = Field( | |
| ..., | |
| ge=0, | |
| le=100, | |
| description="위험도(0~100)" | |
| ) | |
| @validator('estimatedFraudType') | |
| def validate_fraud_type(cls, v): | |
| if not v.strip(): | |
| raise ValueError('사기 유형은 필수입니다') | |
| return v.strip() | |
| @validator('explanation') | |
| def validate_explanation(cls, v): | |
| if not v.strip(): | |
| raise ValueError('설명은 필수입니다') | |
| return v.strip() |
🤖 Prompt for AI Agents
In app/models/fraud_response.py around lines 4 to 8, the FraudResponse model
lacks validation for key fields. Add validation to ensure the score field is
constrained between 0 and 100, and limit the keywords list to a maximum of 3
items. Use Pydantic validators or field constraints to enforce these rules,
raising appropriate errors if the conditions are not met.
| try: | ||
| response = client.responses.create( | ||
| model="gpt-4o-mini", | ||
| input = messages, | ||
| temperature = 0.5, # 생성된 텍스트의 무작위성을 결정 | ||
| max_output_tokens = 200 | ||
| ) | ||
| print(response) | ||
|
|
||
| except OpenAIError as e: | ||
| raise RuntimeError(f"GPT API 호출 실패: {e}") | ||
| except Exception as e: | ||
| return f"서버 오류 발생: {e}" | ||
|
|
||
| return response.output_text.strip() |
There was a problem hiding this comment.
OpenAI API 호출 방식 및 예외 처리 수정 필요
현재 코드에서 여러 가지 중요한 문제가 있습니다:
client.responses.create는 올바른 OpenAI API 메서드가 아닙니다- 응답 객체의
output_text속성도 존재하지 않습니다 - 예외 처리에서 원본 예외 정보가 손실됩니다
- 프로덕션 코드에 디버깅용 print문이 남아있습니다
다음과 같이 수정해야 합니다:
+import logging
+
+logger = logging.getLogger(__name__)
+
async def call_gpt(request: FraudRequest):
messages = get_fraud_detection_prompt(
message_content = request.messageContent,
additional_description = request.additionalDescription,
keywords = request.keywords,
image_content = request.imageContent
)
try:
- response = client.responses.create(
+ response = await client.chat.completions.create(
model="gpt-4o-mini",
- input = messages,
+ messages=messages,
temperature = 0.5, # 생성된 텍스트의 무작위성을 결정
- max_output_tokens = 200
+ max_tokens=200
)
- print(response)
+ logger.info(f"GPT API 호출 성공, 사용 토큰: {response.usage}")
except OpenAIError as e:
- raise RuntimeError(f"GPT API 호출 실패: {e}")
+ logger.error(f"GPT API 호출 실패: {e}", exc_info=True)
+ raise RuntimeError(f"GPT API 호출 실패: {e}") from e
except Exception as e:
- return f"서버 오류 발생: {e}"
+ logger.error(f"예상치 못한 서버 오류: {e}", exc_info=True)
+ raise RuntimeError(f"서버 오류 발생: {e}") from e
- return response.output_text.strip()
+ return response.choices[0].message.content.strip()📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| try: | |
| response = client.responses.create( | |
| model="gpt-4o-mini", | |
| input = messages, | |
| temperature = 0.5, # 생성된 텍스트의 무작위성을 결정 | |
| max_output_tokens = 200 | |
| ) | |
| print(response) | |
| except OpenAIError as e: | |
| raise RuntimeError(f"GPT API 호출 실패: {e}") | |
| except Exception as e: | |
| return f"서버 오류 발생: {e}" | |
| return response.output_text.strip() | |
| import logging | |
| logger = logging.getLogger(__name__) | |
| async def call_gpt(request: FraudRequest): | |
| messages = get_fraud_detection_prompt( | |
| message_content=request.messageContent, | |
| additional_description=request.additionalDescription, | |
| keywords=request.keywords, | |
| image_content=request.imageContent | |
| ) | |
| try: | |
| response = await client.chat.completions.create( | |
| model="gpt-4o-mini", | |
| messages=messages, | |
| temperature=0.5, # 생성된 텍스트의 무작위성을 결정 | |
| max_tokens=200 | |
| ) | |
| logger.info(f"GPT API 호출 성공, 사용 토큰: {response.usage}") | |
| except OpenAIError as e: | |
| logger.error(f"GPT API 호출 실패: {e}", exc_info=True) | |
| raise RuntimeError(f"GPT API 호출 실패: {e}") from e | |
| except Exception as e: | |
| logger.error(f"예상치 못한 서버 오류: {e}", exc_info=True) | |
| raise RuntimeError(f"서버 오류 발생: {e}") from e | |
| return response.choices[0].message.content.strip() |
🧰 Tools
🪛 Ruff (0.12.2)
28-28: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
(B904)
🤖 Prompt for AI Agents
In app/services/gpt_service.py around lines 18 to 32, the code incorrectly uses
client.responses.create which is not a valid OpenAI API method, and attempts to
access a non-existent output_text attribute on the response. Additionally, the
exception handling loses original error details and there is a leftover print
statement. To fix this, replace client.responses.create with the correct method
for chat completions (e.g., client.chat.completions.create), access the
generated text from the proper response field (like
response.choices[0].message.content), remove the print statement, and update
exception handling to preserve and propagate original error information
properly.
There was a problem hiding this comment.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
requirements.txt(1 hunks)
🔇 Additional comments (1)
requirements.txt (1)
13-13: 이슈 없음: 구버전 OpenAI API 호출 패턴 미발견
전역 검색 결과openai.ChatCompletion.create또는openai.Completion.create호출이 모두 발견되지 않았습니다. 따라서 1.x API 마이그레이션이 완료된 것으로 확인됩니다.
|
수고하셨습니다.!! 최대한 토큰 적게 쓰는 방식으로 잘 학습시키는 방법을 찾아봐야할거같네융.. |
💻 Related Issue
🚀 Work Description
app.prompts.data.fraud_examples에서 유형별 예시 데이터를 관리하며,app.prompts.fraud_prompts에서 프롬프트에 지시사항과 예시데이터를 주입하였습니다.🙇🏻♀️ To Reviewer
➕ Next
Summary by CodeRabbit
신규 기능
환경 설정
버그 수정 및 기타