Skip to content

Conversation

HassanBahati
Copy link
Member

@HassanBahati HassanBahati commented Sep 11, 2025

Fixes #3456

Plugin migration guide

Changes of note:

  • We're no longer getting serverAddress from config, because it doesn't exist on that interface any more in v2 API.

Checklist (if applicable):

  • PR title is following https://www.conventionalcommits.org/en/v1.0.0/

  • Tested (integration, unit)

  • Docs updated (updated docs or a docs bug required)

  • Updated and added integration tests with the core genkit framework, for streaming responses and tool calls.

  • All existing plugin tests pass

In the process of manually testing the plugin.

@github-actions github-actions bot added the config label Oct 7, 2025
}
return actions;
},
async resolve(actionType, actionName) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should factor these out into helpers (like in original)

params?.requestHeaders
);
}
return undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

We probably should handle the case where someone tries to resolve an embedder?

const serverAddress = config?.serverAddress || options.serverAddress;
async (request, config) => {
const serverAddress =
options.serverAddress || DEFAULT_OLLAMA_SERVER_ADDRESS;
Copy link
Contributor

Choose a reason for hiding this comment

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

need to double check this, make sure we're not breaking anything by removing config.serverAddress

"build": "npm-run-all build:clean check compile",
"build:watch": "tsup-node --watch",
"test": "find tests -name '*_test.ts' ! -name '*_live_test.ts' -exec node --import tsx --test {} +",
"test": "find tests -name 'model_test.ts' ! -name '*_live_test.ts' -exec node --import tsx --test {} +",
Copy link
Member

Choose a reason for hiding this comment

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

Checking if we meant to switch off the glob testing for this package?

}
return actions;
},
async resolve(actionType, actionName) {
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason this is called actionName and not name?

Comment on lines +75 to +78
function ollamaPlugin(params?: OllamaPluginParams): GenkitPluginV2 {
if (!params) {
params = {};
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
function ollamaPlugin(params?: OllamaPluginParams): GenkitPluginV2 {
if (!params) {
params = {};
}
function ollamaPlugin(params?: OllamaPluginParams = {}): GenkitPluginV2 {

Comment on lines +79 to +82
if (!params.serverAddress) {
params.serverAddress = DEFAULT_OLLAMA_SERVER_ADDRESS;
}
const serverAddress = params.serverAddress;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (!params.serverAddress) {
params.serverAddress = DEFAULT_OLLAMA_SERVER_ADDRESS;
}
const serverAddress = params.serverAddress;
const serverAddress = params.serverAddress || DEFAULT_OLLAMA_SERVER_ADDRESS;

const actions: ResolvableAction[] = [];

const DEFAULT_OLLAMA_SERVER_ADDRESS = 'http://localhost:11434';
if (params?.models) {
Copy link
Member

Choose a reason for hiding this comment

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

Could this be extracted into a helper function?

function getModelActions(params: OllamaPluginParams, serverAddress: string): ResolvableAction[] {
  /** Extract variables **/
  const { models, requestHeaders } = params;

  /** If no models, return empty array; **/
  if (!models || !models.length) return [];
  
 /** Return Ollama models **/
  return models.map(m => createOllamaModel(m, serverAddress, requestHeaders));
}
init() {
  return [
    ...getModelActions(params, serverAddress),
    ...getEmbedderActions(params, serverAddress)
  ];
}

Comment on lines +114 to +124
if (actionType === 'model') {
return await createOllamaModel(
{
name: actionName,
},
serverAddress,
params?.requestHeaders
);
}
return undefined;
},
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason why we removed the resolveAction function? The original resolveActionWe can return early if undefined. Also should we return undefined here.

Suggested change
if (actionType === 'model') {
return await createOllamaModel(
{
name: actionName,
},
serverAddress,
params?.requestHeaders
);
}
return undefined;
},
async resolve(actionType, actionName) {
/** If no model actions, return undefined **/
if (actionType !== 'model') return undefined;
return await createOllamaModel(
{
name: actionName,
},
serverAddress,
params?.requestHeaders
);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

refactor: migrate ollama plugin to V2 Plugin API
4 participants