Finalize WEB UI V2 loose endsfixes

This commit is contained in:
jmd1010
2025-04-12 17:15:14 -04:00
parent 13e9d22ec6
commit 3d2903cb47
10 changed files with 217 additions and 33 deletions

View File

@@ -305,10 +305,11 @@ async function readFileContent(file: File): Promise<string> {
}
}
// Centralized language instruction logic in ChatService.ts; YouTube flow now passes plain transcript and system prompt
async function processYouTubeURL(input: string) {
console.log('\n=== YouTube Flow Start ===');
const originalLanguage = get(languageStore);
try {
// Add processing message first
messageStore.update(messages => [...messages, {
@@ -316,16 +317,11 @@ async function readFileContent(file: File): Promise<string> {
content: 'Processing YouTube video...',
format: 'loading'
}]);
// Get transcript but don't display it
const { transcript } = await getTranscript(input);
// Log system prompt BEFORE createChatRequest
console.log('System prompt BEFORE createChatRequest in YouTube flow:', $systemPrompt);
// Log system prompt BEFORE streamChat
console.log(`System prompt BEFORE streamChat in YouTube flow: ${$systemPrompt}`);
// Pass plain transcript and system prompt; ChatService will handle language instruction
const stream = await chatService.streamChat(transcript, $systemPrompt);
await chatService.processStream(
stream,

View File

@@ -15,23 +15,31 @@
});
// Watch selectedPreset changes
$: if (selectedPreset) {
console.log('Pattern selected from dropdown:', selectedPreset);
// Always call selectPattern when the dropdown value changes.
// The patternAPI.selectPattern function handles empty strings correctly.
$: {
// Log the change regardless of the value
console.log('Dropdown selection changed to:', selectedPreset);
try {
// Call the function to select the pattern (or reset if selectedPreset is empty)
patternAPI.selectPattern(selectedPreset);
// Verify the selection
// Optional: Keep verification logs if helpful for debugging
const currentSystemPrompt = get(systemPrompt);
const currentPattern = get(selectedPatternName);
console.log('After dropdown selection - Pattern:', currentPattern);
console.log('After dropdown selection - System Prompt length:', currentSystemPrompt?.length);
if (!currentPattern || !currentSystemPrompt) {
console.error('Pattern selection verification failed:');
console.error('- Selected Pattern:', currentPattern);
console.error('- System Prompt:', currentSystemPrompt);
}
// Optional: Refine verification logic if needed
// For example, only log error if a pattern was expected but not set
// if (selectedPreset && (!currentPattern || !currentSystemPrompt)) {
// console.error('Pattern selection verification failed:');
// console.error('- Selected Pattern:', currentPattern);
// console.error('- System Prompt:', currentSystemPrompt);
// }
} catch (error) {
console.error('Error in pattern selection:', error);
// Log any errors during the pattern selection process
console.error('Error processing pattern selection:', error);
}
}

View File

@@ -24,6 +24,7 @@ export interface ChatRequest {
top_p: number;
frequency_penalty: number;
presence_penalty: number;
language?: string;
}
export interface Message {

View File

@@ -48,6 +48,8 @@ export class ChatService {
promptCount: request.prompts?.length,
messageCount: request.messages?.length
});
// NEW: Log the full payload before sending to backend
console.log('Final ChatRequest payload:', JSON.stringify(request, null, 2));
const response = await fetch('/api/chat', {
method: 'POST',
@@ -193,10 +195,12 @@ export class ChatService {
public async createChatRequest(userInput: string, systemPromptText?: string, isPattern: boolean = false): Promise<ChatRequest> {
const prompt = this.createChatPrompt(userInput, systemPromptText);
const config = get(chatConfig);
const language = get(languageStore);
return {
prompts: [prompt],
messages: [],
language: language, // Add language at the top level for backend compatibility
...config
};
}

View File

@@ -61,16 +61,16 @@ export const POST: RequestHandler = async ({ request }) => {
language: body.language
});
// Ensure language instruction is present
if (body.prompts?.[0] && body.language && body.language !== 'en') {
const languageInstruction = `. Please use the language '${body.language}' for the output.`;
if (!body.prompts[0].userInput?.includes(languageInstruction)) {
body.prompts[0].userInput = (body.prompts[0].userInput || '') + languageInstruction;
}
}
// Removed redundant language instruction logic; Go backend handles this
// if (body.prompts?.[0] && body.language && body.language !== 'en') {
// const languageInstruction = `. Please use the language '${body.language}' for the output.`;
// if (!body.prompts[0].userInput?.includes(languageInstruction)) {
// body.prompts[0].userInput = (body.prompts[0].userInput || '') + languageInstruction;
// }
// }
console.log('2. Language analysis:', {
input: body.prompts?.[0]?.userInput?.substring(0, 100),
input: body.prompts?.[0]?.userInput?.substring(0, 100), // Note: This input no longer has the instruction appended here
hasLanguageInstruction: body.prompts?.[0]?.userInput?.includes('language'),
containsFr: body.prompts?.[0]?.userInput?.includes('fr'),
containsEn: body.prompts?.[0]?.userInput?.includes('en'),

View File

@@ -1695,6 +1695,56 @@
"patternName": "extract_wisdom_short",
"description": "[Description pending]",
"tags": []
},
{
"patternName": "analyze_bill",
"description": "[Description pending]",
"tags": []
},
{
"patternName": "analyze_bill_short",
"description": "[Description pending]",
"tags": []
},
{
"patternName": "create_coding_feature",
"description": "[Description pending]",
"tags": []
},
{
"patternName": "create_excalidraw_visualization",
"description": "[Description pending]",
"tags": []
},
{
"patternName": "create_flash_cards",
"description": "[Description pending]",
"tags": []
},
{
"patternName": "create_loe_document",
"description": "[Description pending]",
"tags": []
},
{
"patternName": "extract_domains",
"description": "[Description pending]",
"tags": []
},
{
"patternName": "extract_main_activities",
"description": "[Description pending]",
"tags": []
},
{
"patternName": "find_female_life_partner",
"description": "[Description pending]",
"tags": []
},
{
"patternName": "youtube_summary",
"description": "[Description pending]",
"tags": []
}
]
}
}