add login api

This commit is contained in:
lzy
2025-05-26 22:04:35 +08:00
parent 07ea5e1aab
commit 97155afe03
3 changed files with 24 additions and 5 deletions

View File

@@ -520,6 +520,24 @@ async def debug_page():
</html>
""")
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

View File

@@ -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"]
)

View File

@@ -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")