add llm ai

This commit is contained in:
bridge
2025-08-30 21:58:43 +08:00
parent 9ab71d1ac8
commit 4f9c6d4c79
11 changed files with 114 additions and 16 deletions

View File

@@ -1,7 +1,10 @@
from litellm import completion
from langchain.prompts import PromptTemplate
from pathlib import Path
import json
from src.utils.config import CONFIG
from src.utils.io import read_txt
def get_prompt(template: str, infos: dict) -> str:
"""
@@ -31,4 +34,23 @@ def call_llm(prompt: str) -> str:
)
# 返回生成的内容
return response.choices[0].message.content
return response.choices[0].message.content
def get_prompt_and_call_llm(template_path: Path, infos: dict) -> str:
"""
根据模板获取提示词并调用LLM
"""
template = read_txt(template_path)
prompt = get_prompt(template, infos)
res = call_llm(prompt)
json_res = json.loads(res)
print(f"prompt = {prompt}")
print(f"res = {res}")
return json_res
def get_ai_prompt_and_call_llm(infos: dict) -> dict:
"""
根据模板获取提示词并调用LLM
"""
template_path = CONFIG.paths.templates / "ai.txt"
return get_prompt_and_call_llm(template_path, infos)