(self, **kwargs)
| 164 | self.n_samples = n_samples |
| 165 | |
| 166 | def __call__(self, **kwargs): |
| 167 | # if any input kwargs is chat prompt, convert to text prompt |
| 168 | kwargs = { |
| 169 | k: chat_prompt_to_text_prompt(v, for_completion=False) if is_chat_prompt(v) else v |
| 170 | for k, v in kwargs.items() |
| 171 | } |
| 172 | if is_chat_prompt(self.prompt): |
| 173 | prompt = [] |
| 174 | for msg in self.prompt: |
| 175 | formatted_msg = copy.copy(msg) |
| 176 | if "content" in formatted_msg: |
| 177 | formatted_msg["content"] = format_necessary(formatted_msg["content"], **kwargs) |
| 178 | prompt.append(formatted_msg) |
| 179 | else: |
| 180 | # Prompt is a string |
| 181 | prompt = format_necessary(self.prompt, **kwargs) |
| 182 | |
| 183 | result = self.completion_fn( |
| 184 | prompt=prompt, |
| 185 | max_tokens=self.max_tokens, |
| 186 | temperature=self.temperature, |
| 187 | top_p=1, |
| 188 | frequency_penalty=0, |
| 189 | presence_penalty=0, |
| 190 | n=(1 if self.n_samples is None else self.n_samples), |
| 191 | **self.completion_kwargs, |
| 192 | ) |
| 193 | sampled = result.get_completions()[0] |
| 194 | return sampled, prompt |
nothing calls this directly
no test coverage detected