MCPcopy Create free account
hub / github.com/OpenBMB/ToolBench / parse

Method parse

toolbench/inference/LLM/tool_llama_lora_model.py:96–132  ·  view source on GitHub ↗
(self,functions,process_id,**args)

Source from the content-addressed store, hash-verified

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

Callers 1

Calls 4

predictionMethod · 0.95
process_system_messageFunction · 0.90
react_parserFunction · 0.90

Tested by

no test coverage detected