@blaxel/llamaindex 0.2.50-dev.215 → 0.2.50
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/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/model.js +50 -5
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/model.js +50 -5
- package/package.json +2 -2
package/dist/cjs/model.js
CHANGED
|
@@ -59,12 +59,49 @@ class BlaxelLLM {
|
|
|
59
59
|
}
|
|
60
60
|
async createLLM() {
|
|
61
61
|
await (0, core_1.authenticate)();
|
|
62
|
+
// Capture fresh headers and token after authentication
|
|
63
|
+
// Use getter to ensure we get the latest values
|
|
64
|
+
const currentToken = core_1.settings.token;
|
|
62
65
|
const url = `${core_1.settings.runUrl}/${core_1.settings.workspace}/models/${this.model}`;
|
|
66
|
+
// Custom fetch function that adds authentication headers
|
|
67
|
+
const authenticatedFetch = async (input, init) => {
|
|
68
|
+
await (0, core_1.authenticate)();
|
|
69
|
+
// Get fresh headers after authentication
|
|
70
|
+
const freshHeaders = { ...core_1.settings.headers };
|
|
71
|
+
const headers = {
|
|
72
|
+
...freshHeaders,
|
|
73
|
+
...(init?.headers || {}),
|
|
74
|
+
};
|
|
75
|
+
// Ensure Content-Type is set for JSON requests if body exists and Content-Type is not already set
|
|
76
|
+
if (init?.body && !headers['Content-Type'] && !headers['content-type']) {
|
|
77
|
+
// If body is a string, check if it looks like JSON
|
|
78
|
+
if (typeof init.body === 'string') {
|
|
79
|
+
const trimmed = init.body.trim();
|
|
80
|
+
if (trimmed.startsWith('{') || trimmed.startsWith('[')) {
|
|
81
|
+
headers['Content-Type'] = 'application/json';
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
// For non-string bodies (FormData, Blob, etc.), let fetch handle it
|
|
86
|
+
// For objects, assume JSON
|
|
87
|
+
if (typeof init.body === 'object' && !(init.body instanceof FormData) && !(init.body instanceof Blob)) {
|
|
88
|
+
headers['Content-Type'] = 'application/json';
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return fetch(input, {
|
|
93
|
+
...init,
|
|
94
|
+
headers,
|
|
95
|
+
});
|
|
96
|
+
};
|
|
63
97
|
if (this.type === "mistral") {
|
|
64
98
|
return (0, openai_1.openai)({
|
|
65
99
|
model: this.modelData?.spec?.runtime?.model,
|
|
66
|
-
apiKey:
|
|
100
|
+
apiKey: currentToken,
|
|
67
101
|
baseURL: `${url}/v1`,
|
|
102
|
+
additionalSessionOptions: {
|
|
103
|
+
fetch: authenticatedFetch,
|
|
104
|
+
},
|
|
68
105
|
...this.options,
|
|
69
106
|
});
|
|
70
107
|
}
|
|
@@ -72,11 +109,13 @@ class BlaxelLLM {
|
|
|
72
109
|
// Set a dummy API key to satisfy AnthropicSession constructor requirement
|
|
73
110
|
// The actual authentication is handled via defaultHeaders
|
|
74
111
|
process.env.ANTHROPIC_API_KEY = process.env.ANTHROPIC_API_KEY || "dummy-key-for-blaxel";
|
|
112
|
+
// Get fresh headers right before creating the session
|
|
113
|
+
const anthropicHeaders = { ...core_1.settings.headers };
|
|
75
114
|
const llm = (0, anthropic_1.anthropic)({
|
|
76
115
|
model: this.modelData?.spec?.runtime?.model,
|
|
77
116
|
session: new anthropic_1.AnthropicSession({
|
|
78
117
|
baseURL: url,
|
|
79
|
-
defaultHeaders:
|
|
118
|
+
defaultHeaders: anthropicHeaders,
|
|
80
119
|
}),
|
|
81
120
|
...this.options,
|
|
82
121
|
});
|
|
@@ -135,8 +174,11 @@ class BlaxelLLM {
|
|
|
135
174
|
if (this.type === "cohere") {
|
|
136
175
|
const llm = (0, openai_1.openai)({
|
|
137
176
|
model: this.modelData?.spec?.runtime?.model,
|
|
138
|
-
apiKey:
|
|
139
|
-
baseURL: `${url}/compatibility/v1`,
|
|
177
|
+
apiKey: currentToken,
|
|
178
|
+
baseURL: `${url}/compatibility/v1`, // OpenAI compatibility endpoint
|
|
179
|
+
additionalSessionOptions: {
|
|
180
|
+
fetch: authenticatedFetch,
|
|
181
|
+
},
|
|
140
182
|
...this.options,
|
|
141
183
|
});
|
|
142
184
|
return {
|
|
@@ -159,8 +201,11 @@ class BlaxelLLM {
|
|
|
159
201
|
}
|
|
160
202
|
return (0, openai_1.openai)({
|
|
161
203
|
model: this.modelData?.spec?.runtime?.model,
|
|
162
|
-
apiKey:
|
|
204
|
+
apiKey: currentToken,
|
|
163
205
|
baseURL: `${url}/v1`,
|
|
206
|
+
additionalSessionOptions: {
|
|
207
|
+
fetch: authenticatedFetch,
|
|
208
|
+
},
|
|
164
209
|
...this.options,
|
|
165
210
|
});
|
|
166
211
|
}
|