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

Added defaultModel to config that allows setting a global default model and config #98

Merged
merged 5 commits into from
May 10, 2024

Conversation

pavelgj
Copy link
Collaborator

@pavelgj pavelgj commented May 9, 2024

configureGenkit({
  plugins: [vertexAI()],
  defaultModel: {
    name: geminiPro,
    config: {
      temperature: 0.6,
      stopSequences: ['sorry'],
    },
  },
});

can then call generate (including dotprompt) without having to specify a model.

@pavelgj pavelgj requested a review from mbleigh May 9, 2024 20:29
Comment on lines 489 to 496
export function setGlobalDefaultModel<
CustomOptions extends z.ZodTypeAny = z.ZodTypeAny,
>(model: ModelArgument<CustomOptions>, config?: z.infer<CustomOptions>) {
global[DEFAULT_MODEL_GLOBAL_KEY] = {
model,
config,
} as GlobalModelRef;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm curious - why not make this part of configureGenkit? Is it because models aren't a concept in core?

I ask because it could be kinda cool if genkit init set default models (e.g. Gemini Pro for Vertex/Google AI)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah. I can't strongly type it in the config (circular dep with AI package). We can still make genkit init set it this way.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Can take a string model ref in the config....

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think I'd probably prefer string model ref in config. Honestly I think we should consider merging ai and core packages in the future.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure. Do you want config as well?

Copy link
Collaborator

Choose a reason for hiding this comment

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

How about:

interface {
  defaultModel?: {
    name: string | {name: string};
    config: Record<string,any>;
  }
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sg

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@pavelgj pavelgj changed the title Added setGlobalDefaultModel that allows setting a global default model and config Added defaultModel to config that allows setting a global default model and config May 10, 2024
Comment on lines 486 to 496
if (genkitConfig?.options.defaultModel) {
model =
typeof genkitConfig?.options.defaultModel.name === 'string'
? genkitConfig?.options.defaultModel.name
: genkitConfig?.options.defaultModel.name.name;
if (
(!options.config || Object.keys(options.config).length === 0) &&
globalModel.config
genkitConfig?.options.defaultModel.config
) {
// use configured global config
options.config = globalModel.config;
options.config = genkitConfig?.options.defaultModel.config;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just double-checking - this gets overridden if specified by the user, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, the condition above that this is only applied if options.config is not provided (or is {}).

@pavelgj pavelgj requested a review from mbleigh May 10, 2024 01:10
@pavelgj pavelgj enabled auto-merge (squash) May 10, 2024 01:11
@pavelgj pavelgj merged commit 8d871f0 into main May 10, 2024
4 checks passed
@pavelgj pavelgj deleted the pavelgj/setGlobalDefaultModel branch May 10, 2024 01:13
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