-
Notifications
You must be signed in to change notification settings - Fork 665
fix(js): do not append prompt when resuming generation (#4652) #4657
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
base: main
Are you sure you want to change the base?
Changes from all commits
6155d43
0d51d10
5744b1e
799bc7c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -190,6 +190,13 @@ export async function toGenerateRequest( | |||||
| registry: Registry, | ||||||
| options: GenerateOptions | ||||||
| ): Promise<GenerateRequest> { | ||||||
| if (options.prompt && options.resume) { | ||||||
| throw new GenkitError({ | ||||||
| status: 'INVALID_ARGUMENT', | ||||||
| message: | ||||||
| 'prompt is not supported when resume is set. The message history in messages is used instead.', | ||||||
| }); | ||||||
| } | ||||||
| const messages: MessageData[] = []; | ||||||
| if (options.system) { | ||||||
| messages.push({ | ||||||
|
|
@@ -200,7 +207,7 @@ export async function toGenerateRequest( | |||||
| if (options.messages) { | ||||||
| messages.push(...options.messages.map((m) => Message.parseData(m))); | ||||||
| } | ||||||
| if (options.prompt) { | ||||||
| if (options.prompt && !options.resume) { | ||||||
| messages.push({ | ||||||
| role: 'user', | ||||||
| content: Message.parseContent(options.prompt), | ||||||
|
|
@@ -333,6 +340,13 @@ async function resourcesToActionRefs( | |||||
| } | ||||||
|
|
||||||
| function messagesFromOptions(options: GenerateOptions): MessageData[] { | ||||||
| if (options.prompt && options.resume) { | ||||||
| throw new GenkitError({ | ||||||
| status: 'INVALID_ARGUMENT', | ||||||
| message: | ||||||
| 'prompt is not supported when resume is set. The message history in messages is used instead.', | ||||||
| }); | ||||||
| } | ||||||
| const messages: MessageData[] = []; | ||||||
| if (options.system) { | ||||||
| messages.push({ | ||||||
|
|
@@ -343,7 +357,7 @@ function messagesFromOptions(options: GenerateOptions): MessageData[] { | |||||
| if (options.messages) { | ||||||
| messages.push(...options.messages); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's an inconsistency in how messages are processed here compared to
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this seems preexisting? not something introduced here. |
||||||
| } | ||||||
| if (options.prompt) { | ||||||
| if (options.prompt && !options.resume) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. only thing i'm thinking is if a user explicitly does e.g ai.generate({
prompt: 'count to 10',
messages: [...],
resume: { respond: [...] },
})then the prompt is silently ignored, which might be confusing - might be better to be defensive here and do: if (options.prompt && options.resume) {
throw new GenkitError({
status: 'INVALID_ARGUMENT',
message: 'prompt is not supported when resume is set. The message history in messages is used instead.',
});
} |
||||||
| messages.push({ | ||||||
| role: 'user', | ||||||
| content: Message.parseContent(options.prompt), | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(same as other comment in this file i think)