Coverage for aipyapp/config/llm.py: 0%

1#! /usr/bin/env python3

2# -*- coding: utf-8 -*-

3 from collections import OrderedDict

4

5 from .base import BaseConfig

6 from .. import T, get_lang

7

8 PROVIDERS = {

9 "Trustoken": {

10 "api_base": T("https://sapi.trustoken.ai/v1"),

11 "models_endpoint": "/models",

12 "type": "trust",

13 "model": "auto"

14 },

15 "DeepSeek": {

16 "api_base": "https://api.deepseek.com",

17 "models_endpoint": "/models",

18 "type": "deepseek"

19 },

20 "xAI": {

21 "api_base": "https://api.x.ai/v1",

22 "models_endpoint": "/models",

23 "type": "grok"

24 },

25 "Claude": {

26 "api_base": "https://api.anthropic.com/v1",

27 "models_endpoint": "/models",

28 "type": "claude"

29 },

30 "OpenAI": {

31 "api_base": "https://api.openai.com/v1",

32 "models_endpoint": "/models",

33 "type": "openai"

34 },

35 "Gemini": {

36 "api_base": "https://generativelanguage.googleapis.com/v1beta/",

37 "models_endpoint": "/models",

38 "type": "gemini"

39 },

40 "OAuth2": {

41 "type": "oauth2"

42 }

43}

44

45 def get_providers():

46 if get_lang() == "zh":

47 providers = OrderedDict()

48 providers["Trustoken"] = PROVIDERS["Trustoken"]

49 providers["DeepSeek"] = PROVIDERS["DeepSeek"]

50 return providers

51 else:

52 return PROVIDERS

53

54 class LLMConfig(BaseConfig):

55 FILE = "llm.json"

56

57 def __init__(self, path: str):

58 super().__init__(path)

59 self.providers = get_providers()

60

61 def need_config(self):

62 """检查是否需要配置LLM。

63 """

64 if not self.config:

65 return True

66

67 for _, config in self.config.items() :

68 if config.get("enable", True):

69 return False

70 return True