import os file_path = r'd:\aura\AuraK\server\src\knowledge-base\knowledge-base.service.ts' with open(file_path, 'r', encoding='utf-8') as f: lines = f.readlines() new_lines = [] changed = False for line in lines: # Match the specific pattern: userId, followed by kb.embeddingModelId if 'userId,' in line and 'kb.embeddingModelId' in line: # Check if it's the specific call site with three arguments # Example: [chunk.content], userId, kb.embeddingModelId # Or: batchTexts, userId, kb.embeddingModelId if 'getEmbeddings' not in line: # It's probably a multi-line call pass# Handled below new_line = line.replace('userId,', '').replace(' ', ' ') # Simple fix for potential double spaces # But wait, let's be more precise if 'userId,' in line: new_line = line.replace('userId,', '').strip() # Re-add leading whitespace leading = line[:line.find(line.lstrip())] new_line = leading + new_line + '\n' new_lines.append(new_line) changed = True continue new_lines.append(line) # Let's try a simpler approach if the above is too complex with open(file_path, 'r', encoding='utf-8') as f: content = f.read() # Pattern 1: [chunk.content], userId, kb.embeddingModelId target1 = """ [chunk.content], // Single text userId, kb.embeddingModelId,""" replacement1 = """ [chunk.content], // Single text kb.embeddingModelId,""" # Pattern 2: chunkTexts, userId, kb.embeddingModelId target2 = """ chunkTexts, userId, kb.embeddingModelId,""" replacement2 = """ chunkTexts, kb.embeddingModelId,""" # Pattern 3: batchTexts, userId, kb.embeddingModelId target3 = """ batchTexts, userId, kb.embeddingModelId,""" replacement3 = """ batchTexts, kb.embeddingModelId,""" # Pattern 4 (Precise results): texts, userId, embeddingModelId target4 = """ texts, userId, embeddingModelId,""" replacement4 = """ texts, embeddingModelId,""" fixed_content = content.replace(target1, replacement1) fixed_content = fixed_content.replace(target2, replacement2) fixed_content = fixed_content.replace(target3, replacement3) fixed_content = fixed_content.replace(target4, replacement4) if fixed_content != content: with open(file_path, 'w', encoding='utf-8') as f: f.write(fixed_content) print("Successfully replaced patterns.") else: print("No patterns found to replace.")