Hacker News new | past | comments | ask | show | jobs | submit login

Here's 40 lines of python code that I've found to be unreasonably effective at accomplishing something similar:

https://github.com/jiggy-ai/pydantic-chatcompletion/blob/mas...




Thanks. Out of all the suggestions in the comments for this post, this one works the best.

And in fact it is only one line, not 40:

    "Please respond ONLY with valid json that conforms to this pydantic json_schema: {model_class.schema_json()}. Do not include additional text other than the object json as we will load this object with json.loads() and pydantic."


yes thats actually it


Thanks, I'm also doing something similar and figured out that asking a question with examples as `user`, adding the perfect response as `assistant`, replying with `Perfect. Now do this {}` works really well and cuts of a lot of trial/error.


Thanks! I have something similar that I've been using and struggling to keep consistent. I like that this is a relatively small package, I'll probably end up using it to play around with.


Very cool. Out of curiosity, for the retries why are the errors appended as system messages as opposed to appending to the user message? And in either case, would it help to prepend the error with something like “Be sure to avoid outputting something that would cause this error:”?


based on my experience with GPT-4 in coding tasks it responds extremely well to just appended raw error output text without additional explanation.


I dont see how these infinite loops are a good idea... You never sure if you actually getting a good result ?

What is the failure rate?


Um, what? This is a standard retry loop. It's just generally good practice.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: