@node-llm/core 1.12.0 → 1.13.0
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/README.md +1 -1
- package/dist/aliases.d.ts +119 -63
- package/dist/aliases.d.ts.map +1 -1
- package/dist/aliases.js +177 -121
- package/dist/config.d.ts +8 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +15 -1
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +1 -0
- package/dist/llm.d.ts.map +1 -1
- package/dist/llm.js +3 -2
- package/dist/models/models.json +1362 -416
- package/dist/providers/registry.d.ts +2 -1
- package/dist/providers/registry.d.ts.map +1 -1
- package/dist/providers/registry.js +2 -1
- package/dist/providers/xai/Capabilities.d.ts +12 -0
- package/dist/providers/xai/Capabilities.d.ts.map +1 -0
- package/dist/providers/xai/Capabilities.js +79 -0
- package/dist/providers/xai/Chat.d.ts +8 -0
- package/dist/providers/xai/Chat.d.ts.map +1 -0
- package/dist/providers/xai/Chat.js +69 -0
- package/dist/providers/xai/Errors.d.ts +2 -0
- package/dist/providers/xai/Errors.d.ts.map +1 -0
- package/dist/providers/xai/Errors.js +33 -0
- package/dist/providers/xai/Image.d.ts +8 -0
- package/dist/providers/xai/Image.d.ts.map +1 -0
- package/dist/providers/xai/Image.js +47 -0
- package/dist/providers/xai/Models.d.ts +8 -0
- package/dist/providers/xai/Models.d.ts.map +1 -0
- package/dist/providers/xai/Models.js +47 -0
- package/dist/providers/xai/Streaming.d.ts +8 -0
- package/dist/providers/xai/Streaming.d.ts.map +1 -0
- package/dist/providers/xai/Streaming.js +167 -0
- package/dist/providers/xai/XAIProvider.d.ts +37 -0
- package/dist/providers/xai/XAIProvider.d.ts.map +1 -0
- package/dist/providers/xai/XAIProvider.js +66 -0
- package/dist/providers/xai/index.d.ts +7 -0
- package/dist/providers/xai/index.d.ts.map +1 -0
- package/dist/providers/xai/index.js +19 -0
- package/package.json +1 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { BaseProvider } from "../BaseProvider.js";
|
|
2
|
+
import { DEFAULT_XAI_BASE_URL } from "../../constants.js";
|
|
3
|
+
import { XAIChat } from "./Chat.js";
|
|
4
|
+
import { XAIModels } from "./Models.js";
|
|
5
|
+
import { XAIStreaming } from "./Streaming.js";
|
|
6
|
+
import { Capabilities } from "./Capabilities.js";
|
|
7
|
+
import { XAIImage } from "./Image.js";
|
|
8
|
+
export class XAIProvider extends BaseProvider {
|
|
9
|
+
options;
|
|
10
|
+
baseUrl;
|
|
11
|
+
chatHandler;
|
|
12
|
+
streamingHandler;
|
|
13
|
+
modelsHandler;
|
|
14
|
+
imageHandler;
|
|
15
|
+
capabilities = {
|
|
16
|
+
supportsVision: (model) => Capabilities.supportsVision(model),
|
|
17
|
+
supportsTools: (model) => Capabilities.supportsTools(model),
|
|
18
|
+
supportsStructuredOutput: (model) => Capabilities.supportsStructuredOutput(model),
|
|
19
|
+
supportsEmbeddings: (model) => Capabilities.supportsEmbeddings(model),
|
|
20
|
+
supportsImageGeneration: (model) => Capabilities.supportsImageGeneration(model),
|
|
21
|
+
supportsTranscription: (model) => Capabilities.supportsTranscription(model),
|
|
22
|
+
supportsModeration: (model) => Capabilities.supportsModeration(model),
|
|
23
|
+
supportsReasoning: (model) => Capabilities.supportsReasoning(model),
|
|
24
|
+
supportsDeveloperRole: (_model) => false,
|
|
25
|
+
getContextWindow: (model) => Capabilities.getContextWindow(model)
|
|
26
|
+
};
|
|
27
|
+
constructor(options) {
|
|
28
|
+
super();
|
|
29
|
+
this.options = options;
|
|
30
|
+
this.baseUrl = options.baseUrl ?? DEFAULT_XAI_BASE_URL;
|
|
31
|
+
this.chatHandler = new XAIChat(this.baseUrl, options.apiKey);
|
|
32
|
+
this.streamingHandler = new XAIStreaming(this.baseUrl, options.apiKey);
|
|
33
|
+
this.modelsHandler = new XAIModels(this.baseUrl, options.apiKey);
|
|
34
|
+
this.imageHandler = new XAIImage(this.baseUrl, options.apiKey);
|
|
35
|
+
}
|
|
36
|
+
get id() {
|
|
37
|
+
return "xai";
|
|
38
|
+
}
|
|
39
|
+
apiBase() {
|
|
40
|
+
return this.baseUrl;
|
|
41
|
+
}
|
|
42
|
+
headers() {
|
|
43
|
+
return {
|
|
44
|
+
Authorization: `Bearer ${this.options.apiKey}`,
|
|
45
|
+
"Content-Type": "application/json"
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
providerName() {
|
|
49
|
+
return "xAI";
|
|
50
|
+
}
|
|
51
|
+
defaultModel(_feature) {
|
|
52
|
+
return "grok-2";
|
|
53
|
+
}
|
|
54
|
+
async chat(request) {
|
|
55
|
+
return this.chatHandler.execute(request);
|
|
56
|
+
}
|
|
57
|
+
async *stream(request) {
|
|
58
|
+
yield* this.streamingHandler.execute(request);
|
|
59
|
+
}
|
|
60
|
+
async listModels() {
|
|
61
|
+
return this.modelsHandler.execute();
|
|
62
|
+
}
|
|
63
|
+
async paint(request) {
|
|
64
|
+
return this.imageHandler.execute(request);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/xai/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,cAAc,kBAAkB,CAAC;AAEjC;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,CAAC,EAAE,aAAa,QAgBzD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { providerRegistry } from "../registry.js";
|
|
2
|
+
import { XAIProvider } from "./XAIProvider.js";
|
|
3
|
+
export * from "./XAIProvider.js";
|
|
4
|
+
/**
|
|
5
|
+
* Register the xAI provider.
|
|
6
|
+
*/
|
|
7
|
+
export function registerXAIProvider(config) {
|
|
8
|
+
providerRegistry.register("xai", (cfg) => {
|
|
9
|
+
const activeConfig = cfg || config;
|
|
10
|
+
const apiKey = activeConfig?.xaiApiKey;
|
|
11
|
+
if (!apiKey) {
|
|
12
|
+
throw new Error("xAI API key not found. Please provide 'xaiApiKey' in config or set XAI_API_KEY environment variable.");
|
|
13
|
+
}
|
|
14
|
+
return new XAIProvider({
|
|
15
|
+
apiKey,
|
|
16
|
+
baseUrl: activeConfig?.xaiApiBase
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
}
|