Skip to content
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

feat: Scaffold model invocation params form (#5040) #5045

Merged
merged 12 commits into from
Oct 22, 2024

Conversation

cephalization
Copy link
Contributor

@cephalization cephalization commented Oct 16, 2024

invocation.params.form.mov

@mikeldking mikeldking changed the base branch from playground to main October 16, 2024 20:07
@cephalization cephalization force-pushed the cephalization/invocation-parameters-ui branch 2 times, most recently from cdaaeaa to e78d8fd Compare October 18, 2024 15:53
@cephalization cephalization marked this pull request as ready for review October 18, 2024 18:16
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Oct 18, 2024
@cephalization
Copy link
Contributor Author

I think it's a known bug but o1 fails due to lack of stream: false support in the backend

@cephalization cephalization force-pushed the cephalization/invocation-parameters-ui branch from f7c7e0d to 4b0c2d8 Compare October 21, 2024 14:49
/**
* Form field for a single invocation parameter.
*
* TODO(apowell): Should this be generic over the schema field data type? There
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this comment mean exactly? If it's a real todo might add an issue and link it here. The one below seems like a real follow up so might be nice to have the issue

);
});
return (
<Flex direction="column" gap="size-200">
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be a form? We use https://www.react-hook-form.com/ react hook form, seem slike this could be used here iwth controllers etc. might be tough though with the genericness of it, but would probably give it a try, can be afollow up

.string()
.transform((s) =>
z
// TODO(apowell): specify schema for parameters that we care about
Copy link
Contributor

Choose a reason for hiding this comment

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

ticket here

Copy link
Contributor

Choose a reason for hiding this comment

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

just want to make sure that this won't fail and drop the model name if the invocation params are off, if so it might be worth parsing twice with two different schemas just so that we get as much information as we can. Let me know if this doesn't make sense and we can take a look together

Copy link
Contributor

Choose a reason for hiding this comment

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

can we use your schema below with passthrough?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think so

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay so this turned out to be awesome. We can now read invocation params from the span and convert them into the expected format automatically, including snake cased keys.

Copy link
Contributor

Choose a reason for hiding this comment

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

still want to make sure we can get llm model name and stuff even if invocation params are busted. Can also just not use zod for model name and just traverse to it if that makes it easier

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

/**
* Invocation parameters for O1 models.
*/
const o1BaseInvocationParameterSchema = invocationParameterSchema.pick({
Copy link
Contributor

Choose a reason for hiding this comment

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

doesn't this result in all other invocation parameters being dropped?
https://zod.dev/?id=pickomit

or is that the only valid param for o1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is in fact the only valid param for o1 unfortunately

ANTHROPIC: {
default: baseInvocationParameterSchema,
},
} satisfies Record<
Copy link
Contributor

Choose a reason for hiding this comment

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

nice, forced em to go back and read about satisfies, this is great

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's so good once it clicks. You get inference similar to "as const" against some type without all the readonly garbage

Comment on lines 307 to 320
it("should correctly parse the invocation parameters", () => {
const span = {
...basePlaygroundSpan,
attributes: JSON.stringify({
...spanAttributesWithInputMessages,
llm: {
...spanAttributesWithInputMessages.llm,
// note that camel case keys are automatically converted to snake case
invocation_parameters:
'{"topP": 0.5, "maxTokens": 100, "seed": 12345, "stop": ["stop", "me"]}',
},
}),
};
Copy link
Contributor

Choose a reason for hiding this comment

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

wait which direction it goes snake to camel right? can we get a test showing that with at least one param as well, c just convert one of these params

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated comment and test, cursor got me mixed up 😂

@cephalization cephalization force-pushed the cephalization/invocation-parameters-ui branch from 7287cd7 to 419ff2a Compare October 22, 2024 15:14
@cephalization cephalization merged commit 6efc700 into main Oct 22, 2024
7 checks passed
@cephalization cephalization deleted the cephalization/invocation-parameters-ui branch October 22, 2024 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:L This PR changes 100-499 lines, ignoring generated files.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants