Merge branch 'main' into FEAT_BoltDYI_NEW_SETTINGS_UI_V2

This commit is contained in:
Stijnus
2025-01-28 10:38:06 +01:00
committed by GitHub
24 changed files with 436 additions and 161 deletions

View File

@@ -63,6 +63,8 @@ async function chatAction({ context, request }: ActionFunctionArgs) {
const totalMessageContent = messages.reduce((acc, message) => acc + message.content, '');
logger.debug(`Total message length: ${totalMessageContent.split(' ').length}, words`);
let lastChunk: string | undefined = undefined;
const dataStream = createDataStream({
async execute(dataStream) {
const filePaths = getFilePaths(files || {});
@@ -247,15 +249,42 @@ async function chatAction({ context, request }: ActionFunctionArgs) {
}
}
})();
result.mergeIntoDataStream(dataStream);
},
onError: (error: any) => `Custom error: ${error.message}`,
}).pipeThrough(
new TransformStream({
transform: (chunk, controller) => {
if (!lastChunk) {
lastChunk = ' ';
}
if (typeof chunk === 'string') {
if (chunk.startsWith('g') && !lastChunk.startsWith('g')) {
controller.enqueue(encoder.encode(`0: "<div class=\\"__boltThought__\\">"\n`));
}
if (lastChunk.startsWith('g') && !chunk.startsWith('g')) {
controller.enqueue(encoder.encode(`0: "</div>\\n"\n`));
}
}
lastChunk = chunk;
let transformedChunk = chunk;
if (typeof chunk === 'string' && chunk.startsWith('g')) {
let content = chunk.split(':').slice(1).join(':');
if (content.endsWith('\n')) {
content = content.slice(0, content.length - 1);
}
transformedChunk = `0:${content}\n`;
}
// Convert the string stream to a byte stream
const str = typeof chunk === 'string' ? chunk : JSON.stringify(chunk);
const str = typeof transformedChunk === 'string' ? transformedChunk : JSON.stringify(transformedChunk);
controller.enqueue(encoder.encode(str));
},
}),

View File

@@ -41,11 +41,17 @@ function getProviderInfo(llmManager: LLMManager) {
export async function loader({
request,
params,
context,
}: {
request: Request;
params: { provider?: string };
context: {
cloudflare?: {
env: Record<string, string>;
};
};
}): Promise<Response> {
const llmManager = LLMManager.getInstance(import.meta.env);
const llmManager = LLMManager.getInstance(context.cloudflare?.env);
// Get client side maintained API keys and provider settings from cookies
const cookieHeader = request.headers.get('Cookie');
@@ -63,7 +69,7 @@ export async function loader({
if (provider) {
const staticModels = provider.staticModels;
const dynamicModels = provider.getDynamicModels
? await provider.getDynamicModels(apiKeys, providerSettings, import.meta.env)
? await provider.getDynamicModels(apiKeys, providerSettings, context.cloudflare?.env)
: [];
modelList = [...staticModels, ...dynamicModels];
}
@@ -72,7 +78,7 @@ export async function loader({
modelList = await llmManager.updateModelList({
apiKeys,
providerSettings,
serverEnv: import.meta.env,
serverEnv: context.cloudflare?.env,
});
}