add thinking

This commit is contained in:
bridge
2025-09-03 21:56:38 +08:00
parent 8cfa2e5d0a
commit 9fd7dfd471
5 changed files with 81 additions and 30 deletions

View File

@@ -71,8 +71,6 @@ def get_prompt_and_call_llm(template_path: Path, infos: dict) -> str:
prompt = get_prompt(template, infos)
res = call_llm(prompt)
json_res = parse_llm_response(res)
# print(f"prompt = {prompt}")
# print(f"res = {res}")
return json_res
async def get_prompt_and_call_llm_async(template_path: Path, infos: dict) -> str:
@@ -82,7 +80,7 @@ async def get_prompt_and_call_llm_async(template_path: Path, infos: dict) -> str
template = read_txt(template_path)
prompt = get_prompt(template, infos)
res = await call_llm_async(prompt)
print(f"res = {res}")
# print(f"res = {res}")
json_res = parse_llm_response(res)
return json_res

53
src/utils/text_wrap.py Normal file
View File

@@ -0,0 +1,53 @@
def wrap_text(text: str, max_width: int = 20) -> list[str]:
"""
将长文本按指定宽度换行
Args:
text: 要换行的文本
max_width: 每行的最大字符数默认20
Returns:
换行后的文本行列表
"""
if not text:
return []
lines = []
current_line = ""
# 按换行符分割,处理已有的换行
paragraphs = text.split('\n')
for paragraph in paragraphs:
if not paragraph.strip():
lines.append("")
continue
words = paragraph.split()
for word in words:
# 如果当前行加上新词会超过限制
if len(current_line) + len(word) + 1 > max_width:
if current_line:
lines.append(current_line.strip())
current_line = word
else:
# 如果单个词就超过限制,强制换行
if len(word) > max_width:
# 长词强制切分
for i in range(0, len(word), max_width):
lines.append(word[i:i + max_width])
else:
lines.append(word)
else:
if current_line:
current_line += " " + word
else:
current_line = word
# 处理段落的最后一行
if current_line:
lines.append(current_line.strip())
current_line = ""
return lines