@juspay/neurolink 9.68.9 → 9.68.11
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/CHANGELOG.md +4 -0
- package/dist/browser/neurolink.min.js +381 -390
- package/dist/lib/providers/huggingFace.d.ts +24 -72
- package/dist/lib/providers/huggingFace.js +46 -294
- package/dist/lib/providers/togetherAi.d.ts +9 -19
- package/dist/lib/providers/togetherAi.js +30 -126
- package/dist/providers/huggingFace.d.ts +24 -72
- package/dist/providers/huggingFace.js +46 -294
- package/dist/providers/togetherAi.d.ts +9 -19
- package/dist/providers/togetherAi.js +30 -126
- package/package.json +1 -1
|
@@ -1,144 +1,60 @@
|
|
|
1
|
-
import { createOpenAI } from "@ai-sdk/openai";
|
|
2
1
|
import { TogetherAIModels } from "../constants/enums.js";
|
|
3
|
-
import { BaseProvider } from "../core/baseProvider.js";
|
|
4
|
-
import { DEFAULT_MAX_STEPS } from "../core/constants.js";
|
|
5
|
-
import { streamAnalyticsCollector } from "../core/streamAnalytics.js";
|
|
6
|
-
import { isNeuroLink } from "../neurolink.js";
|
|
7
|
-
import { createLoggingFetch } from "../utils/loggingFetch.js";
|
|
8
|
-
import { tracers, ATTR, withClientStreamSpan } from "../telemetry/index.js";
|
|
9
2
|
import { AuthenticationError, InvalidModelError, NetworkError, ProviderError, RateLimitError, } from "../types/index.js";
|
|
10
3
|
import { logger } from "../utils/logger.js";
|
|
11
4
|
import { createTogetherAIConfig, getProviderModel, validateApiKey, } from "../utils/providerConfig.js";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { resolveToolChoice } from "../utils/toolChoice.js";
|
|
15
|
-
import { toAnalyticsStreamResult } from "./providerTypeUtils.js";
|
|
16
|
-
import { stepCountIs } from "../utils/tool.js";
|
|
17
|
-
import { streamText } from "../utils/generation.js";
|
|
5
|
+
import { TimeoutError } from "../utils/timeout.js";
|
|
6
|
+
import { OpenAIChatCompletionsProvider } from "./openaiChatCompletionsBase.js";
|
|
18
7
|
const TOGETHER_DEFAULT_BASE_URL = "https://api.together.xyz/v1";
|
|
19
8
|
const getTogetherApiKey = () => validateApiKey(createTogetherAIConfig());
|
|
20
9
|
const getDefaultTogetherModel = () => getProviderModel("TOGETHER_MODEL", TogetherAIModels.LLAMA_3_3_70B_INSTRUCT_TURBO);
|
|
21
10
|
/**
|
|
22
|
-
* Together AI Provider
|
|
11
|
+
* Together AI Provider — direct HTTP, no AI SDK.
|
|
23
12
|
*
|
|
24
13
|
* Hosted open-model gateway at api.together.xyz/v1 (OpenAI-compatible).
|
|
25
14
|
* Llama / Mistral / Qwen / DeepSeek / Gemma / WizardLM available
|
|
26
15
|
* server-less; pass any catalog id via `--model`.
|
|
16
|
+
* All request/stream/tool-loop orchestration lives in
|
|
17
|
+
* `OpenAIChatCompletionsProvider`; this class only declares configuration
|
|
18
|
+
* and provider-specific error mapping.
|
|
27
19
|
*
|
|
28
20
|
* @see https://docs.together.ai/docs/openai-api-compatibility
|
|
29
21
|
*/
|
|
30
|
-
export class TogetherAIProvider extends
|
|
31
|
-
model;
|
|
32
|
-
apiKey;
|
|
33
|
-
baseURL;
|
|
22
|
+
export class TogetherAIProvider extends OpenAIChatCompletionsProvider {
|
|
34
23
|
constructor(modelName, sdk, _region, credentials) {
|
|
35
|
-
const validatedNeurolink = isNeuroLink(sdk) ? sdk : undefined;
|
|
36
|
-
super(modelName, "together-ai", validatedNeurolink);
|
|
37
24
|
const overrideApiKey = credentials?.apiKey?.trim();
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
TOGETHER_DEFAULT_BASE_URL;
|
|
46
|
-
const together = createOpenAI({
|
|
47
|
-
apiKey: this.apiKey,
|
|
48
|
-
baseURL: this.baseURL,
|
|
49
|
-
fetch: createLoggingFetch("together-ai"),
|
|
50
|
-
});
|
|
51
|
-
this.model = together.chat(this.modelName);
|
|
25
|
+
const apiKey = overrideApiKey && overrideApiKey.length > 0
|
|
26
|
+
? overrideApiKey
|
|
27
|
+
: getTogetherApiKey();
|
|
28
|
+
const baseURL = credentials?.baseURL?.trim() ||
|
|
29
|
+
process.env.TOGETHER_BASE_URL?.trim() ||
|
|
30
|
+
TOGETHER_DEFAULT_BASE_URL;
|
|
31
|
+
super("together-ai", modelName, sdk, { baseURL, apiKey });
|
|
52
32
|
logger.debug("Together AI Provider initialized", {
|
|
53
33
|
modelName: this.modelName,
|
|
54
34
|
providerName: this.providerName,
|
|
55
|
-
baseURL: this.baseURL,
|
|
35
|
+
baseURL: this.config.baseURL,
|
|
56
36
|
});
|
|
57
37
|
}
|
|
58
|
-
async executeStream(options, _analysisSchema) {
|
|
59
|
-
return withClientStreamSpan({
|
|
60
|
-
name: "neurolink.provider.stream",
|
|
61
|
-
tracer: tracers.provider,
|
|
62
|
-
attributes: {
|
|
63
|
-
[ATTR.GEN_AI_SYSTEM]: "together-ai",
|
|
64
|
-
[ATTR.GEN_AI_MODEL]: this.modelName,
|
|
65
|
-
[ATTR.GEN_AI_OPERATION]: "stream",
|
|
66
|
-
[ATTR.NL_STREAM_MODE]: true,
|
|
67
|
-
},
|
|
68
|
-
}, async () => this.executeStreamInner(options), (r) => r.stream, (r, wrapped) => ({ ...r, stream: wrapped }));
|
|
69
|
-
}
|
|
70
|
-
async executeStreamInner(options) {
|
|
71
|
-
this.validateStreamOptions(options);
|
|
72
|
-
// Resolve per-call credentials first, then fall back to instance-level.
|
|
73
|
-
const perCallCreds = options.credentials?.together;
|
|
74
|
-
const effectiveApiKey = perCallCreds?.apiKey?.trim() || this.apiKey;
|
|
75
|
-
const effectiveBaseURL = perCallCreds?.baseURL || this.baseURL;
|
|
76
|
-
const startTime = Date.now();
|
|
77
|
-
const timeout = this.getTimeout(options);
|
|
78
|
-
const timeoutController = createTimeoutController(timeout, this.providerName, "stream");
|
|
79
|
-
try {
|
|
80
|
-
const shouldUseTools = !options.disableTools && this.supportsTools();
|
|
81
|
-
const tools = shouldUseTools
|
|
82
|
-
? options.tools || (await this.getAllTools())
|
|
83
|
-
: {};
|
|
84
|
-
const messages = await this.buildMessagesForStream(options);
|
|
85
|
-
// When per-call credentials differ from instance, build a fresh client.
|
|
86
|
-
const hasDifferentCreds = effectiveApiKey !== this.apiKey || effectiveBaseURL !== this.baseURL;
|
|
87
|
-
const model = hasDifferentCreds
|
|
88
|
-
? createOpenAI({
|
|
89
|
-
apiKey: effectiveApiKey,
|
|
90
|
-
baseURL: effectiveBaseURL,
|
|
91
|
-
fetch: createLoggingFetch("together-ai"),
|
|
92
|
-
}).chat(this.modelName)
|
|
93
|
-
: await this.getAISDKModelWithMiddleware(options);
|
|
94
|
-
const result = await streamText({
|
|
95
|
-
model,
|
|
96
|
-
messages,
|
|
97
|
-
temperature: options.temperature,
|
|
98
|
-
maxOutputTokens: options.maxTokens,
|
|
99
|
-
tools,
|
|
100
|
-
stopWhen: stepCountIs(options.maxSteps || DEFAULT_MAX_STEPS),
|
|
101
|
-
toolChoice: resolveToolChoice(options, tools, shouldUseTools),
|
|
102
|
-
abortSignal: composeAbortSignals(options.abortSignal, timeoutController?.controller.signal),
|
|
103
|
-
experimental_telemetry: this.telemetryHandler.getTelemetryConfig(options),
|
|
104
|
-
experimental_repairToolCall: this.getToolCallRepairFn(options),
|
|
105
|
-
onStepFinish: ({ toolCalls, toolResults }) => {
|
|
106
|
-
emitToolEndFromStepFinish(this.neurolink?.getEventEmitter(), toolResults);
|
|
107
|
-
this.handleToolExecutionStorage(toolCalls, toolResults, options, new Date()).catch((error) => {
|
|
108
|
-
logger.warn("[TogetherAIProvider] Failed to store tool executions", {
|
|
109
|
-
provider: this.providerName,
|
|
110
|
-
error: error instanceof Error ? error.message : String(error),
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
},
|
|
114
|
-
});
|
|
115
|
-
timeoutController?.cleanup();
|
|
116
|
-
const transformedStream = this.createTextStream(result);
|
|
117
|
-
const analyticsPromise = streamAnalyticsCollector.createAnalytics(this.providerName, this.modelName, toAnalyticsStreamResult(result), Date.now() - startTime, {
|
|
118
|
-
requestId: `together-stream-${Date.now()}`,
|
|
119
|
-
streamingMode: true,
|
|
120
|
-
});
|
|
121
|
-
return {
|
|
122
|
-
stream: transformedStream,
|
|
123
|
-
provider: this.providerName,
|
|
124
|
-
model: this.modelName,
|
|
125
|
-
analytics: analyticsPromise,
|
|
126
|
-
metadata: { startTime, streamId: `together-${Date.now()}` },
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
catch (error) {
|
|
130
|
-
timeoutController?.cleanup();
|
|
131
|
-
throw this.handleProviderError(error);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
38
|
getProviderName() {
|
|
135
|
-
return
|
|
39
|
+
return "together-ai";
|
|
136
40
|
}
|
|
137
41
|
getDefaultModel() {
|
|
138
42
|
return getDefaultTogetherModel();
|
|
139
43
|
}
|
|
140
|
-
|
|
141
|
-
return
|
|
44
|
+
getFallbackModelName() {
|
|
45
|
+
return TogetherAIModels.LLAMA_3_1_8B_INSTRUCT_TURBO;
|
|
46
|
+
}
|
|
47
|
+
getFallbackModels() {
|
|
48
|
+
return [
|
|
49
|
+
TogetherAIModels.LLAMA_3_3_70B_INSTRUCT_TURBO,
|
|
50
|
+
TogetherAIModels.LLAMA_3_1_405B_INSTRUCT_TURBO,
|
|
51
|
+
TogetherAIModels.LLAMA_3_1_70B_INSTRUCT_TURBO,
|
|
52
|
+
TogetherAIModels.LLAMA_3_1_8B_INSTRUCT_TURBO,
|
|
53
|
+
TogetherAIModels.MIXTRAL_8X22B_INSTRUCT,
|
|
54
|
+
TogetherAIModels.QWEN_2_5_72B_INSTRUCT_TURBO,
|
|
55
|
+
TogetherAIModels.DEEPSEEK_R1,
|
|
56
|
+
TogetherAIModels.DEEPSEEK_V3,
|
|
57
|
+
];
|
|
142
58
|
}
|
|
143
59
|
formatProviderError(error) {
|
|
144
60
|
if (error instanceof TimeoutError) {
|
|
@@ -161,17 +77,5 @@ export class TogetherAIProvider extends BaseProvider {
|
|
|
161
77
|
}
|
|
162
78
|
return new ProviderError(`Together AI error: ${message}`, "together-ai");
|
|
163
79
|
}
|
|
164
|
-
async validateConfiguration() {
|
|
165
|
-
return typeof this.apiKey === "string" && this.apiKey.trim().length > 0;
|
|
166
|
-
}
|
|
167
|
-
getConfiguration() {
|
|
168
|
-
return {
|
|
169
|
-
provider: this.providerName,
|
|
170
|
-
model: this.modelName,
|
|
171
|
-
defaultModel: getDefaultTogetherModel(),
|
|
172
|
-
baseURL: this.baseURL,
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
80
|
}
|
|
176
|
-
export default TogetherAIProvider;
|
|
177
81
|
//# sourceMappingURL=togetherAi.js.map
|
|
@@ -1,79 +1,31 @@
|
|
|
1
|
-
import type { ZodType } from "zod";
|
|
2
1
|
import type { AIProviderName } from "../constants/enums.js";
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import type { LanguageModel, Schema } from "../types/index.js";
|
|
2
|
+
import type { NeurolinkCredentials } from "../types/index.js";
|
|
3
|
+
import { OpenAIChatCompletionsProvider } from "./openaiChatCompletionsBase.js";
|
|
6
4
|
/**
|
|
7
|
-
* HuggingFace Provider
|
|
8
|
-
*
|
|
5
|
+
* HuggingFace Provider — direct HTTP, no AI SDK.
|
|
6
|
+
*
|
|
7
|
+
* OpenAI-compatible chat completions at router.huggingface.co/v1 (unified
|
|
8
|
+
* router endpoint, 2025). Supports the full HuggingFace model hub including
|
|
9
|
+
* Llama 3.x, Qwen 2.5, Mistral, DeepSeek, and tool-calling capable variants.
|
|
10
|
+
* All request/stream/tool-loop orchestration lives in
|
|
11
|
+
* `OpenAIChatCompletionsProvider`; this class only declares configuration
|
|
12
|
+
* and provider-specific error mapping.
|
|
13
|
+
*
|
|
14
|
+
* @see https://huggingface.co/docs/api-inference/index
|
|
9
15
|
*/
|
|
10
|
-
export declare class HuggingFaceProvider extends
|
|
11
|
-
|
|
12
|
-
|
|
16
|
+
export declare class HuggingFaceProvider extends OpenAIChatCompletionsProvider {
|
|
17
|
+
constructor(modelName?: string, sdk?: unknown, credentials?: NeurolinkCredentials["huggingFace"]);
|
|
18
|
+
protected getProviderName(): AIProviderName;
|
|
19
|
+
protected getDefaultModel(): string;
|
|
20
|
+
protected getFallbackModelName(): string;
|
|
13
21
|
/**
|
|
14
|
-
* HuggingFace
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* - nvidia/Llama-3.1-Nemotron-Ultra-253B-v1 - Optimized for tool calling
|
|
21
|
-
* - NousResearch/Hermes-3-Llama-3.2-3B - Function calling trained
|
|
22
|
-
* - codellama/CodeLlama-34b-Instruct-hf - Code-focused tool calling
|
|
23
|
-
* - mistralai/Mistral-7B-Instruct-v0.3 - Basic tool support
|
|
24
|
-
*
|
|
25
|
-
* **Unsupported Models (Tool Calling Disabled):**
|
|
26
|
-
* - microsoft/DialoGPT-* - Treats tools as conversation context
|
|
27
|
-
* - gpt2, bert, roberta variants - No tool calling training
|
|
28
|
-
* - Most pre-2024 models - Limited function calling capabilities
|
|
29
|
-
*
|
|
30
|
-
* **Implementation Details:**
|
|
31
|
-
* - Intelligent model detection based on known capabilities
|
|
32
|
-
* - Custom tool schema formatting for HuggingFace models
|
|
33
|
-
* - Enhanced response parsing for function call extraction
|
|
34
|
-
* - Graceful fallback for unsupported models
|
|
35
|
-
*
|
|
36
|
-
* @returns true for supported models, false for unsupported models
|
|
22
|
+
* HuggingFace serves a huge variety of models, many of which reject the
|
|
23
|
+
* OpenAI `tools` field. The base reports supportsTools() === true
|
|
24
|
+
* unconditionally, which would merge tools into requests for models
|
|
25
|
+
* (including the default DialoGPT-medium) that don't accept them. Preserve
|
|
26
|
+
* the pre-migration allowlist: only known tool-calling-capable model
|
|
27
|
+
* families opt in; everything else runs tool-free.
|
|
37
28
|
*/
|
|
38
29
|
supportsTools(): boolean;
|
|
39
|
-
protected
|
|
40
|
-
/**
|
|
41
|
-
* Prepare stream options with HuggingFace-specific enhancements
|
|
42
|
-
* Handles tool calling optimizations and model-specific formatting
|
|
43
|
-
*/
|
|
44
|
-
private prepareStreamOptions;
|
|
45
|
-
/**
|
|
46
|
-
* Enhance system prompt with tool calling instructions for HuggingFace models
|
|
47
|
-
* Many HF models benefit from explicit tool calling guidance
|
|
48
|
-
*/
|
|
49
|
-
private enhanceSystemPromptForTools;
|
|
50
|
-
/**
|
|
51
|
-
* Format tools for HuggingFace model compatibility
|
|
52
|
-
* Some models require specific tool schema formatting
|
|
53
|
-
*/
|
|
54
|
-
private formatToolsForHuggingFace;
|
|
55
|
-
/**
|
|
56
|
-
* Get recommendations for tool-calling capable HuggingFace models
|
|
57
|
-
* Provides guidance for users who want to use function calling
|
|
58
|
-
*/
|
|
59
|
-
static getToolCallingRecommendations(): {
|
|
60
|
-
recommended: string[];
|
|
61
|
-
performance: Record<string, {
|
|
62
|
-
speed: number;
|
|
63
|
-
quality: number;
|
|
64
|
-
cost: number;
|
|
65
|
-
}>;
|
|
66
|
-
notes: Record<string, string>;
|
|
67
|
-
};
|
|
68
|
-
/**
|
|
69
|
-
* Enhanced error handling with HuggingFace-specific guidance
|
|
70
|
-
*/
|
|
71
|
-
formatProviderError(error: unknown): Error;
|
|
72
|
-
getProviderName(): AIProviderName;
|
|
73
|
-
getDefaultModel(): string;
|
|
74
|
-
/**
|
|
75
|
-
* Returns the Vercel AI SDK model instance for HuggingFace
|
|
76
|
-
*/
|
|
77
|
-
getAISDKModel(): LanguageModel;
|
|
30
|
+
protected formatProviderError(error: unknown): Error;
|
|
78
31
|
}
|
|
79
|
-
export default HuggingFaceProvider;
|