@umituz/web-ai 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/content/index.cjs +116 -10
- package/dist/content/index.cjs.map +1 -1
- package/dist/content/index.d.cts +1 -1
- package/dist/content/index.d.ts +1 -1
- package/dist/content/index.js +116 -10
- package/dist/content/index.js.map +1 -1
- package/dist/core/index.cjs +10 -0
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +13 -3
- package/dist/core/index.d.ts +13 -3
- package/dist/core/index.js +9 -1
- package/dist/core/index.js.map +1 -1
- package/dist/{create-ai-DXEoke8-.d.ts → create-ai-9PW752z8.d.ts} +11 -1
- package/dist/{create-ai-DOI9jD3v.d.cts → create-ai-CXYKPK6G.d.cts} +11 -1
- package/dist/hooks/index.cjs +272 -10
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +28 -2
- package/dist/hooks/index.d.ts +28 -2
- package/dist/hooks/index.js +272 -11
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.cjs +421 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -4
- package/dist/index.d.ts +5 -4
- package/dist/index.js +402 -11
- package/dist/index.js.map +1 -1
- package/dist/providers/index.cjs +696 -10
- package/dist/providers/index.cjs.map +1 -1
- package/dist/providers/index.d.cts +75 -8
- package/dist/providers/index.d.ts +75 -8
- package/dist/providers/index.js +679 -11
- package/dist/providers/index.js.map +1 -1
- package/dist/text-generation.service-BQO3Tvz2.d.cts +66 -0
- package/dist/text-generation.service-CcYQM6Ch.d.ts +66 -0
- package/package.json +6 -1
package/dist/hooks/index.d.cts
CHANGED
|
@@ -2,11 +2,12 @@ import { B as BlogGenerationRequest, G as GeneratedBlog, b as SocialContentReque
|
|
|
2
2
|
import { A as AIErrorCode, S as SentimentAnalysisResult, C as ContentAnalysisRequest, a as ContentAnalysisResult, b as SEOOptimizationRequest, c as SEOOptimizationResult, d as SEOScoreBreakdown, e as ABTestRequest, f as ABTestPrediction, g as ABTestComparison, G as GenerationResult, h as GenerationProgress, i as GenerationStatus, I as ImageGenerationInput, V as VideoGenerationInput, j as GenerationType, k as ImageQuality, l as VideoQuality } from '../AIErrors-C5EasV_c.cjs';
|
|
3
3
|
import { d as ProviderConfig, I as ImageGenerationRequest, G as GeneratedContent, V as VideoGenerationRequest, a as ImageToVideoRequest, b as VideoToVideoRequest } from '../ProviderConfig-DIFa9nmG.cjs';
|
|
4
4
|
import { f as ITextGenerator, b as ITextProvider, c as ProviderFactory } from '../provider.factory-BxsfK4WW.cjs';
|
|
5
|
-
import { A as AIProviderConfig } from '../create-ai-
|
|
5
|
+
import { A as AIProviderConfig, q as GroqGenerationConfig } from '../create-ai-CXYKPK6G.cjs';
|
|
6
6
|
import { ContentWizardStep, ContentWizardData, ImageWizardStep, ImageWizardData, VideoWizardStep, VideoWizardData } from '../wizard/index.cjs';
|
|
7
7
|
import { c as TextTier } from '../index-fXjxTR5W.cjs';
|
|
8
8
|
import { C as CacheManager, b as CacheStats } from '../cache-manager-Df9LLYGA.cjs';
|
|
9
9
|
import { d as ChatService, U as UseChatOptions, k as UseChatReturn } from '../chat.service-CL1qtYxe.cjs';
|
|
10
|
+
import { c as TextGenerationService } from '../text-generation.service-BQO3Tvz2.cjs';
|
|
10
11
|
import '../index-DKHNcMbl.cjs';
|
|
11
12
|
|
|
12
13
|
/** Provider config for the underlying AIContentService — new AIProviderConfig,
|
|
@@ -207,4 +208,29 @@ interface UseChatDeps {
|
|
|
207
208
|
}
|
|
208
209
|
declare function useChat(options: UseChatOptions, deps?: UseChatDeps): UseChatReturn;
|
|
209
210
|
|
|
210
|
-
|
|
211
|
+
interface UseGroqOptions {
|
|
212
|
+
readonly model?: string;
|
|
213
|
+
readonly generationConfig?: GroqGenerationConfig;
|
|
214
|
+
readonly onStart?: () => void;
|
|
215
|
+
readonly onSuccess?: (result: string) => void;
|
|
216
|
+
readonly onError?: (error: string) => void;
|
|
217
|
+
}
|
|
218
|
+
interface UseGroqReturn {
|
|
219
|
+
readonly isLoading: boolean;
|
|
220
|
+
readonly error: string | null;
|
|
221
|
+
readonly result: string | null;
|
|
222
|
+
generate: (prompt: string, options?: GroqGenerationConfig) => Promise<string | null>;
|
|
223
|
+
generateJSON: <T = Record<string, unknown>>(prompt: string, options?: GroqGenerationConfig & {
|
|
224
|
+
schema?: Record<string, unknown>;
|
|
225
|
+
}) => Promise<T | null>;
|
|
226
|
+
stream: (prompt: string, onChunk: (chunk: string) => void, options?: GroqGenerationConfig) => Promise<string | null>;
|
|
227
|
+
cancel: () => void;
|
|
228
|
+
reset: () => void;
|
|
229
|
+
clearError: () => void;
|
|
230
|
+
}
|
|
231
|
+
interface UseGroqDeps {
|
|
232
|
+
readonly textGeneration?: TextGenerationService;
|
|
233
|
+
}
|
|
234
|
+
declare function useGroq(options?: UseGroqOptions, deps?: UseGroqDeps): UseGroqReturn;
|
|
235
|
+
|
|
236
|
+
export { type ContentWizardRequest, type CreditCheckFunction, type SaveFunction, type UploadFunction, type UseAIContentOptions, type UseAIContentReturn, type UseAIGenerationOptions, type UseAIGenerationReturn, type UseBlogGeneratorOptions, type UseBlogGeneratorReturn, type UseCacheStatsOptions, type UseChatDeps, type UseContentWizardOptions, type UseContentWizardReturn, type UseGroqDeps, type UseGroqOptions, type UseGroqReturn, type UseImageWizardOptions, type UseImageWizardReturn, type UseSocialContentGeneratorOptions, type UseSocialContentGeneratorReturn, type UseTextConfig, type UseTextDeps, type UseTextOptions, type UseTextReturn, type UseVideoWizardOptions, type UseVideoWizardReturn, type VideoWizardRequest, useAIContent, useAIGeneration, useBlogGenerator, useCacheStats, useChat, useContentWizard, useGroq, useImageWizard, useSocialContentGenerator, useText, useVideoWizard };
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -2,11 +2,12 @@ import { B as BlogGenerationRequest, G as GeneratedBlog, b as SocialContentReque
|
|
|
2
2
|
import { A as AIErrorCode, S as SentimentAnalysisResult, C as ContentAnalysisRequest, a as ContentAnalysisResult, b as SEOOptimizationRequest, c as SEOOptimizationResult, d as SEOScoreBreakdown, e as ABTestRequest, f as ABTestPrediction, g as ABTestComparison, G as GenerationResult, h as GenerationProgress, i as GenerationStatus, I as ImageGenerationInput, V as VideoGenerationInput, j as GenerationType, k as ImageQuality, l as VideoQuality } from '../AIErrors-B2ogd1PB.js';
|
|
3
3
|
import { d as ProviderConfig, I as ImageGenerationRequest, G as GeneratedContent, V as VideoGenerationRequest, a as ImageToVideoRequest, b as VideoToVideoRequest } from '../ProviderConfig-DIFa9nmG.js';
|
|
4
4
|
import { f as ITextGenerator, b as ITextProvider, c as ProviderFactory } from '../provider.factory-DfDfk0dK.js';
|
|
5
|
-
import { A as AIProviderConfig } from '../create-ai-
|
|
5
|
+
import { A as AIProviderConfig, q as GroqGenerationConfig } from '../create-ai-9PW752z8.js';
|
|
6
6
|
import { ContentWizardStep, ContentWizardData, ImageWizardStep, ImageWizardData, VideoWizardStep, VideoWizardData } from '../wizard/index.js';
|
|
7
7
|
import { c as TextTier } from '../index-fXjxTR5W.js';
|
|
8
8
|
import { C as CacheManager, b as CacheStats } from '../cache-manager-Df9LLYGA.js';
|
|
9
9
|
import { d as ChatService, U as UseChatOptions, k as UseChatReturn } from '../chat.service-q05GnhEm.js';
|
|
10
|
+
import { c as TextGenerationService } from '../text-generation.service-CcYQM6Ch.js';
|
|
10
11
|
import '../index-DIHz8_OJ.js';
|
|
11
12
|
|
|
12
13
|
/** Provider config for the underlying AIContentService — new AIProviderConfig,
|
|
@@ -207,4 +208,29 @@ interface UseChatDeps {
|
|
|
207
208
|
}
|
|
208
209
|
declare function useChat(options: UseChatOptions, deps?: UseChatDeps): UseChatReturn;
|
|
209
210
|
|
|
210
|
-
|
|
211
|
+
interface UseGroqOptions {
|
|
212
|
+
readonly model?: string;
|
|
213
|
+
readonly generationConfig?: GroqGenerationConfig;
|
|
214
|
+
readonly onStart?: () => void;
|
|
215
|
+
readonly onSuccess?: (result: string) => void;
|
|
216
|
+
readonly onError?: (error: string) => void;
|
|
217
|
+
}
|
|
218
|
+
interface UseGroqReturn {
|
|
219
|
+
readonly isLoading: boolean;
|
|
220
|
+
readonly error: string | null;
|
|
221
|
+
readonly result: string | null;
|
|
222
|
+
generate: (prompt: string, options?: GroqGenerationConfig) => Promise<string | null>;
|
|
223
|
+
generateJSON: <T = Record<string, unknown>>(prompt: string, options?: GroqGenerationConfig & {
|
|
224
|
+
schema?: Record<string, unknown>;
|
|
225
|
+
}) => Promise<T | null>;
|
|
226
|
+
stream: (prompt: string, onChunk: (chunk: string) => void, options?: GroqGenerationConfig) => Promise<string | null>;
|
|
227
|
+
cancel: () => void;
|
|
228
|
+
reset: () => void;
|
|
229
|
+
clearError: () => void;
|
|
230
|
+
}
|
|
231
|
+
interface UseGroqDeps {
|
|
232
|
+
readonly textGeneration?: TextGenerationService;
|
|
233
|
+
}
|
|
234
|
+
declare function useGroq(options?: UseGroqOptions, deps?: UseGroqDeps): UseGroqReturn;
|
|
235
|
+
|
|
236
|
+
export { type ContentWizardRequest, type CreditCheckFunction, type SaveFunction, type UploadFunction, type UseAIContentOptions, type UseAIContentReturn, type UseAIGenerationOptions, type UseAIGenerationReturn, type UseBlogGeneratorOptions, type UseBlogGeneratorReturn, type UseCacheStatsOptions, type UseChatDeps, type UseContentWizardOptions, type UseContentWizardReturn, type UseGroqDeps, type UseGroqOptions, type UseGroqReturn, type UseImageWizardOptions, type UseImageWizardReturn, type UseSocialContentGeneratorOptions, type UseSocialContentGeneratorReturn, type UseTextConfig, type UseTextDeps, type UseTextOptions, type UseTextReturn, type UseVideoWizardOptions, type UseVideoWizardReturn, type VideoWizardRequest, useAIContent, useAIGeneration, useBlogGenerator, useCacheStats, useChat, useContentWizard, useGroq, useImageWizard, useSocialContentGenerator, useText, useVideoWizard };
|
package/dist/hooks/index.js
CHANGED
|
@@ -115,6 +115,14 @@ var AIError = class _AIError extends Error {
|
|
|
115
115
|
}
|
|
116
116
|
};
|
|
117
117
|
|
|
118
|
+
// src/core/errors/groq-error.ts
|
|
119
|
+
var GroqError = class extends AIError {
|
|
120
|
+
constructor(type, message, cause, metadata = {}) {
|
|
121
|
+
super(type, message, cause, metadata);
|
|
122
|
+
this.name = "GroqError";
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
118
126
|
// src/core/errors/error-classifier.ts
|
|
119
127
|
var DEFAULT_RETRYABLE_TYPES = /* @__PURE__ */ new Set([
|
|
120
128
|
"NETWORK_ERROR" /* NETWORK_ERROR */,
|
|
@@ -1339,6 +1347,27 @@ var RequestDeduplicator = class {
|
|
|
1339
1347
|
}
|
|
1340
1348
|
};
|
|
1341
1349
|
|
|
1350
|
+
// src/core/utils/api-key-validator.ts
|
|
1351
|
+
var DEFAULT_API_KEY_RULE = {
|
|
1352
|
+
minLength: 10
|
|
1353
|
+
};
|
|
1354
|
+
function validateApiKey(apiKey, rule = DEFAULT_API_KEY_RULE) {
|
|
1355
|
+
if (!apiKey) {
|
|
1356
|
+
return { valid: false, reason: "API key is required" };
|
|
1357
|
+
}
|
|
1358
|
+
const trimmed = apiKey.trim();
|
|
1359
|
+
if (trimmed.length === 0) {
|
|
1360
|
+
return { valid: false, reason: "API key cannot be empty" };
|
|
1361
|
+
}
|
|
1362
|
+
if (trimmed.length < rule.minLength) {
|
|
1363
|
+
return {
|
|
1364
|
+
valid: false,
|
|
1365
|
+
reason: `API key must be at least ${rule.minLength} characters`
|
|
1366
|
+
};
|
|
1367
|
+
}
|
|
1368
|
+
return { valid: true };
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1342
1371
|
// src/providers/groq/groq.constants.ts
|
|
1343
1372
|
var GROQ_MODELS = {
|
|
1344
1373
|
LLAMA_3_1_8B_INSTANT: "llama-3.1-8b-instant",
|
|
@@ -1355,11 +1384,13 @@ var DEFAULT_GENERATION_CONFIG = {
|
|
|
1355
1384
|
topP: 1
|
|
1356
1385
|
};
|
|
1357
1386
|
var GROQ_BASE_URL = "https://api.groq.com/openai/v1";
|
|
1387
|
+
var DEFAULT_BASE_URL = GROQ_BASE_URL;
|
|
1358
1388
|
var CHAT_COMPLETIONS_PATH = "/chat/completions";
|
|
1359
1389
|
var GROQ_TIMEOUTS = {
|
|
1360
1390
|
DEFAULT: 3e4,
|
|
1361
1391
|
STREAMING: 6e4
|
|
1362
1392
|
};
|
|
1393
|
+
var TIMEOUTS = GROQ_TIMEOUTS;
|
|
1363
1394
|
var HTTP_HEADERS = {
|
|
1364
1395
|
CONTENT_TYPE: "Content-Type",
|
|
1365
1396
|
APPLICATION_JSON: "application/json",
|
|
@@ -1418,13 +1449,65 @@ var GroqChatRequestBuilder = class _GroqChatRequestBuilder {
|
|
|
1418
1449
|
}
|
|
1419
1450
|
};
|
|
1420
1451
|
|
|
1452
|
+
// src/providers/groq/groq-config-store.ts
|
|
1453
|
+
var GroqConfigStore = class {
|
|
1454
|
+
config = null;
|
|
1455
|
+
initialize(config) {
|
|
1456
|
+
const validation = validateApiKey(config.apiKey, { minLength: 1 });
|
|
1457
|
+
if (!validation.valid) {
|
|
1458
|
+
throw new GroqError("INVALID_API_KEY" /* INVALID_API_KEY */, validation.reason ?? "Invalid API key");
|
|
1459
|
+
}
|
|
1460
|
+
const normalized = {
|
|
1461
|
+
apiKey: config.apiKey.trim(),
|
|
1462
|
+
baseUrl: config.baseUrl ?? DEFAULT_BASE_URL,
|
|
1463
|
+
timeoutMs: config.timeoutMs ?? TIMEOUTS.DEFAULT,
|
|
1464
|
+
...config.models !== void 0 ? { models: config.models } : {},
|
|
1465
|
+
...config.textModel !== void 0 ? { textModel: config.textModel } : {}
|
|
1466
|
+
};
|
|
1467
|
+
this.config = normalized;
|
|
1468
|
+
return normalized;
|
|
1469
|
+
}
|
|
1470
|
+
get() {
|
|
1471
|
+
if (!this.config) {
|
|
1472
|
+
throw new GroqError(
|
|
1473
|
+
"MISSING_CONFIG" /* MISSING_CONFIG */,
|
|
1474
|
+
"Client not initialized. Call configureProvider first."
|
|
1475
|
+
);
|
|
1476
|
+
}
|
|
1477
|
+
return this.config;
|
|
1478
|
+
}
|
|
1479
|
+
getOrNull() {
|
|
1480
|
+
return this.config;
|
|
1481
|
+
}
|
|
1482
|
+
isInitialized() {
|
|
1483
|
+
return this.config !== null;
|
|
1484
|
+
}
|
|
1485
|
+
setApiKey(apiKey) {
|
|
1486
|
+
const current = this.get();
|
|
1487
|
+
const validation = validateApiKey(apiKey, { minLength: 1 });
|
|
1488
|
+
if (!validation.valid) {
|
|
1489
|
+
throw new GroqError("INVALID_API_KEY" /* INVALID_API_KEY */, validation.reason ?? "Invalid API key");
|
|
1490
|
+
}
|
|
1491
|
+
this.config = { ...current, apiKey: apiKey.trim() };
|
|
1492
|
+
}
|
|
1493
|
+
reset() {
|
|
1494
|
+
this.config = null;
|
|
1495
|
+
}
|
|
1496
|
+
};
|
|
1497
|
+
|
|
1421
1498
|
// src/providers/groq/groq-http-transport.ts
|
|
1422
1499
|
var GroqHttpTransport = class {
|
|
1423
|
-
constructor(
|
|
1424
|
-
this.
|
|
1500
|
+
constructor(configSource) {
|
|
1501
|
+
this.configSource = configSource;
|
|
1425
1502
|
}
|
|
1426
|
-
|
|
1503
|
+
configSource;
|
|
1427
1504
|
pendingAbortControllers = /* @__PURE__ */ new Set();
|
|
1505
|
+
getConfig() {
|
|
1506
|
+
if ("get" in this.configSource && typeof this.configSource.get === "function") {
|
|
1507
|
+
return this.configSource.get();
|
|
1508
|
+
}
|
|
1509
|
+
return this.configSource;
|
|
1510
|
+
}
|
|
1428
1511
|
cancelPendingRequests() {
|
|
1429
1512
|
for (const controller of this.pendingAbortControllers) {
|
|
1430
1513
|
controller.abort();
|
|
@@ -1439,7 +1522,7 @@ var GroqHttpTransport = class {
|
|
|
1439
1522
|
}
|
|
1440
1523
|
async streamChatCompletion(request, options = {}) {
|
|
1441
1524
|
const url = `${this.baseUrl()}${CHAT_COMPLETIONS_PATH}`;
|
|
1442
|
-
const timeout = this.
|
|
1525
|
+
const timeout = this.getConfig().timeoutMs ?? GROQ_TIMEOUTS.STREAMING;
|
|
1443
1526
|
const controller = new AbortController();
|
|
1444
1527
|
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
1445
1528
|
const onExternalAbort = () => controller.abort();
|
|
@@ -1466,11 +1549,11 @@ var GroqHttpTransport = class {
|
|
|
1466
1549
|
}
|
|
1467
1550
|
}
|
|
1468
1551
|
baseUrl() {
|
|
1469
|
-
return this.
|
|
1552
|
+
return this.getConfig().baseUrl ?? GROQ_BASE_URL;
|
|
1470
1553
|
}
|
|
1471
1554
|
async request(endpoint, body) {
|
|
1472
1555
|
const url = `${this.baseUrl()}${endpoint}`;
|
|
1473
|
-
const timeout = this.
|
|
1556
|
+
const timeout = this.getConfig().timeoutMs ?? GROQ_TIMEOUTS.DEFAULT;
|
|
1474
1557
|
const controller = new AbortController();
|
|
1475
1558
|
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
1476
1559
|
this.pendingAbortControllers.add(controller);
|
|
@@ -1493,7 +1576,7 @@ var GroqHttpTransport = class {
|
|
|
1493
1576
|
buildHeaders() {
|
|
1494
1577
|
return {
|
|
1495
1578
|
[HTTP_HEADERS.CONTENT_TYPE]: HTTP_HEADERS.APPLICATION_JSON,
|
|
1496
|
-
[HTTP_HEADERS.AUTHORIZATION]: `${HTTP_HEADERS.BEARER_PREFIX}${this.
|
|
1579
|
+
[HTTP_HEADERS.AUTHORIZATION]: `${HTTP_HEADERS.BEARER_PREFIX}${this.getConfig().apiKey}`
|
|
1497
1580
|
};
|
|
1498
1581
|
}
|
|
1499
1582
|
async throwFromErrorResponse(response) {
|
|
@@ -1595,21 +1678,40 @@ var CompositeExecutor = class {
|
|
|
1595
1678
|
|
|
1596
1679
|
// src/providers/groq/groq-http-client.ts
|
|
1597
1680
|
var GroqHttpClient = class {
|
|
1681
|
+
configStore;
|
|
1598
1682
|
transport;
|
|
1599
1683
|
executor;
|
|
1600
|
-
constructor(
|
|
1601
|
-
|
|
1684
|
+
constructor(configOrDeps, maybeDeps = {}) {
|
|
1685
|
+
const isConfig = typeof configOrDeps === "object" && configOrDeps !== null && "apiKey" in configOrDeps && typeof configOrDeps.apiKey === "string";
|
|
1686
|
+
const deps = isConfig ? maybeDeps : configOrDeps ?? {};
|
|
1687
|
+
this.configStore = deps.configStore ?? new GroqConfigStore();
|
|
1688
|
+
if (isConfig) {
|
|
1689
|
+
this.configStore.initialize(configOrDeps);
|
|
1690
|
+
}
|
|
1691
|
+
this.transport = deps.transport ?? new GroqHttpTransport(this.configStore);
|
|
1602
1692
|
const retryManager2 = deps.retryManager ?? new RetryManager();
|
|
1603
1693
|
const queue = deps.queue ?? new RequestQueue();
|
|
1604
1694
|
const deduplicator = deps.deduplicator ?? new RequestDeduplicator();
|
|
1605
1695
|
this.executor = new CompositeExecutor([
|
|
1606
1696
|
new DedupeExecutor(deduplicator, {
|
|
1607
|
-
generateKey: (request) => deduplicatorKey(request,
|
|
1697
|
+
generateKey: (request) => deduplicatorKey(request, this.configStore.isInitialized() ? this.configStore.get().apiKey : "")
|
|
1608
1698
|
}),
|
|
1609
1699
|
new RetryExecutor(retryManager2),
|
|
1610
1700
|
new QueueExecutor(queue, QUEUE_PRIORITY_USER_REQUEST)
|
|
1611
1701
|
]);
|
|
1612
1702
|
}
|
|
1703
|
+
initialize(config) {
|
|
1704
|
+
this.configStore.initialize(config);
|
|
1705
|
+
}
|
|
1706
|
+
isInitialized() {
|
|
1707
|
+
return this.configStore.isInitialized();
|
|
1708
|
+
}
|
|
1709
|
+
getApiKey() {
|
|
1710
|
+
return this.configStore.get().apiKey;
|
|
1711
|
+
}
|
|
1712
|
+
setApiKey(apiKey) {
|
|
1713
|
+
this.configStore.setApiKey(apiKey);
|
|
1714
|
+
}
|
|
1613
1715
|
cancelPendingRequests() {
|
|
1614
1716
|
this.transport.cancelPendingRequests();
|
|
1615
1717
|
}
|
|
@@ -1622,6 +1724,10 @@ var GroqHttpClient = class {
|
|
|
1622
1724
|
streamChatCompletion(request, options) {
|
|
1623
1725
|
return this.transport.streamChatCompletion(request, options);
|
|
1624
1726
|
}
|
|
1727
|
+
reset() {
|
|
1728
|
+
this.transport.cancelPendingRequests();
|
|
1729
|
+
this.configStore.reset();
|
|
1730
|
+
}
|
|
1625
1731
|
};
|
|
1626
1732
|
function deduplicatorKey(request, apiKey) {
|
|
1627
1733
|
const { model, messages, stream: _stream, ...rest } = request;
|
|
@@ -5230,6 +5336,161 @@ function useChat(options, deps) {
|
|
|
5230
5336
|
};
|
|
5231
5337
|
}
|
|
5232
5338
|
|
|
5233
|
-
|
|
5339
|
+
// src/providers/groq/groq-container.ts
|
|
5340
|
+
var container = null;
|
|
5341
|
+
function getProvider() {
|
|
5342
|
+
return container;
|
|
5343
|
+
}
|
|
5344
|
+
|
|
5345
|
+
// src/hooks/use-groq.hook.ts
|
|
5346
|
+
function useGroq(options = {}, deps) {
|
|
5347
|
+
const textGeneration = deps?.textGeneration ?? getProvider()?.textGeneration;
|
|
5348
|
+
if (!textGeneration) {
|
|
5349
|
+
throw new Error(
|
|
5350
|
+
"useGroq requires a TextGenerationService dependency. Provide it via the second argument or wire it through configureProvider()."
|
|
5351
|
+
);
|
|
5352
|
+
}
|
|
5353
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
5354
|
+
const [error, setError] = useState(null);
|
|
5355
|
+
const [result, setResult] = useState(null);
|
|
5356
|
+
const optionsRef = useRef(options);
|
|
5357
|
+
optionsRef.current = options;
|
|
5358
|
+
const abortControllerRef = useRef(null);
|
|
5359
|
+
const getOrCreateAbortController = useCallback(() => {
|
|
5360
|
+
if (!abortControllerRef.current || abortControllerRef.current.signal.aborted) {
|
|
5361
|
+
abortControllerRef.current = new AbortController();
|
|
5362
|
+
}
|
|
5363
|
+
return abortControllerRef.current;
|
|
5364
|
+
}, []);
|
|
5365
|
+
const stableConfig = useMemo(
|
|
5366
|
+
() => ({
|
|
5367
|
+
model: options.model,
|
|
5368
|
+
generationConfig: options.generationConfig
|
|
5369
|
+
}),
|
|
5370
|
+
[
|
|
5371
|
+
options.model,
|
|
5372
|
+
options.generationConfig?.temperature,
|
|
5373
|
+
options.generationConfig?.maxTokens,
|
|
5374
|
+
options.generationConfig?.topP
|
|
5375
|
+
]
|
|
5376
|
+
);
|
|
5377
|
+
useEffect(() => {
|
|
5378
|
+
abortControllerRef.current = new AbortController();
|
|
5379
|
+
return () => {
|
|
5380
|
+
abortControllerRef.current?.abort();
|
|
5381
|
+
abortControllerRef.current = null;
|
|
5382
|
+
};
|
|
5383
|
+
}, []);
|
|
5384
|
+
const runWithState = useCallback(
|
|
5385
|
+
async (task) => {
|
|
5386
|
+
const controller = getOrCreateAbortController();
|
|
5387
|
+
const { signal } = controller;
|
|
5388
|
+
if (signal.aborted) return null;
|
|
5389
|
+
setIsLoading(true);
|
|
5390
|
+
setError(null);
|
|
5391
|
+
setResult(null);
|
|
5392
|
+
const currentOptions = optionsRef.current;
|
|
5393
|
+
currentOptions.onStart?.();
|
|
5394
|
+
try {
|
|
5395
|
+
const value = await task(signal);
|
|
5396
|
+
return value;
|
|
5397
|
+
} catch (err) {
|
|
5398
|
+
if (signal.aborted) {
|
|
5399
|
+
return null;
|
|
5400
|
+
}
|
|
5401
|
+
const message = resolveUserFriendlyMessage(err);
|
|
5402
|
+
setError(message);
|
|
5403
|
+
currentOptions.onError?.(message);
|
|
5404
|
+
throw err;
|
|
5405
|
+
} finally {
|
|
5406
|
+
if (!signal.aborted) {
|
|
5407
|
+
setIsLoading(false);
|
|
5408
|
+
}
|
|
5409
|
+
}
|
|
5410
|
+
},
|
|
5411
|
+
[getOrCreateAbortController]
|
|
5412
|
+
);
|
|
5413
|
+
const generate = useCallback(
|
|
5414
|
+
(prompt, config) => runWithState(async () => {
|
|
5415
|
+
const response = await textGeneration.generateCompletion(prompt, {
|
|
5416
|
+
model: stableConfig.model,
|
|
5417
|
+
generationConfig: {
|
|
5418
|
+
...stableConfig.generationConfig,
|
|
5419
|
+
...config
|
|
5420
|
+
}
|
|
5421
|
+
});
|
|
5422
|
+
setResult(response);
|
|
5423
|
+
optionsRef.current.onSuccess?.(response);
|
|
5424
|
+
return response;
|
|
5425
|
+
}),
|
|
5426
|
+
[runWithState, textGeneration, stableConfig]
|
|
5427
|
+
);
|
|
5428
|
+
const generateJSON = useCallback(
|
|
5429
|
+
(prompt, config) => runWithState(async () => {
|
|
5430
|
+
const response = await textGeneration.generateStructured(prompt, {
|
|
5431
|
+
model: stableConfig.model,
|
|
5432
|
+
generationConfig: {
|
|
5433
|
+
...stableConfig.generationConfig,
|
|
5434
|
+
...config
|
|
5435
|
+
},
|
|
5436
|
+
...config?.schema !== void 0 ? { schema: config.schema } : {}
|
|
5437
|
+
});
|
|
5438
|
+
const json = JSON.stringify(response, null, 2);
|
|
5439
|
+
setResult(json);
|
|
5440
|
+
optionsRef.current.onSuccess?.(json);
|
|
5441
|
+
return response;
|
|
5442
|
+
}),
|
|
5443
|
+
[runWithState, textGeneration, stableConfig]
|
|
5444
|
+
);
|
|
5445
|
+
const stream = useCallback(
|
|
5446
|
+
(prompt, onChunk, config) => runWithState(async () => {
|
|
5447
|
+
const callbacks = {
|
|
5448
|
+
onChunk,
|
|
5449
|
+
onComplete: (text) => {
|
|
5450
|
+
setResult(text);
|
|
5451
|
+
optionsRef.current.onSuccess?.(text);
|
|
5452
|
+
}
|
|
5453
|
+
};
|
|
5454
|
+
return textGeneration.streamCompletion(
|
|
5455
|
+
prompt,
|
|
5456
|
+
callbacks,
|
|
5457
|
+
{
|
|
5458
|
+
model: stableConfig.model,
|
|
5459
|
+
generationConfig: {
|
|
5460
|
+
...stableConfig.generationConfig,
|
|
5461
|
+
...config
|
|
5462
|
+
}
|
|
5463
|
+
}
|
|
5464
|
+
);
|
|
5465
|
+
}),
|
|
5466
|
+
[runWithState, textGeneration, stableConfig]
|
|
5467
|
+
);
|
|
5468
|
+
const cancel = useCallback(() => {
|
|
5469
|
+
if (abortControllerRef.current) {
|
|
5470
|
+
abortControllerRef.current.abort();
|
|
5471
|
+
abortControllerRef.current = new AbortController();
|
|
5472
|
+
}
|
|
5473
|
+
setIsLoading(false);
|
|
5474
|
+
}, []);
|
|
5475
|
+
const reset = useCallback(() => {
|
|
5476
|
+
cancel();
|
|
5477
|
+
setError(null);
|
|
5478
|
+
setResult(null);
|
|
5479
|
+
}, [cancel]);
|
|
5480
|
+
const clearError = useCallback(() => setError(null), []);
|
|
5481
|
+
return {
|
|
5482
|
+
isLoading,
|
|
5483
|
+
error,
|
|
5484
|
+
result,
|
|
5485
|
+
generate,
|
|
5486
|
+
generateJSON,
|
|
5487
|
+
stream,
|
|
5488
|
+
cancel,
|
|
5489
|
+
reset,
|
|
5490
|
+
clearError
|
|
5491
|
+
};
|
|
5492
|
+
}
|
|
5493
|
+
|
|
5494
|
+
export { useAIContent, useAIGeneration, useBlogGenerator, useCacheStats, useChat, useContentWizard, useGroq, useImageWizard, useSocialContentGenerator, useText, useVideoWizard };
|
|
5234
5495
|
//# sourceMappingURL=index.js.map
|
|
5235
5496
|
//# sourceMappingURL=index.js.map
|