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