stanfordnlp / dspy

DSPy: The framework for programming—not prompting—foundation models
https://dspy-docs.vercel.app/
MIT License
16.15k stars 1.25k forks source link

TypedPredictor:Too many retries trying to get the correct output format. #1246

Open chenk-gd opened 1 month ago

chenk-gd commented 1 month ago

I wrote a demo, but it throws an exception.

class APISpec(pydantic.BaseModel):
    spec: str

class Code(pydantic.BaseModel):
    code: str

class APISpecSignature(Signature):
    template: APISpec = InputField(desription="API Specification")
    language: str = InputField(description="Language of the generated code.")
    code: Code = OutputField(desription="Code generated according to the api specification and the specified language.")

predictor = TypedPredictor(APISpecSignature)
prediction = predictor(
    template=APISpec(spec=spec),
    language='python'
)

it throws

ValueError: ('Too many retries trying to get the correct output format. Try simplifying the requirements.', {'code': "ValueError('json output should start and end with { and }')"})

I've tried several models, including GPT-4o, but all have failed. So, is there anything wrong with my code?

chenk-gd commented 1 month ago

After changing the 'template' field to 'spec' in the APISpecSignature class, the program ran without issues. DSPy heavily relies on variable naming?