TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: Fructose – LLM calls as strongly typed functions

218 pointsby eduntemanabout 1 year ago
Hi HN! Erik here from Banana (formerly the serverless GPU platform), excited to show you what we’ve been working on next:<p>Fructose<p>Fructose is a python package to call LLMs as strongly typed functions. It uses function type signatures to guide the generation and guarantee a correctly typed output, in whatever basic&#x2F;complex python datatype requested.<p>By guaranteeing output structure, we believe this will enable more complex applications to be built, interweaving code with LLMs with code. For now, we’ve shipped Fructose as a client-only library simply calling gpt-4 (by default) with json mode, pretty simple and not unlike other packages such as marvin and instructor, but we’re also working on our own lightweight formatting model that we’ll host and&#x2F;or distribute to the client, to help reduce token burn and increase accuracy.<p>We figure, no time like the present to show y’all what we’re working on! Questions, compliments, and roasts welcomed.

28 comments

nextosabout 1 year ago
IMHO, in the future programming may look similar to this. Write a type declaration for a function with an expressive type system, e.g. refinement types. Then use LLMs + SAT&#x2F;SMT to generate provably correct code.<p>This strikes a happy medium, where machines are assisting programmers, making them much more productive. Yet the resulting code is understandable as a human has decomposed everything into functions, and also robust as it is formally verified.<p>I am working on a F# proof-of-concept system like this, there are other alternatives around implemented in Haskell and other languages with varying levels of automation. It is potentially an interesting niche for a startup.
评论 #39620622 未加载
评论 #39621294 未加载
评论 #39623421 未加载
评论 #39620986 未加载
评论 #39621534 未加载
评论 #39624375 未加载
评论 #39620210 未加载
评论 #39620319 未加载
minimaxirabout 1 year ago
This approach may be too high-level &quot;magic&quot; to the point of being difficult to work with and iterate upon.<p>Looking at the prompt templates (<a href="https:&#x2F;&#x2F;github.com&#x2F;bananaml&#x2F;fructose&#x2F;tree&#x2F;main&#x2F;src&#x2F;fructose&#x2F;templates">https:&#x2F;&#x2F;github.com&#x2F;bananaml&#x2F;fructose&#x2F;tree&#x2F;main&#x2F;src&#x2F;fructose&#x2F;...</a> ), they use LangChain-esque &quot;just try to make the output to be valid JSON&quot; when APIs such as GPT-4 Turbo which this model uses by default now support function calling&#x2F;structured data natively and do a very good job of it (<a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=38782678">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=38782678</a>), and libraries such as outlines (<a href="https:&#x2F;&#x2F;github.com&#x2F;outlines-dev&#x2F;outlines">https:&#x2F;&#x2F;github.com&#x2F;outlines-dev&#x2F;outlines</a>) which is more complex but can better ensure a dictionary output for local LLMs.
评论 #39619647 未加载
icyfoxabout 1 year ago
Big proponent of guaranteed outputs for LLMs. I wrote a library awhile back (gpt-json) that did something similar by querying the OpenAI API. At the end of the day though while their responses are _highly likely_ to be valid JSON they&#x27;re not guaranteed. There&#x27;s only so much that can be done with remote calls to their model&#x27;s black box.<p>The future here really lies in compiling down context free grammars. They let you model json, yml, csv, and other programming languages as finite state machines that can force LLM transitions. They end up being pretty magical: you can force value typing, enums, and syntax validation of multivariate payloads. For use in data pipelines they can&#x27;t be beat.<p>I did some experiments a few weeks ago on training models to generate these formats explicitly with jsonformers&#x2F;outlines. Finetuning in the right format is still important to maximize output. You can end up seeing a 7% lift if you finetune explicitly for your desired format. [^1] At inference time the CFGs will constrain your model to do what it&#x27;s actually intended to.<p>[^1]: <a href="https:&#x2F;&#x2F;freeman.vc&#x2F;notes&#x2F;constraining-llm-outputs" rel="nofollow">https:&#x2F;&#x2F;freeman.vc&#x2F;notes&#x2F;constraining-llm-outputs</a>
评论 #39624692 未加载
评论 #39624546 未加载
评论 #39625194 未加载
itfollowsthenabout 1 year ago
&gt; not unlike other packages such as marvin<p>This feels pretty much identical to Marvin? Like the entire API?<p>From a genuine place of curiosity: I get that your prompts are different, but like why in the name of open source would you just not contribute to these libraries instead of starting your own from scratch?
评论 #39620789 未加载
评论 #39620337 未加载
babyshakeabout 1 year ago
Does anyone else get bothered by how this seemingly results in code that won&#x27;t compile?<p>Instead of this:<p>@ai() def describe(animals: list[str]) -&gt; str: &quot;&quot;&quot; Given a list of animals, use one word that&#x27;d describe them all. &quot;&quot;&quot;<p>it would seem a lot more intuitive to do this:<p>def describe(animals: list[str]) -&gt; str: return ai(&quot;&quot;&quot;Given a list of animals, use one word that&#x27;d describe them all.&quot;&quot;&quot;, animals)
评论 #39624641 未加载
评论 #39623633 未加载
评论 #39621449 未加载
mattewabout 1 year ago
Good stuff. How does this compare to Instructor? I’ve been using this extensively<p><a href="https:&#x2F;&#x2F;jxnl.github.io&#x2F;instructor&#x2F;" rel="nofollow">https:&#x2F;&#x2F;jxnl.github.io&#x2F;instructor&#x2F;</a>
评论 #39620242 未加载
imtringuedabout 1 year ago
Since you are going down this route, I would recommend you guys to build some sort of unit test driven fine tuning framework, where you may provide input output examples expressed as simple function calls. You could then let the LLM generate examples and check them using the unit tests and keep the valid results to build up a valid data set. For bonus points, the unit tests themselves could also call the LLM to check if the output passes criteria expressed in natural language or not.
shykesabout 1 year ago
I love this emerging space at the intersection of programming and LLMs. It goes beyond having the LLMs generate code: that&#x27;s an obvious and amazing use case, but it&#x27;s far from the only one.<p>Another project I&#x27;m excited about in this area is GPTScript, which launched last week: <a href="http:&#x2F;&#x2F;github.com&#x2F;gptscript-ai&#x2F;gptscript">http:&#x2F;&#x2F;github.com&#x2F;gptscript-ai&#x2F;gptscript</a>.
AmanKishoreabout 1 year ago
This is much nicer than calling GPT in the middle of my code. Honestly the aesthetics of Fructose just make the code so much neater
评论 #39620587 未加载
bagelsabout 1 year ago
How do you guarantee output structure? Does it ever fail to conform?
评论 #39619610 未加载
iAkashPaulabout 1 year ago
TGI just integrated Guidance in 1.4.3, that by itself can support both grammar&#x2F;JSON&#x2F;Pydantic &amp; tool invocation&#x2F;function calling.<p>Langchain &amp; Llamaindex plus Fructose really need to skip the structure adherence work &amp; move to chunking&#x2F;KG generation since that&#x27;s the next pain point to tackle.
评论 #39619922 未加载
评论 #39620125 未加载
ilakshabout 1 year ago
I find it grating that all of these types of things say &quot;LLMs&quot; when in fact they literally only work with OpenAI. There are hundreds of variations of LLM models. When it works with only gpt-4-turbo or gpt-3.5-turbo, it&#x27;s inaccurate to say it&#x27;s a tool for LLMs in general.
评论 #39621686 未加载
评论 #39624917 未加载
Sai_about 1 year ago
Maybe I’m not the audience for this but how is this a “product”. Coercing LLM outputs into a function call is built into OpenAI itself.<p>What is fructose doing extra here? It’s like productising copy&amp;paste which every modern OS has, no?
campersabout 1 year ago
Nice, I&#x27;ve just started building something similar in TypeScript. I wasn&#x27;t a big fan of the Langchain model. I wanted to develop with normal functions in an imperative manner so the code is very easy to read. I&#x27;m also using decorators to add the required functionality to workflow steps so I can support retries, and build something like LangSmith on top too.<p>So far I&#x27;ve been able to make a little workflow that can complete real simple infrastructure requests in JIRA. Pick the right repository, make the changes, compile, and push up the merge request.
评论 #39624511 未加载
nicoabout 1 year ago
This is great, it might be really helpful for what I’ve been working on<p>Just put together a small project that uses GPT to find good job matches[1]<p>One of the most challenging things in making it useful for more users, is managing the prompt that include several pieces of user input, and need to return a specific format, with a structure that depends on what the user wants to include in the prompt<p>What’s the typical use case for this? Who needs it the most right now?<p>Thank you!<p>[1] <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=39621373#39624542">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=39621373#39624542</a>
msp26about 1 year ago
So what is this actually putting into the prompt to guide generation? I dislike libraries that come with a lot of pointless abstraction.<p>I&#x27;m about to write something that generates typescript code from pydantic models. If this just works out of box, it would make me very happy.<p>I&#x27;ll take a look through the repo tomorrow, sorry if my response is a little lazy, I just got off work.
judiciousabout 1 year ago
Definitely very excited to see this be a thing. Genuinely liked the approach to make function calls strongly typed and rely on functional programming principles.<p>During my senior year, I worked on a research project very similar to this and I’m glad to see this out there for everyone. I’d love to connect with the team if possible!
评论 #39624426 未加载
jsightabout 1 year ago
I love the concept, but I&#x27;d really prefer being able to use it against local llms (localai, ollama, etc).
评论 #39620277 未加载
评论 #39619510 未加载
eduntemanabout 1 year ago
Thanks everyone for a great Show HN! This turned out much larger than expected, thanks for all the comments and github stars. We had a fun time with it.<p>Lots of takeaways, blogs to read, things to implement, issues to address. On it!
bidditabout 1 year ago
I&#x27;ve done a lot of work over the last year wrangling LLM outputs - both from the OpenAI API as well as local LLMs.<p>What are the benefits of using Fructose over LMQL, Guidance or OpenAI&#x27;s function calling?
评论 #39619741 未加载
hedgehogabout 1 year ago
How does Fructose relate or compare to Instructor (<a href="https:&#x2F;&#x2F;github.com&#x2F;jxnl&#x2F;instructor">https:&#x2F;&#x2F;github.com&#x2F;jxnl&#x2F;instructor</a>)?
评论 #39620119 未加载
评论 #39620153 未加载
jonathan-adlyabout 1 year ago
Very Cool! Would it work for Pydantic out of the box? Or that&#x27;s something coming along?
评论 #39620014 未加载
justanotheratomabout 1 year ago
Obvious question - how is this better than marvin, instructor, outlines.
yieldcrvabout 1 year ago
fyi: LM Studio can host a server that uses the OpenAI api to whatever model you are using locally<p>So as long as this library can be directed to localhost or configured, it can use any LLM
politelemonabout 1 year ago
Are you planning to add other types like Claude or Llama2?
评论 #39620171 未加载
FrustratedMonkyabout 1 year ago
Can this be a F# Type Provider?
评论 #39621482 未加载
yumidarwi001about 1 year ago
Derick1_1gc &#x2F;insgragam
creatonezabout 1 year ago
Yet another implementation of <a href="https:&#x2F;&#x2F;esolangs.org&#x2F;wiki&#x2F;English" rel="nofollow">https:&#x2F;&#x2F;esolangs.org&#x2F;wiki&#x2F;English</a>