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