llm_presets.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # Copyright (C) 2025 AIDC-AI
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. # Unless required by applicable law or agreed to in writing, software
  8. # distributed under the License is distributed on an "AS IS" BASIS,
  9. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. # See the License for the specific language governing permissions and
  11. # limitations under the License.
  12. """
  13. LLM Presets - Predefined configurations for popular LLM providers
  14. All providers support OpenAI SDK protocol.
  15. """
  16. from typing import Dict, Any, List
  17. LLM_PRESETS: List[Dict[str, Any]] = [
  18. {
  19. "name": "Qwen",
  20. "base_url": "https://dashscope.aliyuncs.com/compatible-mode/v1",
  21. "model": "qwen-max",
  22. "api_key_url": "https://bailian.console.aliyun.com/?tab=model#/api-key",
  23. },
  24. {
  25. "name": "OpenAI",
  26. "base_url": "https://api.openai.com/v1",
  27. "model": "gpt-4o",
  28. "api_key_url": "https://platform.openai.com/api-keys",
  29. },
  30. {
  31. "name": "Claude",
  32. "base_url": "https://api.anthropic.com/v1/",
  33. "model": "claude-sonnet-4-5",
  34. "api_key_url": "https://console.anthropic.com/settings/keys",
  35. },
  36. {
  37. "name": "DeepSeek",
  38. "base_url": "https://api.deepseek.com",
  39. "model": "deepseek-chat",
  40. "api_key_url": "https://platform.deepseek.com/api_keys",
  41. },
  42. {
  43. "name": "Ollama",
  44. "base_url": "http://localhost:11434/v1",
  45. "model": "llama3.2",
  46. "api_key_url": "https://ollama.com/download",
  47. "default_api_key": "ollama", # Required by OpenAI SDK but ignored by Ollama
  48. },
  49. {
  50. "name": "Moonshot",
  51. "base_url": "https://api.moonshot.cn/v1",
  52. "model": "moonshot-v1-8k",
  53. "api_key_url": "https://platform.moonshot.cn/console/api-keys",
  54. },
  55. ]
  56. def get_preset_names() -> List[str]:
  57. """Get list of preset names"""
  58. return [preset["name"] for preset in LLM_PRESETS]
  59. def get_preset(name: str) -> Dict[str, Any]:
  60. """Get preset configuration by name"""
  61. for preset in LLM_PRESETS:
  62. if preset["name"] == name:
  63. return preset
  64. return {}
  65. def find_preset_by_base_url_and_model(base_url: str, model: str) -> str | None:
  66. """
  67. Find preset name by base_url and model
  68. Returns:
  69. Preset name if found, None otherwise
  70. """
  71. for preset in LLM_PRESETS:
  72. if preset["base_url"] == base_url and preset["model"] == model:
  73. return preset["name"]
  74. return None