Skip to content

Conversation

@jakedahn
Copy link
Contributor

@jakedahn jakedahn commented Apr 1, 2025

This PR introduces jsonMode capability to the toolshed llm api endpoints.

Unfortunately, each language model provider has a different strategy for allowing the return of json data. We primarily use Claude and Groq at the moment, claude only supports prompting (and they provide some instructions in their docs for how to do this better), and in groq you must prompt but can also require that the response is valid json.

So this PR introduces some special casing prompt additions to various models when jsonMode: true is set as an api request parameter.

I also removed a handful of never-used language models to clean up some dependencies and surfaces area we need to support.

@jakedahn
Copy link
Contributor Author

jakedahn commented Apr 1, 2025

This should fix #965

Copy link
Contributor

@bfollington bfollington left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal, but a couple comments.

You can merge without my re-review.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider: mode: 'json'? seems more common to me

Comment on lines 34 to 46
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on adding tests for this? It's got a bunch of specific edge cases so tests would act as documentation of expected behavior etc.

Might be generateable?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Deno.test/t.step interface was used in basic-flow to handle some integration/astral slowness/assertions during development, but could probably be ported back to the BDD style -- if we don't have an explicit reason to use the inner t.step interface, consider the BDD wrapper around stepped tests e.g. import { describe, it, beforeEach } from "@std/testing/bdd"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 slimmer deps!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason we want to skip caching for json requests?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh, this should be the cacheKey earlier - don't recompute it!

@jakedahn jakedahn merged commit a7876f6 into main Apr 3, 2025
6 checks passed
@jakedahn jakedahn deleted the llm-jsonmode branch April 3, 2025 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants