From 97155afe03844fa7dbb989c7e3a7831327a6793d Mon Sep 17 00:00:00 2001 From: lzy <949777411@qq.com> Date: Mon, 26 May 2025 22:04:35 +0800 Subject: [PATCH] add login api --- backend/api.py | 18 ++++++++++++++++++ backend/scientist_team.py | 7 ++++--- backend/utils.py | 4 ++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/backend/api.py b/backend/api.py index 8b2f0a1..11ae7c3 100755 --- a/backend/api.py +++ b/backend/api.py @@ -520,6 +520,24 @@ async def debug_page(): """) + +from pydantic import BaseModel +# 申明数据model +class LoginRequest(BaseModel): + user_name: str + pass_word: str + code: str = '' # 兼容传了验证码 + +@app.post("/matagent/login") +async def login(data: LoginRequest): + # 你实际可以加验证码判断,这里略过 + if data.user_name == "test" and data.pass_word == "111111": + # 简单生成一个token,实际生产用jwt等 + token = "fake_token_example" + return {"token": token} + else: + raise HTTPException(status_code=401, detail="用户名或密码错误") + # Example usage if __name__ == "__main__": import uvicorn diff --git a/backend/scientist_team.py b/backend/scientist_team.py index b3542fe..c3092bd 100755 --- a/backend/scientist_team.py +++ b/backend/scientist_team.py @@ -8,7 +8,7 @@ from autogen_agentchat.teams import SelectorGroupChat, RoundRobinGroupChat, Swar from autogen_agentchat.ui import Console from autogen_ext.models.openai import OpenAIChatCompletionClient from backend.constant import MODEL, OPENAI_API_KEY, OPENAI_BASE_URL, GRAPH_RAG -from autogen_ext.tools.graphrag import GlobalSearchTool +# from autogen_ext.tools.graphrag import GlobalSearchTool from backend.tools import hybird_retrieval_from_knowledge_base, search_from_oqmd_by_composition from backend.custom import SocietyOfMindAgent @@ -49,7 +49,7 @@ def create_scientist_team(user_input_func: Callable[[str, Optional[CancellationT handoffs=["Synthesis_Scientist", "Structure_Scientist", "Property_Scientist", "Application_Scientist"] ) - graph_rag_search = GlobalSearchTool.from_settings(settings_path=GRAPH_RAG) + # graph_rag_search = GlobalSearchTool.from_settings(settings_path=GRAPH_RAG) synthesis_agent = AssistantAgent( "Synthesis_Scientist", description="An experienced materials scientist agent who is particularly good at coming up with detailed synthesis schemes, and should be called when the task around a material synthesis topic.", @@ -89,7 +89,8 @@ def create_scientist_team(user_input_func: Callable[[str, Optional[CancellationT Always handoff back to Scientist_Admin when synthesis scheme is complete. Let's think step by step and answer with {lang}: """, - tools=[hybird_retrieval_from_knowledge_base, search_from_oqmd_by_composition, graph_rag_search], + # tools=[hybird_retrieval_from_knowledge_base, search_from_oqmd_by_composition, graph_rag_search], + tools=[hybird_retrieval_from_knowledge_base, search_from_oqmd_by_composition], reflect_on_tool_use=True, handoffs=["Scientist_Admin"] ) diff --git a/backend/utils.py b/backend/utils.py index ee64fcc..c04782a 100755 --- a/backend/utils.py +++ b/backend/utils.py @@ -18,10 +18,10 @@ class Settings(BaseSettings): # Model openai_api_key: Optional[str] = Field(None, env="OPENAI_API_KEY") openai_base_url: Optional[str] = Field(None, env="OPENAI_BASE_URL") - model_name: Optional[str] = Field(None, env="MODEL") + model_name: Optional[str] = Field(None, env="MODEL_NAME") # Path - coding_path: Optional[str] = Field(None, env=os.path.join(os.path.dirname(os.path.abspath(__file__)), "CODING_DIR")) + coding_path: Optional[str] = Field(None, env=os.path.join(os.path.dirname(os.path.abspath(__file__)), "CODING_PATH")) # MinIO minio_endpoint: Optional[str] = Field(None, env="MINIO_ENDPOINT")