Live data from Hacker News

Show HN: GPT-JSON – Structured and typehinted GPT responses in Python

github.com

51–60 of 76 posts

Re: Show HN: GPT-JSON – Structured and typehinted GPT responses in Python

#51

I Found that LLMs are pretty good with TOML. The multiline strings are also a real bonus. One thing I thought that was interesting is that sometimes the LLM will mistake the triple quoutes for the backticks so it will output something like this ``` [TOML] key=""" value """ """

You can instruct the LLM on what the outer markers are.

> Generate some TOML for me, surround the output with a pair of triple equal signs (===).

Re: Show HN: GPT-JSON – Structured and typehinted GPT responses in Python

#53

Is there a reason we won’t have LLMs that only speak in JSON? These JSON hacks are clever and cool but feel like they’ll be obsolete in 6 weeks.

A lot of their value is turning unstructured text or user intent into the structured data. Even if the primary input is JSON, you want to explain what to do with it in words, and then get JSON back.

Why do you think they will be obsolete in 6 weeks?

Re: Show HN: GPT-JSON – Structured and typehinted GPT responses in Python

#54

You 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…

We've been using a variation like this to great effect:

    TYPES: [string, int, bool, float, uuid, datetime, email, url]
    RELATIONS: [belongs-to, has-one, has-many, many-to-many]

    SCHEMA: """
    {
      "Datamodel": {
        "Name": "",
        "Models": {
          "": {
            "": "",
            "": "",
            "$relations": {
              "": {
                "name": "",
                "type": "",
                "model": ""
              },
              "": {
                ...
              }
            }
          },
          "": {
            ...
          }
        }
      }
    }
    """
To let users write things like this: https://twitter.com/verdverm/status/1652504163635347456

Re: Show HN: GPT-JSON – Structured and typehinted GPT responses in Python

#55
post #21

I built zod-chatgpt https://github.com/olup/zod-chatgpt a couple of weeks ago to serve same purpose in typescript

Yes, this is a very similar technique that I have been using and it works great. One suggestion of something that worked well for me was to use safeParse instead of parse. Then if it doesn’t pass validation, you can retry by passing in the JSON object and the validation error messages. You could also use tricks like starting with a smaller model, then try larger models if you hit a validation failure. Not a great approach for real-time chat but very useful for when you need high-quality results.

Re: Show HN: GPT-JSON – Structured and typehinted GPT responses in Python

#56

I've been interfacing with GPT programmatically for a little while now, leveraging it's "soft and fuzzy" interface to produce hard / machine-readable results. JSON was the format that felt best-suited for the job. I see a ton of code in this project, and I don't know what most of it does. As far as GPT troubles with JSON, I'll add a couple: sometimes it likes to throw comments in there as if it was JS. And sometimes…

But the problem is the 99%, no ?

Re: Show HN: GPT-JSON – Structured and typehinted GPT responses in Python

#57
In the last 24 hours I've seen a bunch of projects doing LLM -> JSON. I think we want to be focusing on markdown instead. An intuition I have developed is that an ideal prompt has a very clear narrative structure and very tight "semantic locality" (the instruction is at the end, the most salient data is close to the instruction, etc).

JSON is admittedly way easier to work with up front, but markdown seems to be a more scaleable choice.

Of course, this is all very much an opinion and highly anecdotal at the moment.

Re: Show HN: GPT-JSON – Structured and typehinted GPT responses in Python

#58

I've been interfacing with GPT programmatically for a little while now, leveraging it's "soft and fuzzy" interface to produce hard / machine-readable results. JSON was the format that felt best-suited for the job. I see a ton of code in this project, and I don't know what most of it does. As far as GPT troubles with JSON, I'll add a couple: sometimes it likes to throw comments in there as if it was JS. And sometimes…

Why not both? You can tell it in the prompt what you want and still constrain the output programmatically.

Also note that the output still depends on a random sampling of the next token according to the distribution that the net gives you - so there is a lot of genuine randomness in the model's behaviour. And because each sampled token influences the rest of the response, this randomness will become stronger the longer the response is.

So if you already know you're only interested in a particular subset of tokens, it makes sense to me to clamp the distribution to only those tokens and keep the model from getting onto the "wrong path" in the first place.

Also, pragmatically, if you can get the model to restrict itself to JSON without telling it in the prompt, you're saving that part if the context window for better uses.

Re: Show HN: GPT-JSON – Structured and typehinted GPT responses in Python

#59

Is there a reason we won’t have LLMs that only speak in JSON? These JSON hacks are clever and cool but feel like they’ll be obsolete in 6 weeks.

Fingers crossed OpenAI / Anthropic / etc do this! Would make working with these APIs for prediction projects that much easier.

Technically speaking it's pretty to force the model into an valid JSON-schema if you have access to the inference autoregressive loop and the logit activations. You can either force known areas of the template to a prefixed template, or fill in the basic JSON wrapper and force the model to choose arbitrary keys and values.

Imagine it might come down to how much of their usage is on generating text vs generating structured prediction payloads.

Re: Show HN: GPT-JSON – Structured and typehinted GPT responses in Python

#60
post #56

I've been interfacing with GPT programmatically for a little while now, leveraging it's "soft and fuzzy" interface to produce hard / machine-readable results. JSON was the format that felt best-suited for the job. I see a ton of code in this project, and I don't know what most of it does. As far as GPT troubles with JSON, I'll add a couple: sometimes it likes to throw comments in there as if it was JS. And sometimes…

But the problem is the 99%, no ?

It works fine 99% of the time by just using a small amount of extra instruction in the actual prompt. The method GP describes works in any language with just the basic building blocks of http requests, regexp, and a json decoder.

Why do we need a library for this?

Post reply on HN