Prompt engineering for Function Call prompts.
(self, context, params=None, function=None)
| 9328 | return output_response |
| 9329 | |
| 9330 | def fc_prompt_engineer(self, context, params=None, function=None): |
| 9331 | |
| 9332 | """ Prompt engineering for Function Call prompts. """ |
| 9333 | |
| 9334 | if not params: |
| 9335 | params = self.primary_keys |
| 9336 | |
| 9337 | # add safety check in looking for default self.function pulled from model card |
| 9338 | if not function: |
| 9339 | if self.function: |
| 9340 | if isinstance(self.function,list): |
| 9341 | if len(self.function) > 0: |
| 9342 | function = self.function[0] |
| 9343 | else: |
| 9344 | function = self.function |
| 9345 | |
| 9346 | # if not successful identifying a function, then choose 'classify' by default |
| 9347 | if not function: |
| 9348 | function = "classify" |
| 9349 | |
| 9350 | # prepare SLIM prompt |
| 9351 | class_str = "" |
| 9352 | for key in params: |
| 9353 | class_str += str(key) + ", " |
| 9354 | if class_str.endswith(", "): |
| 9355 | class_str = class_str[:-2] |
| 9356 | |
| 9357 | f = str(function) |
| 9358 | |
| 9359 | # key templating format for SLIM function calls |
| 9360 | full_prompt = "<human>: " + context + "\n" + "<{}> {} </{}>".format(f, class_str, f) + "\n<bot>:" |
| 9361 | |
| 9362 | full_prompt = full_prompt + self.trailing_space |
| 9363 | |
| 9364 | return full_prompt |
| 9365 | |
| 9366 | def register_top_logits(self, next_token_logit): |
| 9367 |