feat: 添加好友功能并集成 LiteLLM 代理服务

- 新增好友搜索、添加、好友列表功能
- 集成 LiteLLM 代理服务及多模型定价配置
- 更新 iOS CocoaPods 配置
- 更新 .gitignore 和环境变量配置
This commit is contained in:
zl-q
2026-03-11 09:14:51 +08:00
parent 487405aa5b
commit e55e445906
28 changed files with 1226 additions and 181 deletions
@@ -31,3 +31,26 @@ def test_seed_data_does_not_keep_legacy_deepseek_alias() -> None:
catalog = load_llm_catalog()
assert all(entry["model_code"] != "deepseek-v3.2" for entry in catalog["llms"])
def test_llm_catalog_contains_litellm_routing_and_pricing_fields() -> None:
catalog = load_llm_catalog()
for entry in catalog["llms"]:
assert set(entry.keys()) == {
"model_code",
"factory_name",
"litellm_model",
"pricing_tiers",
}
assert isinstance(entry["litellm_model"], str)
assert "/" in entry["litellm_model"]
pricing_tiers = entry["pricing_tiers"]
assert isinstance(pricing_tiers, list)
assert len(pricing_tiers) > 0
for tier in pricing_tiers:
assert isinstance(tier, dict)
assert int(tier["max_prompt_tokens"]) > 0
assert float(tier["input_cost_per_token"]) >= 0
assert float(tier["output_cost_per_token"]) >= 0
assert float(tier["cache_hit_cost_per_token"]) >= 0
@@ -0,0 +1,55 @@
from __future__ import annotations
import pytest
from services.litellm.service import LiteLLMService
def test_calculate_cost_uses_first_qwen_tier() -> None:
service = LiteLLMService()
cost = service.calculate_cost(
model="dashscope/qwen3.5-flash",
prompt_tokens=100_000,
completion_tokens=1_000,
cached_prompt_tokens=10_000,
)
assert cost == pytest.approx(0.0202)
def test_calculate_cost_uses_second_qwen_tier() -> None:
service = LiteLLMService()
cost = service.calculate_cost(
model="dashscope/qwen3.5-flash",
prompt_tokens=200_000,
completion_tokens=5_000,
cached_prompt_tokens=20_000,
)
assert cost == pytest.approx(0.1856)
def test_run_completion_extracts_usage_and_cost() -> None:
service = LiteLLMService()
result = service.run_completion_with_cost(
model="dashscope/qwen3.5-flash",
messages=[{"role": "user", "content": "hello"}],
completion_fn=lambda **_: {
"model": "dashscope/qwen3.5-flash",
"usage": {
"prompt_tokens": 2000,
"completion_tokens": 100,
"total_tokens": 2100,
"prompt_tokens_details": {"cached_tokens": 500},
},
"choices": [{"message": {"content": "ok"}}],
},
)
assert result.usage.prompt_tokens == 2000
assert result.usage.completion_tokens == 100
assert result.usage.total_tokens == 2100
assert result.usage.cost == pytest.approx(0.00051)