Skip to content

Commit 4e32549

Browse files
authored
Merge pull request #138 from anaregdesign/fix/prompt
fix: prompt chet_completion -> responses
2 parents 80791e8 + 9e82916 commit 4e32549

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

src/openaivec/prompt.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
from xml.etree import ElementTree
4949

5050
from openai import OpenAI
51-
from openai.types.chat import ParsedChatCompletion
51+
from openai.types.responses import ParsedResponse
5252
from pydantic import BaseModel
5353

5454
__all__ = [
@@ -116,7 +116,7 @@ class Response(BaseModel):
116116
iterations: List[Step]
117117

118118

119-
_prompt: str = """
119+
_PROMPT: str = """
120120
<Prompt>
121121
<Instructions>
122122
<Instruction id="1">
@@ -425,35 +425,24 @@ def improve(
425425
temperature (float, optional): Sampling temperature. Defaults to 0.0.
426426
top_p (float, optional): Nucleus sampling parameter. Defaults to 1.0.
427427
428-
Raises:
429-
ValueError: If fewer than five examples are present.
430-
431428
Returns:
432429
FewShotPromptBuilder: The current builder instance containing the refined prompt and iteration history.
433430
"""
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.")
437431

438-
completion: ParsedChatCompletion[Response] = client.beta.chat.completions.parse(
432+
response: ParsedResponse[Response] = client.responses.parse(
439433
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(),
447436
temperature=temperature,
448437
top_p=top_p,
449-
response_format=Response,
438+
text_format=Response,
450439
)
451440

452441
# keep the original prompt
453442
self._steps = [Step(id=0, analysis="Original Prompt", prompt=self._prompt)]
454443

455444
# add the histories
456-
for step in completion.choices[0].message.parsed.iterations:
445+
for step in response.output_parsed.iterations:
457446
self._steps.append(step)
458447

459448
# set the final prompt

tests/test_prompt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class TestAtomicPromptBuilder(unittest.TestCase):
1313
def setUp(self):
1414
self.client: OpenAI = OpenAI()
15-
self.model_name: str = "gpt-4o-mini"
15+
self.model_name: str = "gpt-4.1-nano"
1616

1717
def test_improve(self):
1818
prompt: str = (

0 commit comments

Comments
 (0)