Skip to content

add snippets tests & response_format support #1524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

TGlide
Copy link
Member

@TGlide TGlide commented Jun 11, 2025

No description provided.

@Wauplin
Copy link
Contributor

Wauplin commented Jun 18, 2025

Hey @TGlide let me know if you want any guidance about inference snippets or a review :)

@TGlide
Copy link
Member Author

TGlide commented Jul 11, 2025

Hi @Wauplin sorry for the delay! Yes, I would love a review, specially to see if I've gone about this the right way.

Copy link
Contributor

@Wauplin Wauplin left a comment

Choose a reason for hiding this comment

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

Hey @TGlide , understood! I've had a first look at it, let me know if you have extra questions :)

Copy link
Contributor

Choose a reason for hiding this comment

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

sorry about all the work done on this module but tests are actually defined in the tasks-gen package (see ./tasks-gen/scripts/generate-snippets-fixtures.ts) and fixtures are auto-generated + committed in ./packages/tasks-gen/snippets-fixtures. This way we can easily spot in a PR what has changed and if the snippets are looking good.

@@ -3,6 +3,9 @@
*
* Using src/scripts/inference-codegen
*/

import type { ChatCompletionInputGrammarType } from "../chat-completion/inference.js";
Copy link
Contributor

Choose a reason for hiding this comment

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

this is not needed in ASR types I believe

temperature?: GenerationParameters["temperature"];
max_tokens?: GenerationParameters["max_new_tokens"];
top_p?: GenerationParameters["top_p"];
response_format?: Record<string, unknown>;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there is a confusion between the Chat Completion API that accepts a response_format and the Text Generation API that accepts a grammar input.

@@ -408,6 +436,46 @@ function formatBody(obj: object, format: "curl" | "json" | "python" | "ts"): str
}
}

function formatPythonValue(obj: unknown, depth?: number): string {
Copy link
Contributor

Choose a reason for hiding this comment

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

I start to really think we should first generate the snippets and then format it. Seems that there are a few solutions although not very popular (blackjs, prettier/plugin-python). For now, let's keep it like this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, was this code auto-generate or written manually? (if yes, better to mention it in docstring)

Copy link
Contributor

Choose a reason for hiding this comment

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

(note to myself, maybe a single-file python formatter would be enough given our small requirements. Here's an example)

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.

2 participants