♻️ application 패키지 리팩토링#56
Merged
Merged
Conversation
Closed
Yeonu-Kim
commented
Jun 23, 2026
Comment on lines
+53
to
+67
| async def _download_image(image_key: str) -> tuple[bytes, str]: | ||
| def _sync() -> tuple[bytes, str]: | ||
| s3 = boto3.client( | ||
| "s3", | ||
| aws_access_key_id=settings.aws_access_key_id, | ||
| aws_secret_access_key=settings.aws_secret_access_key, | ||
| region_name=settings.aws_region, | ||
| ) | ||
| try: | ||
| resp = s3.get_object(Bucket=settings.s3_private_bucket, Key=image_key) | ||
| except ClientError as e: | ||
| raise AppException(IMAGE_002) from e | ||
| return resp["Body"].read(), str(resp.get("ContentType", "image/jpeg")) | ||
|
|
||
| return await asyncio.get_running_loop().run_in_executor(None, _sync) |
Comment on lines
+70
to
+112
| async def _validate_image_condition(image_key: str, condition: str) -> None: | ||
| image_bytes, content_type = await _download_image(image_key) | ||
| media_type = _to_media_type(content_type) | ||
| encoded = base64.standard_b64encode(image_bytes).decode("utf-8") | ||
|
|
||
| client = anthropic.AsyncAnthropic(api_key=settings.anthropic_api_key) | ||
| response = await client.messages.create( | ||
| model="claude-opus-4-8", | ||
| max_tokens=128, | ||
| messages=[ | ||
| { | ||
| "role": "user", | ||
| "content": [ | ||
| { | ||
| "type": "image", | ||
| "source": { | ||
| "type": "base64", | ||
| "media_type": media_type, | ||
| "data": encoded, | ||
| }, | ||
| }, | ||
| { | ||
| "type": "text", | ||
| "text": ( | ||
| f"이미지가 아래 조건을 충족하는지 판단하세요.\n" | ||
| f"조건: {condition}\n\n" | ||
| "충족하면 'PASS', 충족하지 않으면 'FAIL'로만 응답하세요." | ||
| ), | ||
| }, | ||
| ], | ||
| } | ||
| ], | ||
| ) | ||
|
|
||
| block = response.content[0] | ||
| verdict = ( | ||
| block.text.strip() | ||
| if isinstance(block, anthropic.types.TextBlock) | ||
| else "(non-text block)" | ||
| ) | ||
| logger.warning("[IMAGE_VALIDATION] key=%s verdict=%r", image_key, verdict) | ||
| if not isinstance(block, anthropic.types.TextBlock) or "FAIL" in block.text.upper(): | ||
| raise ImageConditionNotMetError() |
Collaborator
Author
There was a problem hiding this comment.
AI 연결 부분도 별도의 패키지로 분리해야 할 듯
Yeonu-Kim
commented
Jun 23, 2026
Comment on lines
24
to
34
| if not settings.blockchain_rpc_url or not settings.server_private_key: | ||
| return None | ||
| try: | ||
| from app.services.blockchain import deploy_contract | ||
| from app.blockchain.service_impl import BlockchainServiceImpl | ||
|
|
||
| return await deploy_contract() | ||
| return await BlockchainServiceImpl().deploy_contract() | ||
| except Exception: | ||
| logger.exception("[SEED] contract deploy failed, skipping") | ||
| return None | ||
|
|
||
|
|
Collaborator
Author
There was a problem hiding this comment.
import가 왜 이렇게 꼬여있지? 따로 이슈 뽑아서 처리
Closed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.