Compare commits
7 Commits
fix/minima
...
fix/crypto
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4fa9b0456a | ||
|
|
b3ab004447 | ||
| d394bc0857 | |||
|
|
dfa806ab53 | ||
| 3493775b7f | |||
|
|
82645dfb3b | ||
| c17fa243a1 |
@@ -33,7 +33,7 @@ class MiniMaxLLM:
|
|||||||
|
|
||||||
|
|
||||||
class MiniMaxConnector:
|
class MiniMaxConnector:
|
||||||
def __init__(self, api_key: str, model: str = "MiniMax-Text-01"):
|
def __init__(self, api_key: str, model: str = "MiniMax-M2.7"):
|
||||||
self.api_key = api_key
|
self.api_key = api_key
|
||||||
self.model = model
|
self.model = model
|
||||||
|
|
||||||
|
|||||||
@@ -104,11 +104,12 @@ export const api = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async chat(id: string, message: string): Promise<BotChatResponse> {
|
async chat(id: string, message: string, signal?: AbortSignal): Promise<BotChatResponse> {
|
||||||
const response = await fetch(`${API_URL}/bots/${id}/chat`, {
|
const response = await fetch(`${API_URL}/bots/${id}/chat`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: getAuthHeaders(),
|
headers: getAuthHeaders(),
|
||||||
body: JSON.stringify({ message } as BotChatRequest)
|
body: JSON.stringify({ message } as BotChatRequest),
|
||||||
|
signal
|
||||||
});
|
});
|
||||||
return handleResponse<BotChatResponse>(response);
|
return handleResponse<BotChatResponse>(response);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -8,12 +8,25 @@ export interface ChatMessage {
|
|||||||
timestamp: Date;
|
timestamp: Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fallback UUID generator for environments where crypto.randomUUID is not available
|
||||||
|
function generateId(): string {
|
||||||
|
if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
|
||||||
|
return crypto.randomUUID();
|
||||||
|
}
|
||||||
|
// Fallback: simple UUID v4 implementation
|
||||||
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
||||||
|
const r = (Math.random() * 16) | 0;
|
||||||
|
const v = c === 'x' ? r : (r & 0x3) | 0x8;
|
||||||
|
return v.toString(16);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export const chatStore = writable<ChatMessage[]>([]);
|
export const chatStore = writable<ChatMessage[]>([]);
|
||||||
|
|
||||||
export function addMessage(message: Omit<ChatMessage, 'id' | 'timestamp'>) {
|
export function addMessage(message: Omit<ChatMessage, 'id' | 'timestamp'>) {
|
||||||
const newMessage: ChatMessage = {
|
const newMessage: ChatMessage = {
|
||||||
...message,
|
...message,
|
||||||
id: crypto.randomUUID(),
|
id: generateId(),
|
||||||
timestamp: new Date()
|
timestamp: new Date()
|
||||||
};
|
};
|
||||||
chatStore.update(messages => [...messages, newMessage]);
|
chatStore.update(messages => [...messages, newMessage]);
|
||||||
|
|||||||
@@ -44,8 +44,17 @@
|
|||||||
|
|
||||||
isSending = true;
|
isSending = true;
|
||||||
|
|
||||||
|
// Add user's message immediately so it shows even before API response
|
||||||
|
addMessage({ role: 'user', content: message });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await api.bots.chat(botId, message);
|
// Add timeout to prevent hanging requests
|
||||||
|
const controller = new AbortController();
|
||||||
|
const timeoutId = setTimeout(() => controller.abort(), 30000);
|
||||||
|
|
||||||
|
const response = await api.bots.chat(botId, message, controller.signal);
|
||||||
|
clearTimeout(timeoutId);
|
||||||
|
|
||||||
addMessage({ role: 'assistant', content: response.response });
|
addMessage({ role: 'assistant', content: response.response });
|
||||||
|
|
||||||
if (response.strategy_config) {
|
if (response.strategy_config) {
|
||||||
@@ -53,7 +62,11 @@
|
|||||||
setCurrentBot(bot);
|
setCurrentBot(bot);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if (e instanceof Error && e.name === 'AbortError') {
|
||||||
|
addMessage({ role: 'assistant', content: 'Request timed out. Please try again.' });
|
||||||
|
} else {
|
||||||
addMessage({ role: 'assistant', content: 'Sorry, I encountered an error. Please try again.' });
|
addMessage({ role: 'assistant', content: 'Sorry, I encountered an error. Please try again.' });
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
isSending = false;
|
isSending = false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user