Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

client.py 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #
  2. # Copyright 2024 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. import argparse
  17. import os
  18. from functools import partial
  19. from agent.canvas import Canvas
  20. from agent.settings import DEBUG
  21. if __name__ == '__main__':
  22. parser = argparse.ArgumentParser()
  23. dsl_default_path = os.path.join(
  24. os.path.dirname(os.path.realpath(__file__)),
  25. "dsl_examples",
  26. "retrieval_and_generate.json",
  27. )
  28. parser.add_argument('-s', '--dsl', default=dsl_default_path, help="input dsl", action='store', required=True)
  29. parser.add_argument('-t', '--tenant_id', default=False, help="Tenant ID", action='store', required=True)
  30. parser.add_argument('-m', '--stream', default=False, help="Stream output", action='store_true', required=False)
  31. args = parser.parse_args()
  32. canvas = Canvas(open(args.dsl, "r").read(), args.tenant_id)
  33. while True:
  34. ans = canvas.run(stream=args.stream)
  35. print("==================== Bot =====================\n> ", end='')
  36. if args.stream and isinstance(ans, partial):
  37. cont = ""
  38. for an in ans():
  39. print(an["content"][len(cont):], end='', flush=True)
  40. cont = an["content"]
  41. else:
  42. print(ans["content"])
  43. if DEBUG: print(canvas.path)
  44. question = input("\n==================== User =====================\n> ")
  45. canvas.add_user_input(question)