no test connection
Browse files
src/lib/services/textGenerationClient.ts
CHANGED
|
@@ -29,84 +29,20 @@ class TextGenerationManager {
|
|
| 29 |
}
|
| 30 |
|
| 31 |
/**
|
| 32 |
-
*
|
| 33 |
*/
|
| 34 |
async initialize(): Promise<void> {
|
| 35 |
if (this.connectionTested) return;
|
| 36 |
|
| 37 |
-
console.log('
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
// Add timeout wrapper for connection test
|
| 42 |
-
const connectionTestPromise = this.primaryClient.testConnection();
|
| 43 |
-
const timeoutPromise = new Promise<boolean>((_, reject) => {
|
| 44 |
-
setTimeout(() => reject(new Error('Connection test timeout')), 15000); // 15 second timeout
|
| 45 |
-
});
|
| 46 |
-
|
| 47 |
-
const qwen3Available = await Promise.race([connectionTestPromise, timeoutPromise]);
|
| 48 |
-
|
| 49 |
-
if (qwen3Available) {
|
| 50 |
-
console.log('β
Qwen3 client is available and will be used for text generation');
|
| 51 |
-
this.useQwen3 = true;
|
| 52 |
-
|
| 53 |
-
// Perform a secondary validation test to ensure real functionality
|
| 54 |
-
await this.performSecondaryValidation();
|
| 55 |
-
} else {
|
| 56 |
-
console.log('β οΈ Qwen3 client is not available, falling back to Zephyr-7B');
|
| 57 |
-
this.useQwen3 = false;
|
| 58 |
-
}
|
| 59 |
-
}
|
| 60 |
-
} catch (error) {
|
| 61 |
-
console.error('Failed to test Qwen3 connection:', error);
|
| 62 |
-
console.log('β οΈ Falling back to Zephyr-7B due to connection error');
|
| 63 |
-
this.useQwen3 = false;
|
| 64 |
-
}
|
| 65 |
-
|
| 66 |
this.connectionTested = true;
|
|
|
|
|
|
|
| 67 |
}
|
| 68 |
|
| 69 |
-
/**
|
| 70 |
-
* Perform secondary validation to ensure Qwen3 is actually working
|
| 71 |
-
*/
|
| 72 |
-
private async performSecondaryValidation(): Promise<void> {
|
| 73 |
-
try {
|
| 74 |
-
console.log('π§ Performing secondary validation of Qwen3 functionality...');
|
| 75 |
-
|
| 76 |
-
// Test with a specific request that should return predictable content
|
| 77 |
-
const validationResult = await Promise.race([
|
| 78 |
-
this.primaryClient.predict('/chat', [
|
| 79 |
-
'Respond with exactly this text: "VALIDATION_SUCCESS"',
|
| 80 |
-
[],
|
| 81 |
-
'You are a helpful assistant. Follow instructions exactly as given.',
|
| 82 |
-
20, // Very small token limit
|
| 83 |
-
0.1, // Low temperature for deterministic output
|
| 84 |
-
0.9,
|
| 85 |
-
10,
|
| 86 |
-
1.0
|
| 87 |
-
]),
|
| 88 |
-
new Promise<any>((_, reject) => {
|
| 89 |
-
setTimeout(() => reject(new Error('Validation timeout')), 10000); // 10 second timeout
|
| 90 |
-
})
|
| 91 |
-
]);
|
| 92 |
-
|
| 93 |
-
const response = validationResult?.data?.[0] || '';
|
| 94 |
-
const isValidResponse = typeof response === 'string' &&
|
| 95 |
-
response.length > 0 &&
|
| 96 |
-
!response.includes('temporarily unavailable') &&
|
| 97 |
-
!response.includes('using_fallback');
|
| 98 |
-
|
| 99 |
-
if (!isValidResponse) {
|
| 100 |
-
console.warn('β οΈ Secondary validation failed - Qwen3 responses seem invalid, switching to fallback');
|
| 101 |
-
this.useQwen3 = false;
|
| 102 |
-
} else {
|
| 103 |
-
console.log('β
Secondary validation passed - Qwen3 is fully functional');
|
| 104 |
-
}
|
| 105 |
-
} catch (error) {
|
| 106 |
-
console.warn('β οΈ Secondary validation failed with error, switching to fallback:', error);
|
| 107 |
-
this.useQwen3 = false;
|
| 108 |
-
}
|
| 109 |
-
}
|
| 110 |
|
| 111 |
/**
|
| 112 |
* Get the active client for text generation
|
|
@@ -123,7 +59,7 @@ class TextGenerationManager {
|
|
| 123 |
}
|
| 124 |
|
| 125 |
/**
|
| 126 |
-
* Predict method with automatic fallback
|
| 127 |
*/
|
| 128 |
async predict(endpoint: string, params: any[]): Promise<{data: any[]}> {
|
| 129 |
// Ensure initialization has been attempted
|
|
@@ -144,11 +80,12 @@ class TextGenerationManager {
|
|
| 144 |
|
| 145 |
// If primary client fails and we have a fallback, try it
|
| 146 |
if (this.useQwen3 && this.fallbackClient) {
|
| 147 |
-
console.log('π Qwen3 failed,
|
| 148 |
try {
|
| 149 |
const fallbackResult = await this.fallbackClient.predict(endpoint, params);
|
| 150 |
// Mark for future calls to use fallback
|
| 151 |
this.useQwen3 = false;
|
|
|
|
| 152 |
return fallbackResult;
|
| 153 |
} catch (fallbackError) {
|
| 154 |
console.error('Fallback client also failed:', fallbackError);
|
|
|
|
| 29 |
}
|
| 30 |
|
| 31 |
/**
|
| 32 |
+
* Initialize without testing - assume Qwen3 is available and test on first real use
|
| 33 |
*/
|
| 34 |
async initialize(): Promise<void> {
|
| 35 |
if (this.connectionTested) return;
|
| 36 |
|
| 37 |
+
console.log('π§ Initializing text generation manager - using Qwen3 but will fallback to Zephyr-7B on failure');
|
| 38 |
|
| 39 |
+
// Default to using Qwen3, test will happen on first predict() call
|
| 40 |
+
this.useQwen3 = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
this.connectionTested = true;
|
| 42 |
+
|
| 43 |
+
console.log('β
Text generation manager initialized - ready to use Qwen3 (with fallback to Zephyr-7B)');
|
| 44 |
}
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
/**
|
| 48 |
* Get the active client for text generation
|
|
|
|
| 59 |
}
|
| 60 |
|
| 61 |
/**
|
| 62 |
+
* Predict method with automatic fallback - tests on first failure
|
| 63 |
*/
|
| 64 |
async predict(endpoint: string, params: any[]): Promise<{data: any[]}> {
|
| 65 |
// Ensure initialization has been attempted
|
|
|
|
| 80 |
|
| 81 |
// If primary client fails and we have a fallback, try it
|
| 82 |
if (this.useQwen3 && this.fallbackClient) {
|
| 83 |
+
console.log('π Qwen3 failed, switching to fallback Zephyr-7B...');
|
| 84 |
try {
|
| 85 |
const fallbackResult = await this.fallbackClient.predict(endpoint, params);
|
| 86 |
// Mark for future calls to use fallback
|
| 87 |
this.useQwen3 = false;
|
| 88 |
+
console.log('β
Fallback to Zephyr-7B successful - will use Zephyr-7B for future requests');
|
| 89 |
return fallbackResult;
|
| 90 |
} catch (fallbackError) {
|
| 91 |
console.error('Fallback client also failed:', fallbackError);
|