Actualización: mejoras en ChatInterface, API, backend y nuevos archivos de diagnóstico/testing
This commit is contained in:
@@ -56,7 +56,9 @@ export default function ChatInterface() {
|
||||
|
||||
try {
|
||||
// Send message to AI
|
||||
console.log('Sending message to API:', currentInput);
|
||||
const aiResponse = await apiService.sendChatMessage(currentInput);
|
||||
console.log('Received response:', aiResponse);
|
||||
|
||||
const aiMessage: Message = {
|
||||
id: (Date.now() + 1).toString(),
|
||||
@@ -95,7 +97,12 @@ export default function ChatInterface() {
|
||||
setMessages((prev) => [...prev, successMessage]);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
console.error('Error in handleSend:', error);
|
||||
console.error('Error details:', {
|
||||
message: error instanceof Error ? error.message : error,
|
||||
stack: error instanceof Error ? error.stack : undefined,
|
||||
name: error instanceof Error ? error.name : typeof error
|
||||
});
|
||||
const errorMessage: Message = {
|
||||
id: (Date.now() + 2).toString(),
|
||||
content: 'Lo siento, hubo un error al procesar tu solicitud. Por favor, intenta de nuevo.',
|
||||
|
||||
@@ -3,9 +3,7 @@
|
||||
* Handles all communication with the FastAPI backend
|
||||
*/
|
||||
|
||||
const API_BASE_URL = typeof window !== 'undefined'
|
||||
? `${window.location.protocol}//${window.location.hostname}:8000`
|
||||
: 'http://localhost:8000';
|
||||
const API_BASE_URL = 'http://localhost:8000';
|
||||
|
||||
export interface ChatMessageRequest {
|
||||
user_id: string;
|
||||
@@ -52,6 +50,7 @@ class ApiService {
|
||||
*/
|
||||
async sendChatMessage(message: string): Promise<ChatMessageResponse> {
|
||||
try {
|
||||
console.log('API Service: Sending request to', `${API_BASE_URL}/api/chat`);
|
||||
const response = await fetch(`${API_BASE_URL}/api/chat`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -63,11 +62,15 @@ class ApiService {
|
||||
} as ChatMessageRequest),
|
||||
});
|
||||
|
||||
console.log('API Service: Response status:', response.status, response.statusText);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Chat request failed: ${response.statusText}`);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
const json = await response.json();
|
||||
console.log('API Service: Response JSON:', json);
|
||||
return json;
|
||||
} catch (error) {
|
||||
console.error('Chat API Error:', error);
|
||||
throw error;
|
||||
|
||||
Reference in New Issue
Block a user