|
48 | 48 | from xml.etree import ElementTree
|
49 | 49 |
|
50 | 50 | from openai import OpenAI
|
51 |
| -from openai.types.chat import ParsedChatCompletion |
| 51 | +from openai.types.responses import ParsedResponse |
52 | 52 | from pydantic import BaseModel
|
53 | 53 |
|
54 | 54 | __all__ = [
|
@@ -116,7 +116,7 @@ class Response(BaseModel):
|
116 | 116 | iterations: List[Step]
|
117 | 117 |
|
118 | 118 |
|
119 |
| -_prompt: str = """ |
| 119 | +_PROMPT: str = """ |
120 | 120 | <Prompt>
|
121 | 121 | <Instructions>
|
122 | 122 | <Instruction id="1">
|
@@ -425,35 +425,24 @@ def improve(
|
425 | 425 | temperature (float, optional): Sampling temperature. Defaults to 0.0.
|
426 | 426 | top_p (float, optional): Nucleus sampling parameter. Defaults to 1.0.
|
427 | 427 |
|
428 |
| - Raises: |
429 |
| - ValueError: If fewer than five examples are present. |
430 |
| -
|
431 | 428 | Returns:
|
432 | 429 | FewShotPromptBuilder: The current builder instance containing the refined prompt and iteration history.
|
433 | 430 | """
|
434 |
| - # At least 5 examples are required to enhance the prompt. |
435 |
| - if len(self._prompt.examples) < 5: |
436 |
| - raise ValueError("At least 5 examples are required to enhance the prompt.") |
437 | 431 |
|
438 |
| - completion: ParsedChatCompletion[Response] = client.beta.chat.completions.parse( |
| 432 | + response: ParsedResponse[Response] = client.responses.parse( |
439 | 433 | model=model_name,
|
440 |
| - messages=[ |
441 |
| - {"role": "system", "content": _prompt}, |
442 |
| - { |
443 |
| - "role": "user", |
444 |
| - "content": Request(prompt=self._prompt).model_dump_json(), |
445 |
| - }, |
446 |
| - ], |
| 434 | + instructions=_PROMPT, |
| 435 | + input=Request(prompt=self._prompt).model_dump_json(), |
447 | 436 | temperature=temperature,
|
448 | 437 | top_p=top_p,
|
449 |
| - response_format=Response, |
| 438 | + text_format=Response, |
450 | 439 | )
|
451 | 440 |
|
452 | 441 | # keep the original prompt
|
453 | 442 | self._steps = [Step(id=0, analysis="Original Prompt", prompt=self._prompt)]
|
454 | 443 |
|
455 | 444 | # add the histories
|
456 |
| - for step in completion.choices[0].message.parsed.iterations: |
| 445 | + for step in response.output_parsed.iterations: |
457 | 446 | self._steps.append(step)
|
458 | 447 |
|
459 | 448 | # set the final prompt
|
|
0 commit comments