修改了refer模块
This commit is contained in:
parent
b6910ee15b
commit
18d60cae93
Binary file not shown.
@ -17,6 +17,7 @@ from typing import Dict, Any, Optional, List, cast
|
||||
from pathlib import Path
|
||||
import mysql.connector
|
||||
from mysql.connector import pooling
|
||||
import random
|
||||
|
||||
from core.config import ConfigManager, ResourceConfig
|
||||
from utils.prompts import BasePromptBuilder, PromptTemplate
|
||||
@ -341,10 +342,15 @@ class PromptService:
|
||||
full_path = self._get_full_path(path_str)
|
||||
|
||||
if full_path.exists() and full_path.is_file():
|
||||
content = full_path.read_text('utf-8')
|
||||
refer_content += f"--- {full_path.name} ---\n{content}\n\n"
|
||||
with open(full_path, 'r', encoding='utf-8') as f:
|
||||
lines = f.readlines()
|
||||
if lines:
|
||||
sample_size = max(1, int(len(lines) * ref_item.sampling_rate))
|
||||
sampled_lines = random.sample(lines, sample_size)
|
||||
sampled_content = ''.join(sampled_lines)
|
||||
refer_content += f"--- {full_path.name} (sampled {ref_item.sampling_rate * 100}%) ---\n{sampled_content}\n\n"
|
||||
except Exception as e:
|
||||
logger.error(f"读取参考文件失败 {ref_item.path}: {e}")
|
||||
logger.error(f"读取或采样参考文件失败 {ref_item.path}: {e}")
|
||||
except Exception as e:
|
||||
logger.error(f"获取参考内容失败: {e}")
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user