jeffreymeetkai commited on
Commit
8526803
1 Parent(s): 3db8af6

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +9 -1
  2. modeling_functionary.py +3 -2
  3. tokenizer_config.json +1 -1
README.md CHANGED
@@ -101,6 +101,14 @@ will yield:
101
  ```
102
  <|start_header_id|>system<|end_header_id|>
103
 
 
 
 
 
 
 
 
 
104
  // Supported function definitions that should be called when necessary.
105
  namespace functions {
106
 
@@ -115,7 +123,7 @@ location: string,
115
  What is the weather for Istanbul?
116
  ```
117
 
118
- A more detailed example is provided [here](https://github.com/MeetKai/functionary/blob/main/tests/prompt_test_v2.llama3.txt).
119
 
120
  ## Run the model
121
 
 
101
  ```
102
  <|start_header_id|>system<|end_header_id|>
103
 
104
+ You are capable of executing available function(s) if required.
105
+ Only execute function(s) when absolutely necessary.
106
+ Ask for the required input to:recipient==all
107
+ Use JSON for function arguments.
108
+ Respond in this format:
109
+ >>>${recipient}
110
+ ${content}
111
+ Available functions:
112
  // Supported function definitions that should be called when necessary.
113
  namespace functions {
114
 
 
123
  What is the weather for Istanbul?
124
  ```
125
 
126
+ A more detailed example is provided [here](https://github.com/MeetKai/functionary/blob/main/tests/prompt_test_v3.llama3.txt).
127
 
128
  ## Run the model
129
 
modeling_functionary.py CHANGED
@@ -66,22 +66,23 @@ class FunctionaryForCausalLM(LlamaForCausalLM):
66
  )
67
 
68
  input_ids = kwargs.pop("input_ids")
69
- function_call_token = "<|reserved_special_token_249|>"
70
 
71
  correct_results = []
72
  for input_id, result in zip(input_ids, results):
73
  final_output_json = {"role": "assistant", "content": None, "tool_calls": None}
74
  tool_calls = []
75
  raw_output_str = tokenizer.decode(result[len(input_id):].cpu())
76
- has_text = False if raw_output_str.startswith(function_call_token) else True
77
  chunks = raw_output_str.split(function_call_token)
78
  for i, chunk in enumerate(chunks):
79
  if len(chunk) == 0:
80
  continue
81
 
82
  chunk = chunk.replace(tokenizer.pad_token, "")
 
83
  if i == 0 and has_text is not False:
84
  final_output_json["content"] = chunk.strip[:-len("<|eot_id|>")] if chunk.endswith("<|eot_id|>") else chunk
 
85
  else:
86
  tool_calls.append(
87
  {
 
66
  )
67
 
68
  input_ids = kwargs.pop("input_ids")
69
+ function_call_token = ">>>"
70
 
71
  correct_results = []
72
  for input_id, result in zip(input_ids, results):
73
  final_output_json = {"role": "assistant", "content": None, "tool_calls": None}
74
  tool_calls = []
75
  raw_output_str = tokenizer.decode(result[len(input_id):].cpu())
 
76
  chunks = raw_output_str.split(function_call_token)
77
  for i, chunk in enumerate(chunks):
78
  if len(chunk) == 0:
79
  continue
80
 
81
  chunk = chunk.replace(tokenizer.pad_token, "")
82
+ has_text = True if chunk.startswith("all") else False
83
  if i == 0 and has_text is not False:
84
  final_output_json["content"] = chunk.strip[:-len("<|eot_id|>")] if chunk.endswith("<|eot_id|>") else chunk
85
+ final_output_json["content"] = final_output_json["content"][len("all\n"):]
86
  else:
87
  tool_calls.append(
88
  {
tokenizer_config.json CHANGED
@@ -2050,7 +2050,7 @@
2050
  }
2051
  },
2052
  "bos_token": "<|begin_of_text|>",
2053
- "chat_template": "{% for message in messages %}\n{% if message['role'] == 'user' or message['role'] == 'system' %}\n{{ '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n' + message['content'] + '<|eot_id|>' }}{% elif message['role'] == 'tool' %}\n{{ '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n' + message['content'] + '<|eot_id|>' }}{% else %}\n{{ '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n'}}{% if message['content'] is not none %}\n{{ '>>>all\n' + message['content'] }}{% endif %}\n{% if 'tool_calls' in message and message['tool_calls'] is not none %}\n{% for tool_call in message['tool_calls'] %}\n{{ '>>>' + tool_call['function']['name'] + '\n' + tool_call['function']['arguments'] }}{% endfor %}\n{% endif %}\n{{ '<|eot_id|>' }}{% endif %}\n{% endfor %}\n{% if add_generation_prompt %}{{ '<|start_header_id|>assistant<|end_header_id|>\n\n' }}{% endif %}",
2054
  "clean_up_tokenization_spaces": true,
2055
  "eos_token": "<|eot_id|>",
2056
  "legacy": true,
 
2050
  }
2051
  },
2052
  "bos_token": "<|begin_of_text|>",
2053
+ "chat_template": "{% for message in messages %}\n{% if message['role'] == 'user' or message['role'] == 'system' %}\n{{ '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n' + message['content'] + '<|eot_id|>' }}{% elif message['role'] == 'tool' %}\n{{ '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n' + message['content'] + '<|eot_id|>' }}{% else %}\n{{ '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n'}}{% if message['content'] is not none %}\n{{ '>>>all\n' + message['content'] }}{% endif %}\n{% if 'tool_calls' in message and message['tool_calls'] is not none %}\n{% for tool_call in message['tool_calls'] %}\n{{ '>>>' + tool_call['function']['name'] + '\n' + tool_call['function']['arguments'] }}{% endfor %}\n{% endif %}\n{{ '<|eot_id|>' }}{% endif %}\n{% endfor %}\n{% if add_generation_prompt %}{{ '<|start_header_id|>assistant<|end_header_id|>\n\n>>>' }}{% endif %}",
2054
  "clean_up_tokenization_spaces": true,
2055
  "eos_token": "<|eot_id|>",
2056
  "legacy": true,