Files
hack/tools/scripts/llm-key-hunter/results/_cache/content/carbonliwr_user-management-system.json

1 line
19 KiB
JSON

{"repo": "carbonliwr/user-management-system", "files": {"backend/app/admin/service/llm_create_service.py": {"1ccc9fa47076ba0838c458319fd691168f36d6db": {"t": 1785768190.223612, "n": 17773, "h": "8426e0f215d968c7", "c": "from celery import group\nfrom openai import OpenAI\n\nfrom backend.app.admin.crud.crud_llm_model import llm_model_dao\nfrom backend.app.admin.crud.crud_llm_provider import llm_provider_dao\nfrom backend.app.admin.model.llm_model import LlmModel\nfrom backend.database.db_mysql import async_db_session\nfrom backend.app.admin.crud.crud_llm_create import LlmCreateCRUD\nfrom backend.app.admin.model.llm_provider_model import LlmProvider\n\n# {\"name\": \"\", \"type\": \"text-generation\", \"status\": 0},\n# {\"name\": \"\", \"type\": \"image-generation\", \"status\": 0},\n# {\"name\": \"\", \"type\": \"video-generation\", \"status\": 0},\n# {\"name\": \"\", \"type\": \"text-embedding\", \"status\": 0},\n# {\"name\": \"\", \"type\": \"audio-generation\", \"status\": 0},\n\nllm_providers_data = {\n \"NO.1 API\": [\n {\n \"group_name\": \"OpenAI\",\n \"models\": [\n {\"name\": \"gpt-3.5-turbo\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"gpt-4\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"gpt-4-turbo\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"gpt-4o\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"gpt-4o-2024-08-06\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"gpt-4o-mini\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"gpt-4o-mini-2024-07-18\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"chatgpt-4o-latest\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"o1-mini\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"o1-mini-2024-09-12\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"o1-preview\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"dall-e-2\", \"type\": \"image-generation\", \"status\": 0},\n {\"name\": \"dall-e-3\", \"type\": \"image-generation\", \"status\": 0},\n {\"name\": \"text-embedding-3-large\", \"type\": \"text-embedding\", \"status\": 0},\n {\"name\": \"text-embedding-3-small\", \"type\": \"text-embedding\", \"status\": 0},\n {\"name\": \"text-embedding-v1\", \"type\": \"text-embedding\", \"status\": 0},\n ]\n },\n {\n \"group_name\": \"Claude\",\n \"models\": [\n {\"name\": \"claude-2.1\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"claude-3-5-sonnet-20240620\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"claude-3-haiku-20240307\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"claude-3-7-sonnet-20250219\", \"type\": \"text-generation\", \"status\": 0},\n ]\n },\n {\n \"group_name\": \"DeepSeek\",\n \"models\": [\n {\"name\": \"deepseek-chat\", \"type\": \"text-generation\", \"status\": 1},\n {\"name\": \"deepseek-coder\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"deepseek-reasoner\", \"type\": \"text-generation\", \"status\": 0},\n ]\n },\n {\n \"group_name\": \"Midjourney\",\n \"models\": [\n {\"name\": \"mj_fast_blend\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"mj_fast_custom_zoom\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"mj_fast_describe\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"mj_fast_imagine\", \"type\": \"image-generation\", \"status\": 0}\n ]\n },\n {\n \"group_name\": \"SUNO音乐\",\n \"models\": [\n {\"name\": \"suno_lyrics\", \"type\": \"audio-generation\", \"status\": 0},\n {\"name\": \"suno_music\", \"type\": \"audio-generation\", \"status\": 0},\n {\"name\": \"suno-v3\", \"type\": \"audio-generation\", \"status\": 0},\n {\"name\": \"suno-v3.5\", \"type\": \"audio-generation\", \"status\": 0},\n ]\n },\n {\n \"group_name\": \"Google\",\n \"models\": [\n {\"name\": \"gemini-1.5-flash\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"gemini-1.5-pro\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"gemini-1.5-pro-002\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"gemini-1.5-pro-latest\", \"type\": \"text-generation\", \"status\": 0}\n ]\n },\n {\n \"group_name\": \"百度千帆\",\n \"models\": [\n {\"name\": \"ERNIE-4.0-8K\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"ERNIE-Bot-4\", \"type\": \"text-generation\", \"status\": 0}\n ]\n }\n ],\n \"腾讯混元\": [\n {\n \"group_name\": \"Embedding\",\n \"models\": [\n {\"name\": \"hunyuan-embedding\", \"type\": \"text-embedding\", \"status\": 0}\n ]\n },\n {\n \"group_name\": \"Hunyuan\",\n \"models\": [\n {\"name\": \"hunyuan-pro\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"hunyuan-standard\", \"type\": \"text-generation\", \"status\": 1},\n {\"name\": \"hunyuan-lite\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"hunyuan-standard-256k\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"hunyuan-vision\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"hunyuan-code\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"hunyuan-role\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"hunyuan-turbo\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"hunyuan-turbos-latest\", \"type\": \"text-generation\", \"status\": 0}\n ]\n }\n\n ],\n \"DeepSeek\": [\n {\n \"group_name\": \"DeepSeek Chat\",\n \"models\": [\n {\"name\": \"DeepSeek Chat\", \"type\": \"text-generation\", \"status\": 1}\n ]\n },\n {\n \"group_name\": \"DeepSeek Reasoner\",\n \"models\": [\n {\"name\": \"DeepSeek Reasoner\", \"type\": \"text-generation\", \"status\": 0}\n ]\n }\n ],\n \"火山引擎\": [\n {\n \"group_name\": \"DeepSeek\",\n \"models\": [\n {\"name\": \"DeepSeek-R1\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"DeepSeek-V3\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"DeepSeek-R1-Distill-Qwen-7B\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"DeepSeek-R1-Distill-Qwen-32B\", \"type\": \"text-generation\", \"status\": 0},\n ]\n },\n {\n \"group_name\": \"豆包\",\n \"models\": [\n {\"name\": \"Doubao-1.5-vision-pro-32k\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"Doubao-1.5-pro-32k\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"Doubao-1.5-lite-32k\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"Doubao-1.5-pro-256k\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"Doubao-embedding-vision\", \"type\": \"text-embedding\", \"status\": 0},\n {\"name\": \"Doubao-视频生成-Seaweed\", \"type\": \"video-generation\", \"status\": 0},\n {\"name\": \"Doubao-音乐大模型\", \"type\": \"audio-generation\", \"status\": 0},\n {\"name\": \"Doubao-同声传译\", \"type\": \"audio-generation\", \"status\": 0},\n {\"name\": \"Doubao-录音文件识别\", \"type\": \"audio-generation\", \"status\": 0},\n ]\n },\n {\n \"group_name\": \"月之暗面\",\n \"models\": [\n {\"name\": \"Moonshot-v1-128k\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"Moonshot-v1-32k\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"Moonshot-v1-8k\", \"type\": \"text-generation\", \"status\": 0},\n ]\n }\n ],\n \"Gemini\": [\n {\n \"group_name\": \"Gemini 1.5\",\n \"models\": [\n {\"name\": \"Gemini 1.5 Flash\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"Gemini 1.5 Flash (8B)\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"Gemini 1.5 Pro\", \"type\": \"text-generation\", \"status\": 0},\n ]\n },\n {\n \"group_name\": \"Gemini 2.0\",\n \"models\": [\n {\"name\": \"Gemini 2.0 Flash\", \"type\": \"text-generation\", \"status\": 0},\n ]\n }\n ],\n \"百度云千帆\": [\n {\n \"group_name\": \"ERNIE\",\n \"models\": [\n {\"name\": \"ERNIE-4.0\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"ERNIE 4.0 Trubo\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"ERNIE Speed\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"ERNIE Lite\", \"type\": \"text-generation\", \"status\": 0},\n ]\n },\n {\n \"group_name\": \"DeepSeek\",\n \"models\": [\n {\"name\": \"DeepSeek R1\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"DeepSeek V3\", \"type\": \"text-generation\", \"status\": 1},\n ]\n },\n {\n \"group_name\": \"Embedding\",\n \"models\": [\n {\"name\": \"BGE Large ZH\", \"type\": \"text-embedding\", \"status\": 0},\n {\"name\": \"BGE Large EN\", \"type\": \"text-embedding\", \"status\": 0},\n ]\n }\n ],\n \"月之暗面\":[\n {\n \"group_name\": \"moonshot-v1\",\n \"models\": [\n {\"name\": \"moonshot-v1-auto\", \"type\": \"text-generation\", \"status\": 1},\n ]\n }\n ],\n \"百川\": [\n {\n \"group_name\": \"Baichuan3\",\n \"models\": [\n {\"name\": \"Baichuan3 Turbo\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"Baichuan3 Turbo 128k\", \"type\": \"text-generation\", \"status\": 0},\n ]\n },\n {\n \"group_name\": \"Baichuan4\",\n \"models\": [\n {\"name\": \"Baichuan4\", \"type\": \"text-generation\", \"status\": 0}\n ]\n }\n ],\n \"阿里云百炼\": [\n {\n \"group_name\": \"qwen-coder\",\n \"models\": [\n {\"name\": \"qwen-coder-plus\", \"type\": \"text-generation\", \"status\": 0},\n ]\n },\n {\n \"group_name\": \"qwen-max\",\n \"models\": [\n {\"name\": \"qwen-max\", \"type\": \"text-generation\", \"status\": 0},\n ]\n },\n {\n \"group_name\": \"qwen-plus\",\n \"models\": [\n {\"name\": \"qwen-plus\", \"type\": \"text-generation\", \"status\": 0},\n ]\n },\n {\n \"group_name\": \"qwen-turbo\",\n \"models\": [\n {\"name\": \"qwen-turbo\", \"type\": \"text-generation\", \"status\": 0},\n ]\n },\n {\n \"group_name\": \"qwen-vl\",\n \"models\": [\n {\"name\": \"qwen-vl-plus\", \"type\": \"text-generation\", \"status\": 0},\n ]\n }\n ],\n \"硅基流动\": [\n {\n \"group_name\": \"BAAI\",\n \"models\": [\n {\"name\": \"BAAI/bge-m3\", \"type\": \"text-embedding\", \"status\": 0},\n ]\n },\n {\n \"group_name\": \"Qwen\",\n \"models\": [\n {\"name\": \"Qwen2.5-7B-Instruct\", \"type\": \"text-embedding\", \"status\": 0},\n ]\n },\n {\n \"group_name\": \"deepseek-ai\",\n \"models\": [\n {\"name\": \"deepseek-ai/DeepSeek-R1\", \"type\": \"text-generation\", \"status\": 0},\n {\"name\": \"deepseek-ai/DeepSeek-V3\", \"type\": \"text-generation\", \"status\": 0},\n ]\n },\n {\n \"group_name\": \"meta-llama\",\n \"models\": [\n {\"name\": \"meta-llama/Llama-3.3-70B-Instruct\", \"type\": \"text-generation\", \"status\": 0},\n ]\n }\n ]\n}\n\n\nclass LlmCreateService:\n @staticmethod\n async def add_llm_providers(user_uuid: str):\n providers = [\n (\"NO.1 API\", \"https://api.rcouyi.com/v1\", \"https://api.rcouyi.com/\", \"https://api.rcouyi.com/v1/models\", 1),\n (\"OpenAI\", \"https://api.openai.com\", \"https://platform.openai.com/docs\", \"https://api.openai.com/v1/models\",\n 0),\n (\"Anthropic\", \"https://api.anthropic.com\", \"https://docs.anthropic.com\",\n \"https://api.anthropic.com/v1/models\", 0),\n (\"Cohere\", \"https://api.cohere.ai\", \"https://docs.cohere.ai\", \"https://api.cohere.ai/v1/models\", 0),\n (\"硅基流动\", \"https://api.siliconflow.cn\", \"https://docs.siliconflow.cn\",\n \"https://api.siliconflow.cn/v1/models\", 0),\n (\"O3\", \"https://api.o3.fan\", \"https://docs.o3.fan/\", \"https://docs.o3.fan/models\", 0),\n (\"AiHubMix\", \"https://aihubmix.com\", \"https://doc.aihubmix.com/\", \"https://aihubmix.com/models\", 0),\n (\"DeepSeek\", \"https://api.deepseek.com\", \"https://api-docs.deepseek.com/\", \"https://api.deepseek.com\", 0),\n (\"ocoolAI\", \"https://api.ocoolai.com\", \"https://docs.ocoolai.com/\", \"https://api.ocoolai.com/info/models/\",\n 0),\n (\"百度云千帆\", \"https://qianfan.baidubce.com/v2/\", \"https://cloud.baidu.com/doc/index.html\",\n \"https://qianfan.baidubce.com/v2\", 0),\n (\"Ollama\", \"http://localhost:11434\", \"https://github.com/ollama/ollama/tree/main/docs\",\n \"https://ollama.com/library\", 0),\n (\"LM Studio\", \"http://localhost:1234\", \"https://lmstudio.ai/docs\", \"https://lmstudio.ai/models\", 0),\n (\"Azure OpenAI\", \"https://api.anthropic.com/\", \"https://docs.anthropic.com/en/docs/\",\n \"https://docs.anthropic.com/en/docs/about-claude/models/all-models\", 0),\n (\"Gemini\", \"https://generativelanguage.googleapis.com\", \"https://ai.google.dev/gemini-api/docs\",\n \"https://ai.google.dev/gemini-api/docs/models/gemini\", 0),\n (\"GitHub Models\", \"https://models.inference.ai.azure.com/\", \"https://docs.github.com/en/github-models\",\n \"https://github.com/marketplace/models\", 0),\n (\"DMXAPI\", \"https://www.dmxapi.cn\", \"https://dmxapi.cn/models.html#code-block\",\n \"https://www.dmxapi.cn/pricing\", 0),\n (\"零一万物\", \"https://api.lingyiwanwu.com\", \"https://platform.lingyiwanwu.com/docs\",\n \"https://platform.lingyiwanwu.com/docs#%E6%A8%A1%E5%9E%8B\", 0),\n (\"智谱AI\", \"https://open.bigmodel.cn/api/paas.v4/\", \"https://open.bigmodel.cn/dev/howuse/introduction\",\n \"https://open.bigmodel.cn/modelcenter/square\", 0),\n (\"月之暗面\", \"https://api.moonshot.cn\", \"https://platform.moonshot.cn/docs/intro\",\n \"https://platform.moonshot.cn/docs/intro#%E6%A8%A1%E5%9E%8B%E5%88%97%E8%A1%A8\", 0),\n (\"百川\", \"https://api.baichuan-ai.com\", \"https://platform.baichuan-ai.com/docs\",\n \"https://platform.baichuan-ai.com/price\", 0),\n (\"阿里云百炼\", \"https://dashscope.aliyuncs.com/compatible-mode/v1/\",\n \"https://help.aliyun.com/zh/model-studio/getting-started/\",\n \"https://bailian.console.aliyun.com/model-market#/model-market\", 0),\n ('火山引擎', 'https://ark.cn-beijing.volces.com/api/v3/', 'https://www.volcengine.com/docs/82379/1182403',\n 'https://console.volcengine.com/ark/region:ark+cn-beijing/endpoint', 0),\n ('OpenRouter', 'https://openrouter.ai/api/v1/', 'https://openrouter.ai/docs/',\n 'https://openrouter.ai/docs/models', 0),\n ('腾讯混元', 'https://api.hunyuan.cloud.tencent.com',\n 'https://cloud.tencent.com/document/product/1729/111007',\n 'https://cloud.tencent.com/document/product/1729/104753', 0),\n ('腾讯云TI', 'https://api.lkeap.cloud.tencent.com', 'https://cloud.tencent.com/document/product/1772',\n 'https://console.cloud.tencent.com/tione/v2/aimarket', 0)\n ]\n\n objects = []\n for name, api_url, document_url, llm_model_url, status in providers:\n objects.append(LlmProvider(\n user_uuid=user_uuid,\n name=name,\n api_key=\"\",\n api_url=api_url,\n document_url=document_url,\n llm_model_url=llm_model_url,\n status=status\n ))\n\n async with async_db_session() as db:\n await LlmCreateCRUD.create_providers(db, objects, commit=True)\n\n async with async_db_session() as db:\n all_providers = await llm_provider_dao.get_all(db, user_uuid=user_uuid)\n\n # 组织模型数据\n model_objects = []\n\n for provider in all_providers:\n if provider.name in llm_providers_data.keys():\n for group in llm_providers_data[provider.name]:\n group_name = group[\"group_name\"]\n for model in group[\"models\"]:\n model_objects.append(\n LlmModel(\n provider_uuid=provider.uuid,\n group_name=group_name,\n name=model[\"name\"],\n type=model[\"type\"],\n status=model[\"status\"]\n )\n )\n\n if len(model_objects) != 0:\n async with async_db_session() as db:\n await LlmCreateCRUD.create_models(db, model_objects, commit=True)\n\n\n @staticmethod\n async def test(base_url: str, api_key: str, model_name: str):\n client = OpenAI(api_key=api_key, base_url=base_url)\n\n response = client.chat.completions.create(\n model=model_name,\n messages=[\n {\"role\": \"system\", \"content\": \"You are a helpful assistant\"},\n {\"role\": \"user\", \"content\": \"Hello\"},\n ],\n stream=False\n )\n print(response)\n\n\n\n\n\nllm_create_service = LlmCreateService()\n\n\n"}}}}