@blaxel/llamaindex 0.2.49-dev.213 → 0.2.49-dev1

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.
@@ -0,0 +1,3 @@
1
+ import "./telemetry.js";
2
+ export * from "./model.js";
3
+ export * from "./tools.js";
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ require("./telemetry.js");
18
+ __exportStar(require("./model.js"), exports);
19
+ __exportStar(require("./tools.js"), exports);
@@ -0,0 +1,2 @@
1
+ import type { ToolCallLLM, ToolCallLLMMessageOptions } from '@llamaindex/core/llms' with { "resolution-mode": "import" };
2
+ export declare const blModel: (model: string, options?: Record<string, unknown>) => Promise<ToolCallLLM<object, ToolCallLLMMessageOptions>>;
package/dist/model.js ADDED
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.blModel = void 0;
4
+ const core_1 = require("@blaxel/core");
5
+ const anthropic_1 = require("@llamaindex/anthropic");
6
+ const google_1 = require("@llamaindex/google");
7
+ const openai_1 = require("@llamaindex/openai");
8
+ // Custom LLM provider that refreshes auth on each call
9
+ class BlaxelLLM {
10
+ model;
11
+ options;
12
+ modelData;
13
+ type;
14
+ _metadata;
15
+ constructor(model, modelData, options) {
16
+ this.model = model;
17
+ this.modelData = modelData;
18
+ this.options = options;
19
+ this.type = modelData?.spec?.runtime?.type || "openai";
20
+ }
21
+ get supportToolCall() {
22
+ return true;
23
+ }
24
+ get metadata() {
25
+ // Return cached metadata or default values
26
+ if (this._metadata) {
27
+ return this._metadata;
28
+ }
29
+ // Return default values with overrides from options
30
+ return {
31
+ model: this.model,
32
+ temperature: this.options?.temperature ?? 0,
33
+ topP: this.options?.topP ?? 1,
34
+ maxTokens: this.options?.maxTokens ?? undefined,
35
+ contextWindow: this.options?.contextWindow ?? 4096,
36
+ tokenizer: undefined, // Let the underlying LLM handle tokenizer
37
+ structuredOutput: this.options?.structuredOutput ?? false,
38
+ };
39
+ }
40
+ async ensureMetadata() {
41
+ if (!this._metadata) {
42
+ const llm = await this.createLLM();
43
+ this._metadata = llm.metadata;
44
+ }
45
+ }
46
+ async createLLM() {
47
+ await (0, core_1.authenticate)();
48
+ const url = `${core_1.settings.runUrl}/${core_1.settings.workspace}/models/${this.model}`;
49
+ if (this.type === "mistral") {
50
+ return (0, openai_1.openai)({
51
+ model: this.modelData?.spec?.runtime?.model,
52
+ apiKey: core_1.settings.token,
53
+ baseURL: `${url}/v1`,
54
+ ...this.options,
55
+ });
56
+ }
57
+ if (this.type === "anthropic") {
58
+ const llm = (0, anthropic_1.anthropic)({
59
+ model: this.modelData?.spec?.runtime?.model,
60
+ session: new anthropic_1.AnthropicSession({
61
+ baseURL: url,
62
+ defaultHeaders: core_1.settings.headers,
63
+ }),
64
+ ...this.options,
65
+ });
66
+ return {
67
+ ...llm,
68
+ supportToolCall: true,
69
+ };
70
+ }
71
+ if (this.type === "cohere") {
72
+ const llm = (0, openai_1.openai)({
73
+ model: this.modelData?.spec?.runtime?.model,
74
+ apiKey: core_1.settings.token,
75
+ baseURL: `${url}/compatibility/v1`,
76
+ ...this.options,
77
+ });
78
+ return {
79
+ ...llm,
80
+ supportToolCall: true,
81
+ };
82
+ }
83
+ if (this.type === "gemini") {
84
+ process.env.GOOGLE_API_KEY = process.env.GOOGLE_API_KEY || "THIS_IS_A_DUMMY_KEY_FOR_LLAMAINDEX";
85
+ const llm = new google_1.Gemini({
86
+ apiKey: core_1.settings.token,
87
+ model: this.modelData?.spec?.runtime?.model,
88
+ httpOptions: {
89
+ baseUrl: url,
90
+ headers: core_1.settings.headers,
91
+ },
92
+ ...this.options,
93
+ });
94
+ return llm;
95
+ }
96
+ return (0, openai_1.openai)({
97
+ model: this.modelData?.spec?.runtime?.model,
98
+ apiKey: core_1.settings.token,
99
+ baseURL: `${url}/v1`,
100
+ ...this.options,
101
+ });
102
+ }
103
+ async chat(params) {
104
+ await this.ensureMetadata();
105
+ const llm = await this.createLLM();
106
+ // Type guard to handle overloads
107
+ if ('stream' in params && params.stream === true) {
108
+ return llm.chat(params);
109
+ }
110
+ else {
111
+ return llm.chat(params);
112
+ }
113
+ }
114
+ async complete(params) {
115
+ await this.ensureMetadata();
116
+ const llm = await this.createLLM();
117
+ // Type guard to handle overloads
118
+ if ('stream' in params && params.stream === true) {
119
+ return llm.complete(params);
120
+ }
121
+ else {
122
+ return llm.complete(params);
123
+ }
124
+ }
125
+ }
126
+ const blModel = async (model, options) => {
127
+ const modelData = await (0, core_1.getModelMetadata)(model);
128
+ if (!modelData) {
129
+ throw new Error(`Model ${model} not found`);
130
+ }
131
+ try {
132
+ return new BlaxelLLM(model, modelData, options);
133
+ }
134
+ catch (err) {
135
+ (0, core_1.handleDynamicImportError)(err);
136
+ throw err;
137
+ }
138
+ };
139
+ exports.blModel = blModel;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@blaxel/core");
4
+ const instrumentation_1 = require("@opentelemetry/instrumentation");
5
+ // Safely initialize LlamaIndex telemetry instrumentation
6
+ async function initializeTelemetry() {
7
+ try {
8
+ const { LlamaIndexInstrumentation } = await import("@traceloop/instrumentation-llamaindex");
9
+ const llamaindex = new LlamaIndexInstrumentation();
10
+ // Try to enable the instrumentation
11
+ llamaindex.enable();
12
+ (0, instrumentation_1.registerInstrumentations)({
13
+ instrumentations: [llamaindex],
14
+ });
15
+ }
16
+ catch (error) {
17
+ // Log the error but don't crash the application
18
+ core_1.logger.warn("LlamaIndex telemetry instrumentation failed to initialize:", error instanceof Error ? error.message : String(error));
19
+ core_1.logger.warn("Continuing without LlamaIndex-specific telemetry...");
20
+ }
21
+ }
22
+ // Initialize telemetry asynchronously
23
+ initializeTelemetry().catch((error) => {
24
+ core_1.logger.warn("Failed to initialize telemetry:", error instanceof Error ? error.message : String(error));
25
+ });
@@ -0,0 +1,7 @@
1
+ import { ToolOptions } from "@blaxel/core/tools/mcpTool";
2
+ export declare const blTool: (name: string, options?: ToolOptions | number) => Promise<import("llamaindex").FunctionTool<{
3
+ [x: string]: any;
4
+ }, import("llamaindex").JSONValue | Promise<import("llamaindex").JSONValue>, object>[]>;
5
+ export declare const blTools: (names: string[], ms?: number) => Promise<import("llamaindex").FunctionTool<{
6
+ [x: string]: any;
7
+ }, import("llamaindex").JSONValue | Promise<import("llamaindex").JSONValue>, object>[]>;
package/dist/tools.js ADDED
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.blTools = exports.blTool = void 0;
4
+ // @ts-ignore - Required for build time due to missing types in 'llamaindex'
5
+ const core_1 = require("@blaxel/core");
6
+ const llamaindex_1 = require("llamaindex");
7
+ const blTool = async (name, options) => {
8
+ try {
9
+ const blaxelTool = await (0, core_1.getTool)(name, options);
10
+ const tools = blaxelTool.map((t) => {
11
+ // @ts-ignore - Required for build time due to missing types in 'llamaindex'
12
+ return (0, llamaindex_1.tool)(t.call.bind(t), {
13
+ name: t.name,
14
+ description: t.description,
15
+ parameters: t.inputSchema,
16
+ });
17
+ });
18
+ return tools;
19
+ }
20
+ catch (err) {
21
+ (0, core_1.handleDynamicImportError)(err);
22
+ throw err;
23
+ }
24
+ };
25
+ exports.blTool = blTool;
26
+ const blTools = async (names, ms) => {
27
+ const toolArrays = await Promise.all(names.map((n) => (0, exports.blTool)(n, ms)));
28
+ return toolArrays.flat();
29
+ };
30
+ exports.blTools = blTools;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blaxel/llamaindex",
3
- "version": "0.2.49-dev.213",
3
+ "version": "0.2.49-dev1",
4
4
  "description": "Blaxel SDK for TypeScript",
5
5
  "license": "MIT",
6
6
  "author": "Blaxel, INC (https://blaxel.ai)",
@@ -48,7 +48,7 @@
48
48
  "@opentelemetry/instrumentation": "^0.203.0",
49
49
  "@traceloop/instrumentation-llamaindex": "^0.14.0",
50
50
  "llamaindex": "^0.11.13",
51
- "@blaxel/core": "0.2.49-dev.213"
51
+ "@blaxel/core": "0.2.49-dev1"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@eslint/js": "^9.30.1",