Skip to content

Commit

Permalink
feat: Available Ollama models support for
Browse files Browse the repository at this point in the history
quarkus.langchain4j.ollama.chat-model.model-id property value

Signed-off-by: azerr <azerr@redhat.com>
  • Loading branch information
angelozerr committed Aug 20, 2024
1 parent 9f4c520 commit c0d6c69
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*******************************************************************************
* Copyright (c) 2024 Red Hat Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
package com.redhat.quarkus.extensions.ollama;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.lsp4mp.commons.metadata.ItemHint;
import org.eclipse.lsp4mp.commons.metadata.ItemMetadata;
import org.eclipse.lsp4mp.commons.metadata.ValueHint;
import org.eclipse.lsp4mp.extensions.ExtendedMicroProfileProjectInfo;
import org.eclipse.lsp4mp.extensions.ItemMetadataProvider;
import org.eclipse.lsp4mp.model.PropertiesModel;

/**
* Properties provider for available Ollama models.
*/
public class OllamaItemMetadataProvider implements ItemMetadataProvider {

private static final String QUARKUS_LANGCHAIN4J_OLLAMA_CHAT_MODEL_MODEL_ID_KEY = "quarkus.langchain4j.ollama.chat-model.model-id";
private ExtendedMicroProfileProjectInfo projectInfo;
private boolean available;

public OllamaItemMetadataProvider(ExtendedMicroProfileProjectInfo projectInfo) {
this.projectInfo = projectInfo;
this.available = this.projectInfo.getProperties().stream()
.anyMatch(p -> QUARKUS_LANGCHAIN4J_OLLAMA_CHAT_MODEL_MODEL_ID_KEY.equals(p.getName()));
if (available) {
ItemHint hint = new ItemHint();
hint.setName(QUARKUS_LANGCHAIN4J_OLLAMA_CHAT_MODEL_MODEL_ID_KEY);
hint.setDescription("Ollama models");
hint.setValues(collectOllamaModels());
this.projectInfo.getHints().add(hint);
}
}

private List<ValueHint> collectOllamaModels() {
List<ValueHint> models = new ArrayList<>();
ValueHint model1 = new ValueHint();
model1.setValue("Model 1");
models.add(model1);

ValueHint model2 = new ValueHint();
model2.setValue("Model 2");
models.add(model2);

return models;
}

@Override
public boolean isAvailable() {
return available;
}

@Override
public void update(PropertiesModel document) {

}

@Override
public List<ItemMetadata> getProperties() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*******************************************************************************
* Copyright (c) 2024 Red Hat Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
package com.redhat.quarkus.extensions.ollama;

import org.eclipse.lsp4mp.extensions.ExtendedMicroProfileProjectInfo;
import org.eclipse.lsp4mp.extensions.ItemMetadataProvider;
import org.eclipse.lsp4mp.extensions.ItemMetadataProviderFactory;

/**
* Factory for creating {@link ItemMetadataProvider} instance for available
* Ollama models.
*
* @author Angelo ZERR
*
*/
public class OllamaItemMetadataProviderFactory implements ItemMetadataProviderFactory {

@Override
public ItemMetadataProvider create(ExtendedMicroProfileProjectInfo projectInfo) {
return new OllamaItemMetadataProvider(projectInfo);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.redhat.quarkus.extensions.ollama.OllamaItemMetadataProviderFactory

0 comments on commit c0d6c69

Please sign in to comment.