Coverage for llm.py: 0%

1 from qrclaw.providers import provider

2 from qrclaw.logger import get_logger

3

4 logger = get_logger("qrclaw.llm")

5

6

7 def chat(messages: list[dict]) -> str:

8 """

9 发送消息给 LLM，返回回复文本。

10

11 messages 格式：

12 [

13 {"role": "system", "content": "你是一个助手"},

14 {"role": "user", "content": "你好"},

15 ]

16 """

17 logger.debug(f"调用 chat，消息数: {len(messages)}")

18 try:

19 return provider.chat(messages)

20 except Exception as e:

21 logger.error(f"LLM 调用失败: {e}", exc_info=True)

22 raise