Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #
  2. # Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. from .base import Base
  17. from .session import Session
  18. import requests
  19. class Agent(Base):
  20. def __init__(self,rag,res_dict):
  21. self.id = None
  22. self.avatar = None
  23. self.canvas_type = None
  24. self.description = None
  25. self.dsl = None
  26. super().__init__(rag, res_dict)
  27. class Dsl(Base):
  28. def __init__(self,rag,res_dict):
  29. self.answer = []
  30. self.components = {
  31. "begin": {
  32. "downstream": ["Answer:China"],
  33. "obj": {
  34. "component_name": "Begin",
  35. "params": {}
  36. },
  37. "upstream": []
  38. }
  39. }
  40. self.graph = {
  41. "edges": [],
  42. "nodes": [
  43. {
  44. "data": {
  45. "label": "Begin",
  46. "name": "begin"
  47. },
  48. "id": "begin",
  49. "position": {
  50. "x": 50,
  51. "y": 200
  52. },
  53. "sourcePosition": "left",
  54. "targetPosition": "right",
  55. "type": "beginNode"
  56. }
  57. ]
  58. }
  59. self.history = []
  60. self.messages = []
  61. self.path = []
  62. self.reference = []
  63. super().__init__(rag,res_dict)
  64. @staticmethod
  65. def create_session(id,rag,**kwargs) -> Session:
  66. res = requests.post(f"{rag.api_url}/agents/{id}/sessions",headers={"Authorization": f"Bearer {rag.user_key}"},json=kwargs)
  67. res = res.json()
  68. if res.get("code") == 0:
  69. return Session(rag,res.get("data"))
  70. raise Exception(res.get("message"))
  71. @staticmethod
  72. def list_sessions(agent_id,rag,page: int = 1, page_size: int = 30, orderby: str = "create_time", desc: bool = True,
  73. id: str = None) -> list[Session]:
  74. url = f"{rag.api_url}/agents/{agent_id}/sessions"
  75. headers = {"Authorization": f"Bearer {rag.user_key}"}
  76. params = {"page": page, "page_size": page_size, "orderby": orderby, "desc": desc, "id": id}
  77. res = requests.get(url=url,headers=headers,params=params)
  78. res = res.json()
  79. if res.get("code") == 0:
  80. result_list = []
  81. for data in res.get("data"):
  82. temp_agent = Session(rag,data)
  83. result_list.append(temp_agent)
  84. return result_list
  85. raise Exception(res.get("message"))