-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcapture_js_logs.py
More file actions
217 lines (177 loc) · 8.39 KB
/
capture_js_logs.py
File metadata and controls
217 lines (177 loc) · 8.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/usr/bin/env python3
"""
Script para capturar logs del test JavaScript ejecutándolo automáticamente
"""
import requests
import json
import time
def simulate_javascript_execution():
"""Simula la ejecución del test JavaScript desde final_test.html"""
print("🔍 Simulando ejecución del test JavaScript de final_test.html")
print("="*60)
try:
# Paso 1: Verificar backendAPI (simular)
print("✅ backendAPI disponible (simulado)")
# Paso 2: Cargar audio como lo hace el JavaScript
print("📁 Cargando archivo de audio...")
response = requests.get("https://localhost:5037/test/test.wav", verify=False)
if not response.ok:
raise Exception(f"No se pudo cargar test.wav: {response.status_code}")
audio_data = response.content
print(f"📄 Audio cargado: {len(audio_data)} bytes")
# Paso 3: Simular transcribeWithOpenAI
print("🔧 Ejecutando transcribeWithOpenAI...")
mock_config = {
'transcriptionModel': 'gpt-4o-mini-transcribe',
'transcriptionLanguage': 'auto',
'transcriptionPrompt': '',
'streamingEnabled': False,
'transcriptionProvider': 'openai'
}
model = mock_config['transcriptionModel']
print(f"🎯 Modelo seleccionado: {model}")
# Paso 4: Como incluye 'gpt-4o', simular transcribeWithGPT4O
if 'gpt-4o' in model:
print("🔄 Usando GPT-4o transcription...")
# Paso 5: Preparar opciones exactas como el JavaScript
options = {
'model': mock_config['transcriptionModel'],
'language': mock_config['transcriptionLanguage'],
'responseFormat': 'json',
'stream': mock_config['streamingEnabled'] and 'gpt-4o' in mock_config['transcriptionModel']
}
if mock_config['transcriptionPrompt']:
options['prompt'] = mock_config['transcriptionPrompt']
print(f"⚙️ Opciones: {json.dumps(options, indent=2)}")
print(f"🌊 Streaming: {options['stream']}")
# Paso 6: Como stream=False, simular transcripción normal
if not options['stream']:
print("🔄 Usando transcription normal...")
print("📞 Llamando backendAPI.transcribeAudioGPT4O...")
# Esta es la llamada REAL que hace el JavaScript
files = {'audio': ('test.wav', audio_data, 'audio/wav')}
data = {
'model': options['model'],
'response_format': options['responseFormat'],
'stream': 'false'
}
if options['language'] and options['language'] != 'auto':
data['language'] = options['language']
if options.get('prompt'):
data['prompt'] = options['prompt']
print(f"📤 Datos enviados: {data}")
# Hacer la petición EXACTA que hace el JavaScript
api_response = requests.post(
"https://localhost:5037/api/transcribe-gpt4o",
files=files,
data=data,
timeout=30
)
print(f"📊 Respuesta HTTP: {api_response.status_code}")
print(f"📋 Headers: {dict(api_response.headers)}")
if api_response.ok:
result = api_response.json()
transcription = result.get('transcription', '')
print(f"✅ Resultado: {transcription}")
print("🎉 TEST JAVASCRIPT SIMULADO EXITOSO")
return True
else:
error_text = api_response.text
print(f"❌ Error HTTP: {error_text}")
# Intentar parsear error JSON
try:
error_json = api_response.json()
print(f"❌ Error JSON: {json.dumps(error_json, indent=2)}")
except:
print("❌ No se pudo parsear error como JSON")
print("❌ TEST JAVASCRIPT SIMULADO FALLÓ")
return False
else:
print("🌊 Streaming habilitado - requiere implementación específica")
return False
else:
print("🔄 Modelo no es GPT-4o")
return False
except Exception as e:
print(f"❌ Error en simulación: {e}")
print("❌ TEST JAVASCRIPT SIMULADO FALLÓ")
return False
def analyze_potential_frontend_issues():
"""Analiza posibles problemas del frontend"""
print("\n🔍 ANÁLISIS DE POSIBLES PROBLEMAS DEL FRONTEND")
print("="*60)
# 1. Verificar si backend-api.js se carga correctamente
print("1. Verificando backend-api.js...")
try:
response = requests.get("https://localhost:5037/backend-api.js", verify=False)
if response.ok:
print("✅ backend-api.js accesible")
# Verificar contenido básico
content = response.text
if 'class BackendAPI' in content:
print("✅ Clase BackendAPI encontrada")
else:
print("❌ Clase BackendAPI NO encontrada")
if 'transcribeAudioGPT4O' in content:
print("✅ Método transcribeAudioGPT4O encontrado")
else:
print("❌ Método transcribeAudioGPT4O NO encontrado")
else:
print(f"❌ Error cargando backend-api.js: {response.status_code}")
except Exception as e:
print(f"❌ Error verificando backend-api.js: {e}")
# 2. Verificar página principal
print("\n2. Verificando página principal...")
try:
response = requests.get("https://localhost:5037/", verify=False)
if response.ok:
print("✅ Página principal accesible")
content = response.text
if 'backend-api.js' in content:
print("✅ backend-api.js referenciado")
else:
print("❌ backend-api.js NO referenciado")
if 'app.js' in content:
print("✅ app.js referenciado")
else:
print("❌ app.js NO referenciado")
else:
print(f"❌ Error cargando página principal: {response.status_code}")
except Exception as e:
print(f"❌ Error verificando página principal: {e}")
# 3. Verificar headers CORS
print("\n3. Verificando CORS...")
try:
response = requests.get("https://localhost:5037/api/check-apis", verify=False)
cors_headers = {k: v for k, v in response.headers.items() if 'cors' in k.lower() or 'access-control' in k.lower()}
if cors_headers:
print(f"✅ Headers CORS encontrados: {cors_headers}")
else:
print("⚠️ No se encontraron headers CORS específicos")
except Exception as e:
print(f"❌ Error verificando CORS: {e}")
def main():
"""Función principal"""
# Ejecutar simulación del JavaScript
success = simulate_javascript_execution()
# Analizar posibles problemas
analyze_potential_frontend_issues()
print(f"\n📊 RESULTADO FINAL:")
if success:
print("✅ La simulación del JavaScript fue EXITOSA")
print("🎯 El problema puede estar en:")
print(" - Manejo de promesas/async-await")
print(" - Event listeners del frontend")
print(" - Configuración específica del navegador")
print(" - Interferencia de otros scripts")
else:
print("❌ La simulación del JavaScript FALLÓ")
print("🎯 Se encontraron problemas reales en el backend/API")
print("\n📋 RECOMENDACIÓN:")
print("1. Abre https://localhost:5037/final_test.html en el navegador")
print("2. Abre DevTools (F12)")
print("3. Ve a la pestaña Console")
print("4. Haz clic en 'Test Exacto del Frontend Principal'")
print("5. Revisa los mensajes de error en la consola")
if __name__ == "__main__":
main()