Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions src/prerna/engine/api/IModelRouterEngine.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*******************************************************************************
* Copyright 2015 Defense Health Agency (DHA)
*
* If your use of this software does not include any GPLv2 components:
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ----------------------------------------------------------------------------
* If your use of this software includes any GPLv2 components:
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*******************************************************************************/
package prerna.engine.api;

import java.io.IOException;

import prerna.logging.IgnoreEngineLogging;

/**
* A model engine that delegates each ask to one of several backing model
* engines based on a routing configuration it can reload at runtime.
*
* <p>These methods are declared on an interface rather than only on the
* implementation because Utility.getModel returns a dynamic proxy over the
* engine's interfaces (see EngineProxyFactory) - the concrete engine is
* unreachable through it, so a cast to the implementation class fails. Callers
* that need the routing config work against this interface and check
* {@code instanceof IModelRouterEngine} instead of the implementation class.
*
* <p>All methods are marked {@link IgnoreEngineLogging}: they are admin-time
* configuration operations, not model calls, so they should neither produce
* engine audit rows nor be run through the guardrail pipelines.
*/
public interface IModelRouterEngine extends IModelEngine {

/**
* Raw contents of the routing config file, for the settings UI.
*
* @return the config file contents
* @throws IOException if the config file is missing or unreadable
*/
@IgnoreEngineLogging
String readConfigJson() throws IOException;

/**
* Validates the given JSON, persists it to the config file, and applies it to
* the live instance. Nothing is written when validation fails.
*
* @param json the new routing config
* @throws IOException if the config file cannot be written
*/
@IgnoreEngineLogging
void updateConfig(String json) throws IOException;

/**
* Re-reads and applies the config file on the live instance, picking up an
* edit made outside of {@link #updateConfig(String)}.
*
* @throws IOException if the config file is missing or unreadable
*/
@IgnoreEngineLogging
void reloadConfig() throws IOException;

}
4 changes: 4 additions & 0 deletions src/prerna/engine/api/ModelTypeEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import prerna.engine.impl.model.KServeImageEngine;
import prerna.engine.impl.model.KServeTTSEngine;
import prerna.engine.impl.model.KServeVisionEngine;
import prerna.engine.impl.model.ModelRouterEngine;
import prerna.engine.impl.model.NEREngine;
import prerna.engine.impl.model.OpenAiEngine;
import prerna.engine.impl.model.TextEmbeddingsEngine;
Expand Down Expand Up @@ -63,6 +64,9 @@ public enum ModelTypeEnum {
REMOTE("REMOTE", RemoteModelEngine.class.getName()),
TEXT_EMBEDDINGS("TEXT_EMBEDDINGS", TextEmbeddingsEngine.class.getName()),
TEXT_GENERATION("TEXT_GENERATION", TextGenerationEngine.class.getName()),

// routing engine - dispatches to backing engines per its assets/router.json config
MODEL_ROUTER("MODEL_ROUTER", ModelRouterEngine.class.getName()),
;
// @formatter:on

Expand Down
14 changes: 12 additions & 2 deletions src/prerna/engine/impl/model/AbstractModelEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ public AskModelEngineResponse askRoom(String question, Room room, AbstractMessag
Thread inferenceRecorder = new Thread(new ModelEngineInferenceLogsWorker (
/*messageId*/ inputMessage.getMessageId(),
/*transactionId*/askModelResponse.getMessageId(),
/*messageMethod*/"ask",
/*messageMethod*/inferenceLogMessageMethod("ask"),
/*engine*/this,
/*insightId*/room.getInsight().getInsightId(),
/*projectContextId*/room.getInsight().getContextProjectId(),
Expand Down Expand Up @@ -573,6 +573,16 @@ public AskModelEngineResponse askRoom(String question, Room room, AbstractMessag
}
}

/**
* messageMethod recorded on inference log rows written by this engine.
* Delegating engines (e.g. the model router) override this to tag their
* rows, so ask-history queries and usage aggregations can separate the
* delegating row from the actual model call.
*/
protected String inferenceLogMessageMethod(String method) {
return method;
}

@Override
@Deprecated
public AskModelEngineResponse ask(String question, String context, Insight insight,
Expand Down Expand Up @@ -613,7 +623,7 @@ public EmbeddingsModelEngineResponse embeddings(List<String> stringsToEmbed, Ins
Thread inferenceRecorder = new Thread(new ModelEngineInferenceLogsWorker (
/*messageId*/messageId,
/*transactionId*/messageId,
/*messageMethod*/"embeddings",
/*messageMethod*/inferenceLogMessageMethod("embeddings"),
/*engine*/this,
/*insightId*/insight.getInsightId(),
/*projectContextId*/insight.getContextProjectId(),
Expand Down
Loading
Loading