Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. class Agent(Base):
  19. def __init__(self, rag, res_dict):
  20. self.id = None
  21. self.avatar = None
  22. self.canvas_type = None
  23. self.description = None
  24. self.dsl = None
  25. super().__init__(rag, res_dict)
  26. class Dsl(Base):
  27. def __init__(self, rag, res_dict):
  28. self.answer = []
  29. self.components = {
  30. "begin": {
  31. "downstream": ["Answer:China"],
  32. "obj": {
  33. "component_name": "Begin",
  34. "params": {}
  35. },
  36. "upstream": []
  37. }
  38. }
  39. self.graph = {
  40. "edges": [],
  41. "nodes": [
  42. {
  43. "data": {
  44. "label": "Begin",
  45. "name": "begin"
  46. },
  47. "id": "begin",
  48. "position": {
  49. "x": 50,
  50. "y": 200
  51. },
  52. "sourcePosition": "left",
  53. "targetPosition": "right",
  54. "type": "beginNode"
  55. }
  56. ]
  57. }
  58. self.history = []
  59. self.messages = []
  60. self.path = []
  61. self.reference = []
  62. super().__init__(rag, res_dict)
  63. def create_session(self, **kwargs) -> Session:
  64. res = self.post(f"/agents/{self.id}/sessions", json=kwargs)
  65. res = res.json()
  66. if res.get("code") == 0:
  67. return Session(self.rag, res.get("data"))
  68. raise Exception(res.get("message"))
  69. def list_sessions(self, page: int = 1, page_size: int = 30, orderby: str = "create_time", desc: bool = True,
  70. id: str = None) -> list[Session]:
  71. res = self.get(f"/agents/{self.id}/sessions",
  72. {"page": page, "page_size": page_size, "orderby": orderby, "desc": desc, "id": id})
  73. res = res.json()
  74. if res.get("code") == 0:
  75. result_list = []
  76. for data in res.get("data"):
  77. temp_agent = Session(self.rag, data)
  78. result_list.append(temp_agent)
  79. return result_list
  80. raise Exception(res.get("message"))
  81. def delete_sessions(self, ids: list[str] | None = None):
  82. res = self.rm(f"/agents/{self.id}/sessions", {"ids": ids})
  83. res = res.json()
  84. if res.get("code") != 0:
  85. raise Exception(res.get("message"))