- 新增 app/api、app/service 数据分析 Agent 全套服务与接口 - schemas.py 重构为 schemas 包(analyst schema) - 新增 SQL 防注入、guardrail、缓存、字典、LLM 等服务 - 新增 tests 测试套件与 scripts/dev、scripts/setup 脚本 - 补充需求规格、架构说明书、开发清单、表设计等文档
34 lines
926 B
Python
34 lines
926 B
Python
"""llm 客户端测试(extract_sql 纯逻辑 + DeepSeek 真实冒烟)。"""
|
|
import unittest
|
|
|
|
from app.service.llm import DeepSeekLLM, extract_sql
|
|
|
|
|
|
class TestExtractSql(unittest.TestCase):
|
|
def test_plain(self):
|
|
self.assertEqual(extract_sql("SELECT 1"), "SELECT 1")
|
|
|
|
def test_fenced(self):
|
|
self.assertEqual(
|
|
extract_sql("结果如下:\n```sql\nSELECT 1\n```"),
|
|
"SELECT 1",
|
|
)
|
|
|
|
def test_fenced_no_lang(self):
|
|
self.assertEqual(extract_sql("```\nSELECT 2\n```"), "SELECT 2")
|
|
|
|
|
|
class TestDeepSeekSmoke(unittest.TestCase):
|
|
def test_complete(self):
|
|
llm = DeepSeekLLM()
|
|
text, usage = llm.complete(
|
|
[{"role": "user", "content": "只回复两个字:正常"}],
|
|
max_tokens=8,
|
|
)
|
|
self.assertTrue(text.strip())
|
|
self.assertIn("prompt_tokens", usage)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|