(self, prompt, system_prompt, seed=-1, *args, **kwargs)
| 250 | self.retry_times = retry_times |
| 251 | |
| 252 | def extend(self, prompt, system_prompt, seed=-1, *args, **kwargs): |
| 253 | messages = [{ |
| 254 | 'role': 'system', |
| 255 | 'content': system_prompt |
| 256 | }, { |
| 257 | 'role': 'user', |
| 258 | 'content': prompt |
| 259 | }] |
| 260 | |
| 261 | exception = None |
| 262 | for _ in range(self.retry_times): |
| 263 | try: |
| 264 | response = dashscope.Generation.call( |
| 265 | self.model, |
| 266 | messages=messages, |
| 267 | seed=seed, |
| 268 | result_format='message', # set the result to be "message" format. |
| 269 | ) |
| 270 | assert response.status_code == HTTPStatus.OK, response |
| 271 | expanded_prompt = response['output']['choices'][0]['message'][ |
| 272 | 'content'] |
| 273 | return PromptOutput( |
| 274 | status=True, |
| 275 | prompt=expanded_prompt, |
| 276 | seed=seed, |
| 277 | system_prompt=system_prompt, |
| 278 | message=json.dumps(response, ensure_ascii=False)) |
| 279 | except Exception as e: |
| 280 | exception = e |
| 281 | return PromptOutput( |
| 282 | status=False, |
| 283 | prompt=prompt, |
| 284 | seed=seed, |
| 285 | system_prompt=system_prompt, |
| 286 | message=str(exception)) |
| 287 | |
| 288 | def extend_with_img(self, |
| 289 | prompt, |
nothing calls this directly
no test coverage detected