| | |
| | | from pydantic import BaseModel |
| | | from sqlalchemy.orm import relationship, backref |
| | | |
| | | from app.config.const import Dialog_STATSU_DELETE |
| | | from app.models.base_model import Base |
| | | |
| | | |
| | |
| | | json['knowledges'] = [knowledge.to_json() for knowledge in self.knowledges] |
| | | |
| | | # if len(self.dialogs.all()) > 0: |
| | | json['dialogs'] = [dialog.to_json() for dialog in self.dialogs] |
| | | json['dialogs'] = [dialog.to_json() for dialog in self.dialogs if dialog.status != Dialog_STATSU_DELETE] |
| | | |
| | | # if len(self.agents.all()) > 0: |
| | | # json['agents'] = [agent.to_json() for agent in self.agents] |
| | |
| | | # if len(self.resources) > 0: |
| | | json['resources'] = [resource.to_json() for resource in self.resources if resource.status != DEPT_STATUS_DELETE] |
| | | |
| | | json['dept'] = [dept.to_base_json() for dept in self.organizationsif if dept.status != RESOURCE_STATUS_DELETE] |
| | | json['dept'] = [dept.to_base_json() for dept in self.organizations if dept.status != RESOURCE_STATUS_DELETE] |
| | | |
| | | return json |
| | | |
| | |
| | | from app.config.config import settings |
| | | from app.models import CanvasModel, DialogModel, KnowledgeModel |
| | | from app.models.dialog_model import DialogModel |
| | | from app.models.knowledge_model import KnowledgeModel |
| | | from app.models.llm_model import CommonLlmModel |
| | | from app.models.group_model import GroupModel |
| | | from app.models.user_model import UserModel |
| | | from app.service.ragflow import RagflowService |
| | |
| | | if keyword: |
| | | query = query.filter(GroupModel.group_name.like('%{}%'.format(keyword))) |
| | | total = query.count() |
| | | print(total) |
| | | items = query.order_by(GroupModel.id.desc()).limit(page_size).offset((page_index - 1) * page_size) |
| | | |
| | | return {"total":total , "items": [item.to_json() for item in items.all()]} |
| | |
| | | async def save_group_resource(db, user_id, group_id, llms, dialogs, knowledges): |
| | | try: |
| | | group = db.query(GroupModel).filter(GroupModel.id.__eq__(group_id)).first() |
| | | group.llms = [db.get(CommonLlmModel, user) for user in llms] |
| | | |
| | | group.dialogs = [db.get(DialogModel, user) for user in dialogs] |
| | | group.knowledges = [db.get(KnowledgeModel, user) for user in knowledges] |
| | | db.commit() |
| | |
| | | data = {"email": email, "user_id": user_id} |
| | | async with httpx.AsyncClient(timeout=60) as client: |
| | | response = await client.post(url, headers=headers, json=data) |
| | | print(response) |
| | | print(response.text) |
| | | if response.status_code != 200: |
| | | raise Exception(f"Ragflow add user to tenant failed: {response.text}") |
| | | |
| | |
| | | # logger.info("set_user_password:{}".format(data)) |
| | | return data |
| | | |
| | | async def agree_tenant_role(self, token: str, tenant_id: str) -> str: |
| | | url = f"{self.base_url}/v1/tenant/agree/{tenant_id}" |
| | | headers = {"Authorization": token} |
| | | data = {} |
| | | async with httpx.AsyncClient(timeout=60) as client: |
| | | response = await client.put(url, headers=headers, json=data) |
| | | print(response.text) |
| | | if response.status_code != 200: |
| | | raise Exception(f"Ragflow add user to tenant failed: {response.text}") |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | # async def a(): |
| | | # a = RagflowService("http://192.168.20.119:11080") |
| | | # b = await a.get_knowledge_list("ImY3ZTZlZWQwYTY2NTExZWY5ZmFiMDI0MmFjMTMwMDA2Ig.Zzxwmw.uI_HAWzOkipQuga1aeQtoeIc3IM", 1, |
| | | # 10) |
| | | # print(b) |
| | | # |
| | | # import asyncio |
| | | # |
| | | # asyncio.run(a()) |
| | | password = RagflowCrypto(settings.PUBLIC_KEY, settings.PRIVATE_KEY).encrypt("123456") |
| | | print(password) |
| | | async def a(): |
| | | a = RagflowService("http://192.168.20.119:11080") |
| | | b = await a.agree_tenant_role("ImQ3MGY1NGFhYzFkZjExZWY5MDFmMDI0MmFjMTMwMDA2Ig.Z2qJfA.hJX4rPnnmlkUzpjIl0YGcM-yp1M", "fe24dd2c9be611ef92880242ac160006") |
| | | print(b) |
| | | print(b) |
| | | |
| | | import asyncio |
| | | |
| | | asyncio.run(a()) |
| | | # password = RagflowCrypto(settings.PUBLIC_KEY, settings.PRIVATE_KEY).encrypt("123456") |
| | | # print(password) |
| | |
| | | await ragflow_service.add_user_tenant(token,u.app_id, |
| | | user.email, |
| | | user.app_id) |
| | | |
| | | await ragflow_service.add_user_tenant(token, u.app_id, |
| | | user.email, |
| | | user.app_id) |
| | | await ragflow_service.add_user_tenant(token, user.app_id, |
| | | u.email, |
| | | u.app_id) |
| | | await ragflow_service.add_user_tenant(token, user.app_id, |
| | | u.email, |
| | | u.app_id) |
| | |
| | | try: |
| | | if names: |
| | | query = db.query(Dialog.id, Dialog.name, Dialog.description, Dialog.status, Dialog.tenant_id) \ |
| | | .filter( Dialog.name.in_(names)) |
| | | .filter( Dialog.name.in_(names), Dialog.status == "1") |
| | | else: |
| | | query = db.query(Dialog.id, Dialog.name, Dialog.description, Dialog.status, Dialog.tenant_id) |
| | | query = db.query(Dialog.id, Dialog.name, Dialog.description, Dialog.status, Dialog.tenant_id).filter( Dialog.status == "1") |
| | | |
| | | results = query.all() |
| | | formatted_results = [ |
| | |
| | | if existing_agent: |
| | | existing_agent.name = row["name"] |
| | | existing_agent.description = row["description"] |
| | | existing_agent.status = row["status"] |
| | | # existing_agent.status = row["status"] |
| | | existing_agent.mode = row["mode"] |
| | | # existing_agent.tenant_id = get_rag_user_id(db, row["user_id"], type_dict[dialog_type]) |
| | | else: |