(self,functions,process_id,**args)
| 76 | print("end_print"+"*"*50) |
| 77 | |
| 78 | def parse(self,functions,process_id,**args): |
| 79 | conv = get_conversation_template(self.template) |
| 80 | if self.template == "tool-llama": |
| 81 | roles = {"human": conv.roles[0], "gpt": conv.roles[1]} |
| 82 | elif self.template == "tool-llama-single-round" or self.template == "tool-llama-multi-rounds": |
| 83 | roles = {"system": conv.roles[0], "user": conv.roles[1], "function": conv.roles[2], "assistant": conv.roles[3]} |
| 84 | |
| 85 | self.time = time.time() |
| 86 | conversation_history = self.conversation_history |
| 87 | prompt = '' |
| 88 | for message in conversation_history: |
| 89 | role = roles[message['role']] |
| 90 | content = message['content'] |
| 91 | if role == "System" and functions != []: |
| 92 | content = process_system_message(content, functions) |
| 93 | prompt += f"{role}: {content}\n" |
| 94 | prompt += "Assistant:\n" |
| 95 | if functions != []: |
| 96 | predictions = self.prediction(prompt) |
| 97 | else: |
| 98 | predictions = self.prediction(prompt) |
| 99 | |
| 100 | decoded_token_len = len(self.tokenizer(predictions)) |
| 101 | if process_id == 0: |
| 102 | print(f"[process({process_id})]total tokens: {decoded_token_len}") |
| 103 | |
| 104 | thought, action, action_input = react_parser(predictions) |
| 105 | if len(thought.strip()) > 1: |
| 106 | print(thought) |
| 107 | # input() |
| 108 | message = { |
| 109 | "role": "assistant", |
| 110 | "content": thought, |
| 111 | "function_call": { |
| 112 | "name": action, |
| 113 | "arguments": action_input |
| 114 | } |
| 115 | } |
| 116 | return message, 0, decoded_token_len |
| 117 | |
| 118 | |
| 119 | if __name__ == "__main__": |
no test coverage detected