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.

client.py 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 agent.canvas import Canvas
  19. from api import settings
  20. if __name__ == '__main__':
  21. parser = argparse.ArgumentParser()
  22. dsl_default_path = os.path.join(
  23. os.path.dirname(os.path.realpath(__file__)),
  24. "dsl_examples",
  25. "retrieval_and_generate.json",
  26. )
  27. parser.add_argument('-s', '--dsl', default=dsl_default_path, help="input dsl", action='store', required=True)
  28. parser.add_argument('-t', '--tenant_id', default=False, help="Tenant ID", action='store', required=True)
  29. parser.add_argument('-m', '--stream', default=False, help="Stream output", action='store_true', required=False)
  30. args = parser.parse_args()
  31. settings.init_settings()
  32. canvas = Canvas(open(args.dsl, "r").read(), args.tenant_id)
  33. if canvas.get_prologue():
  34. print(f"==================== Bot =====================\n> {canvas.get_prologue()}", end='')
  35. query = ""
  36. while True:
  37. canvas.reset(True)
  38. query = input("\n==================== User =====================\n> ")
  39. ans = canvas.run(query=query)
  40. print("==================== Bot =====================\n> ", end='')
  41. for ans in canvas.run(query=query):
  42. print(ans, end='\n', flush=True)
  43. print(canvas.path)