command_parser.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # This file contains helpful parsing utilities
  2. # This is not used for now
  3. class BaseParser:
  4. def __init__(self, llm, parser_type):
  5. self.llm = llm
  6. self.parser_type = parser_type
  7. def parse(self, instruction):
  8. pass
  9. class PunctuationParser(BaseParser):
  10. def __init__(self, llm, parser_type = "punctuation"):
  11. pass
  12. def parse(self, instruction):
  13. """
  14. parse calls with different number of arguments
  15. 1) command_type
  16. 2) command_type command_name
  17. 3) command_type command_name command_body
  18. """
  19. if ": " in instruction:
  20. splitted_command = instruction.split(": ")
  21. command_head = splitted_command[0].split(" ")
  22. command_body = splitted_command[-1]
  23. command_type = command_head[0]
  24. command_name = command_head[1]
  25. return {
  26. "command_type": command_type,
  27. "command_name": command_name,
  28. "command_body": command_body
  29. }
  30. elif " " in instruction:
  31. command_head = instruction.split(" ")
  32. command_type = command_head[0]
  33. command_name = command_head[1]
  34. return {
  35. "command_type": command_type,
  36. "command_name": command_name,
  37. "command_body": None
  38. }
  39. else:
  40. command_type = instruction
  41. return {
  42. "command_type": command_type,
  43. "command_name": None,
  44. "command_body": None
  45. }
  46. class ChatGPTParser:
  47. def __init__(self, llm, parser_type = "gpt3.5"):
  48. pass
  49. def parse(self, instruction):
  50. pass