mirror of
https://github.com/slhaf/Partner.git
synced 2026-06-28 01:59:17 +08:00
refactor(vector): add model id assigning support
This commit is contained in:
@@ -12,6 +12,7 @@ public abstract class VectorClient {
|
||||
|
||||
public static boolean status = false;
|
||||
public static VectorClient INSTANCE;
|
||||
public static String VECTOR_MODEL_ID;
|
||||
|
||||
public static void startClient(VectorConfig config) {
|
||||
try {
|
||||
@@ -23,6 +24,7 @@ public abstract class VectorClient {
|
||||
return;
|
||||
}
|
||||
status = true;
|
||||
VECTOR_MODEL_ID = config.modelId;
|
||||
} catch (VectorClientStartupException e) {
|
||||
throw e;
|
||||
} catch (VectorClientExecutionException e) {
|
||||
|
||||
@@ -39,7 +39,7 @@ public class VectorClientRegistry implements Configurable, ConfigRegistration<Ve
|
||||
@Nullable
|
||||
@Override
|
||||
public VectorConfig defaultConfig() {
|
||||
return new VectorConfig(false, null);
|
||||
return new VectorConfig(false, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,10 +5,16 @@ import work.slhaf.partner.framework.agent.config.Config;
|
||||
public sealed class VectorConfig extends Config permits VectorConfig.Ollama, VectorConfig.Onnx {
|
||||
final boolean enabled;
|
||||
final Type type;
|
||||
final String modelId;
|
||||
|
||||
public VectorConfig(boolean enabled, Type type) {
|
||||
public VectorConfig(boolean enabled, Type type, String modelId) {
|
||||
this.enabled = enabled;
|
||||
this.type = type;
|
||||
this.modelId = modelId;
|
||||
}
|
||||
|
||||
protected static String fallbackModelId(String modelId, String fallback) {
|
||||
return modelId == null || modelId.isBlank() ? fallback : modelId;
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
@@ -21,8 +27,8 @@ public sealed class VectorConfig extends Config permits VectorConfig.Ollama, Vec
|
||||
final String tokenizerPath;
|
||||
final String embeddingModelPath;
|
||||
|
||||
public Onnx(boolean enabled, Type type, String tokenizerPath, String embeddingModelPath) {
|
||||
super(enabled, type);
|
||||
public Onnx(boolean enabled, Type type, String tokenizerPath, String embeddingModelPath, String modelId) {
|
||||
super(enabled, type, fallbackModelId(modelId, embeddingModelPath));
|
||||
this.tokenizerPath = tokenizerPath;
|
||||
this.embeddingModelPath = embeddingModelPath;
|
||||
}
|
||||
@@ -33,12 +39,10 @@ public sealed class VectorConfig extends Config permits VectorConfig.Ollama, Vec
|
||||
final String ollamaEmbeddingUrl;
|
||||
final String ollamaEmbeddingModel;
|
||||
|
||||
public Ollama(boolean enabled, Type type, String ollamaEmbeddingUrl, String ollamaEmbeddingModel) {
|
||||
super(enabled, type);
|
||||
public Ollama(boolean enabled, Type type, String ollamaEmbeddingUrl, String ollamaEmbeddingModel, String modelId) {
|
||||
super(enabled, type, fallbackModelId(modelId, ollamaEmbeddingModel));
|
||||
this.ollamaEmbeddingUrl = ollamaEmbeddingUrl;
|
||||
this.ollamaEmbeddingModel = ollamaEmbeddingModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user