function_descriptions = [ { "name": "remove_word_from_string", "description": "Remove a word from a string by given its index", "parameters": { "type": "object", "properties": { "string": { "type": "string", "description": "The original string to be processed", }, "index": { "type": "integer", "description": "The index of the word to be removed" }, }, "required": [ "string", "index" ], }, }, { "name": "send_message_by_email", "description": "Send an email with the text message to a recipient", "parameters": { "type": "object", "properties": { "recipient": { "type": "string", "description": "The email address of the recipient", }, "message": { "type": "string", "description": "The message of the email content", } }, "required": [ "recipient", "message" ], }, } ]
以上两个函数,一个用来获取字符串和要移除单词的位置,一个用来获取接收者和消息
定义执行函数以返回结果
1 2 3 4 5 6 7 8 9 10 11 12 13 14
defremove_word_from_string(string, index): words = string.split()
if0 <= index < len(words): del words[index]
return' '.join(words) else: return string
defsend_message_by_email(recipient, message): print(f'Sending {message} to {recipient}\n\n') returnf'Just sent email to {recipient}'
question = """ I have a string as follows: black yellow red blue green Please do the following 2 operations on it: 1. Remove the third word in the string 2. Send the updated string to Alex via email [email protected] """ first_response = llm.predict_messages( [HumanMessage(content=question)], functions=function_descriptions) print(first_response.additional_kwargs, end='\n\n')