Show HN: GPT-JSON – Structured and typehinted GPT responses in Python
21–30 of 76 posts
Re: Show HN: GPT-JSON – Structured and typehinted GPT responses in Python
#22It takes the expected return type of a function, translates it into a JSON Schema, queries OpenAI, validates the response, and then magically returns the response as typed output.
Re: Show HN: GPT-JSON – Structured and typehinted GPT responses in Python
#23"Yes, integrating the CUE language with GPT-JSON can potentially lead to improvements in its capability. CUE, short for Configuration, Unification, and Environment, is an open-source data constraint language designed to simplify the definition, generation, and validation of data in structured formats, like JSON, YAML, and others.
Integrating CUE with GPT-JSON can bring several benefits:
1) Validation: By using CUE, you can define schemas for the input and output JSON, which helps in validating the data structure and ensuring it adheres to the expected format. This can help reduce errors and improve the quality of the interaction with the GPT model.
2) Simplification: CUE can help simplify the process of defining and generating JSON inputs and outputs for GPT-JSON. By providing a more concise and expressive syntax, CUE can make it easier to craft structured inputs and outputs, which can be especially helpful when working with complex data structures.
3) Interoperability: Integrating CUE can improve the interoperability between GPT-JSON and other systems or applications. With CUE's ability to work with multiple data formats (such as JSON, YAML, or HCL), it becomes easier to integrate GPT-JSON with various tools and platforms.
To integrate CUE with GPT-JSON, you would need to follow these general steps:
1) Define CUE schemas for the input and output JSON structures used by GPT-JSON.
2) Use the CUE language to validate and generate input JSON for GPT-JSON.
3) Process the output JSON generated by GPT-JSON using CUE to ensure it adheres to the defined schema and transform it as needed.
Integrating CUE with GPT-JSON can improve the overall robustness and ease of use of the library, making it more accessible and useful for a wider range of applications."
Re: Show HN: GPT-JSON – Structured and typehinted GPT responses in Python
#24 messages=[
GPTMessage(
role=GPTMessageRole.SYSTEM,
content=SYSTEM_PROMPT,
),
GPTMessage(
role=GPTMessageRole.USER,
content="Text: I love this product. It's the best thing ever!",
)
]
Try: messages=(
("system", SYSTEM_PROMPT),
("user", "Text: I love this product. It's the best thing ever!")
)
Or: messages=(
SystemMsg(SYSTEM_PROMPT),
UserMsg("Text: I love this product. It's the best thing ever!")
)
This is still Python, not Java.Re: Show HN: GPT-JSON – Structured and typehinted GPT responses in Python
#25Here'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...
Re: Show HN: GPT-JSON – Structured and typehinted GPT responses in Python
#26Re: Show HN: GPT-JSON – Structured and typehinted GPT responses in Python
#27Here'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...
Re: Show HN: GPT-JSON – Structured and typehinted GPT responses in Python
#28I like the idea, but I think a library that focuses on producing requests and parsing responses according to schema is better. Sending requests to the server is orthogonal to the purpose. What we've found useful in practice in dealing with similar problems: - Use json5 instead of json when parsing. It allows trailing commas. - Don't let it respond in true/false. Instead, ask it for a short sentence explaining whether…
Have you tried just getting it to do both? It reasons far better given some space to think, so I often have it explain things first then give the answer. You're effectively then using gpt for the extraction too.
This hugely improved the class hierarchies it was creating for me, significantly improving the reuse of classes and using better classes for fields too.
Re: Show HN: GPT-JSON – Structured and typehinted GPT responses in Python
#29Re: Show HN: GPT-JSON – Structured and typehinted GPT responses in Python
#30You can use simpler types. Instead of : messages=[ GPTMessage( role=GPTMessageRole.SYSTEM, content=SYSTEM_PROMPT, ), GPTMessage( role=GPTMessageRole.USER, content="Text: I love this product. It's the best thing ever!", ) ] Try: messages=( ("system", SYSTEM_PROMPT), ("user", "Text: I love this product. It's the best thing ever!") ) Or: messages=( SystemMsg(SYSTEM_PROMPT), UserMsg("Text: I love this product. It's the b…