Files
aurak/fix_kb_service.py
T
Developer 0a9588abb7 feat: implement QuestionBank CRUD with pagination and template query
- Add pagination support to findAll (page, limit query params)
- Add findByTemplateId method to service
- Add GET /by-template/:templateId endpoint to controller
- Service already includes CRUD for QuestionBank and QuestionBankItem
2026-04-23 17:19:11 +08:00

75 lines
2.7 KiB
Python

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.")