Skip to content

♻️ application 패키지 리팩토링#56

Merged
Yeonu-Kim merged 5 commits into
mainfrom
refactor/#55
Jun 23, 2026
Merged

♻️ application 패키지 리팩토링#56
Yeonu-Kim merged 5 commits into
mainfrom
refactor/#55

Conversation

@Yeonu-Kim

Copy link
Copy Markdown
Collaborator

No description provided.

@Yeonu-Kim Yeonu-Kim linked an issue Jun 23, 2026 that may be closed by this pull request
Comment thread app/application/service_impl.py Outdated
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)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이건 S3로 옮겨야함

Comment thread app/application/service_impl.py Outdated
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()

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI 연결 부분도 별도의 패키지로 분리해야 할 듯

Comment thread app/db/seed.py
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


Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import가 왜 이렇게 꼬여있지? 따로 이슈 뽑아서 처리

@Yeonu-Kim Yeonu-Kim merged commit 3f5cb86 into main Jun 23, 2026
2 checks passed
@Yeonu-Kim Yeonu-Kim linked an issue Jun 23, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

blockchain 패키지 리팩토링 application 패키지 리팩토링

1 participant