mirror of
https://github.com/thecyberlearn/quantum-ai-v3.git
synced 2026-08-18 08:52:58 +00:00
Fix social ads generator network errors and content extraction
## Issues Fixed - Added missing status endpoint for polling mechanism - Fixed content extraction priority to handle ad_copy field and raw_response.output - Corrected include_emoji field handling (form sends 'yes' not 'on') - Updated URL patterns to include proper status and result endpoints ## Technical Changes - Added social_ads_generator_status() view for polling - Updated content extraction priority: ad_copy_content > content > ad_copy > raw_response.output - Fixed boolean field handling for include_emoji checkbox - Consistent with other agents' polling patterns ## URL Updates - Added /status/<uuid:request_id>/ for polling - Added /result/<uuid:request_id>/ for results - Consistent API structure across all agents ## Content Field Priority Based on actual JSON response showing "output" field: 1. ad_copy_content (primary field) 2. content (fallback) 3. ad_copy (model field) 4. raw_response.output (actual webhook response) 5. formatted_ad (processed content) 6. output_text (legacy field) ## Result - Social ads generator now properly handles form submission - Correct content extraction from webhook response - Consistent polling mechanism with other agents - No more network errors during ad generation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
ea944072aa
commit
bfbb7d3515
@ -233,8 +233,12 @@
|
||||
content = result.ad_copy_content;
|
||||
} else if (result.content && typeof result.content === 'string') {
|
||||
content = result.content;
|
||||
} else if (result.formatted_report && typeof result.formatted_report === 'string') {
|
||||
content = result.formatted_report;
|
||||
} else if (result.ad_copy && typeof result.ad_copy === 'string') {
|
||||
content = result.ad_copy;
|
||||
} else if (result.raw_response && result.raw_response.output && typeof result.raw_response.output === 'string') {
|
||||
content = result.raw_response.output;
|
||||
} else if (result.formatted_ad && typeof result.formatted_ad === 'string') {
|
||||
content = result.formatted_ad;
|
||||
} else if (result.output_text && typeof result.output_text === 'string') {
|
||||
content = result.output_text;
|
||||
} else {
|
||||
|
||||
@ -5,5 +5,6 @@ app_name = 'social_ads_generator'
|
||||
|
||||
urlpatterns = [
|
||||
path('', views.social_ads_generator_detail, name='detail'),
|
||||
path('status/<uuid:request_id>/', views.social_ads_generator_result, name='status'),
|
||||
path('status/<uuid:request_id>/', views.social_ads_generator_status, name='status'),
|
||||
path('result/<uuid:request_id>/', views.social_ads_generator_result, name='result'),
|
||||
]
|
||||
@ -37,7 +37,7 @@ def social_ads_generator_detail(request):
|
||||
cost=agent.price,
|
||||
description=request.POST.get('description'),
|
||||
social_platform=request.POST.get('social_platform', 'facebook'),
|
||||
include_emoji=request.POST.get('include_emoji') == 'on',
|
||||
include_emoji=request.POST.get('include_emoji') == 'yes',
|
||||
language=request.POST.get('language', 'English'),
|
||||
)
|
||||
|
||||
@ -124,6 +124,46 @@ class SocialAdsGeneratorProcessView(View):
|
||||
return JsonResponse({'error': str(e)}, status=500)
|
||||
|
||||
|
||||
@login_required
|
||||
def social_ads_generator_status(request, request_id):
|
||||
"""Get status for a specific request (for polling)"""
|
||||
try:
|
||||
agent_request = SocialAdsGeneratorRequest.objects.get(
|
||||
id=request_id,
|
||||
user=request.user
|
||||
)
|
||||
|
||||
if hasattr(agent_request, 'response'):
|
||||
response = agent_request.response
|
||||
# Refresh user to get current wallet balance
|
||||
request.user.refresh_from_db()
|
||||
|
||||
return JsonResponse({
|
||||
'success': response.success,
|
||||
'status': agent_request.status,
|
||||
'content': getattr(response, 'ad_copy', None),
|
||||
'ad_copy_content': getattr(response, 'ad_copy', None),
|
||||
'hashtags': getattr(response, 'hashtags', None),
|
||||
'targeting_suggestions': getattr(response, 'targeting_suggestions', None),
|
||||
'formatted_ad': getattr(response, 'formatted_ad', None),
|
||||
'raw_response': getattr(response, 'raw_response', None),
|
||||
'processing_time': float(response.processing_time) if response.processing_time else None,
|
||||
'error_message': response.error_message,
|
||||
'wallet_balance': float(request.user.wallet_balance)
|
||||
})
|
||||
else:
|
||||
return JsonResponse({
|
||||
'success': False,
|
||||
'status': agent_request.status,
|
||||
'message': 'Processing in progress...'
|
||||
})
|
||||
|
||||
except SocialAdsGeneratorRequest.DoesNotExist:
|
||||
return JsonResponse({'error': 'Request not found'}, status=404)
|
||||
except Exception as e:
|
||||
return JsonResponse({'error': str(e)}, status=500)
|
||||
|
||||
|
||||
@login_required
|
||||
def social_ads_generator_result(request, request_id):
|
||||
"""Get result for a specific request"""
|
||||
@ -142,7 +182,7 @@ def social_ads_generator_result(request, request_id):
|
||||
'success': response.success,
|
||||
'status': agent_request.status,
|
||||
'content': getattr(response, 'ad_copy', None),
|
||||
'ad_copy': getattr(response, 'ad_copy', None),
|
||||
'ad_copy_content': getattr(response, 'ad_copy', None),
|
||||
'hashtags': getattr(response, 'hashtags', None),
|
||||
'targeting_suggestions': getattr(response, 'targeting_suggestions', None),
|
||||
'formatted_ad': getattr(response, 'formatted_ad', None),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user