mirror of
https://github.com/OpenSPG/KAG.git
synced 2025-11-23 05:41:16 +00:00
45 lines
1.0 KiB
Python
45 lines
1.0 KiB
Python
|
|
# -*- coding: utf-8 -*-
|
||
|
|
import pytest
|
||
|
|
from kag.interface import LLMClient
|
||
|
|
|
||
|
|
|
||
|
|
def get_vllm_config():
|
||
|
|
return {
|
||
|
|
"type": "vllm",
|
||
|
|
"model": "qwen2.5-3b",
|
||
|
|
"base_url": "http://localhost:8000/v1/chat/completions",
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
def get_openai_config():
|
||
|
|
return {
|
||
|
|
"type": "openai",
|
||
|
|
"base_url": "https://api.deepseek.com/beta",
|
||
|
|
"api_key": "",
|
||
|
|
"model": "deepseek-chat",
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
def get_ollama_config():
|
||
|
|
return {
|
||
|
|
"type": "ollama",
|
||
|
|
"base_url": "http://localhost:11434/api/generate",
|
||
|
|
"model": "llama3.1",
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.mark.skip(reason="Missing API key")
|
||
|
|
def test_llm_client():
|
||
|
|
|
||
|
|
for conf in [get_vllm_config(), get_openai_config(), get_ollama_config()]:
|
||
|
|
client = LLMClient.from_config(conf)
|
||
|
|
rsp = client("Who are you?")
|
||
|
|
# assert rsp is not None
|
||
|
|
|
||
|
|
|
||
|
|
def test_mock_llm_client():
|
||
|
|
conf = {"type": "mock"}
|
||
|
|
client = LLMClient.from_config(conf)
|
||
|
|
rsp = client.call_with_json_parse("who are you?")
|
||
|
|
assert rsp == "I am an intelligent assistant"
|