diff --git a/inception/inception-imls-azureai-openai/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/azureaiopenai/AzureAiOpenAiInteractionPanel.java b/inception/inception-imls-azureai-openai/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/azureaiopenai/AzureAiOpenAiInteractionPanel.java index 7eb22ce9bcc..468585bf5ea 100644 --- a/inception/inception-imls-azureai-openai/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/azureaiopenai/AzureAiOpenAiInteractionPanel.java +++ b/inception/inception-imls-azureai-openai/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/azureaiopenai/AzureAiOpenAiInteractionPanel.java @@ -38,7 +38,7 @@ import de.tudarmstadt.ukp.inception.recommendation.api.model.Recommender; import de.tudarmstadt.ukp.inception.recommendation.api.recommender.AbstractTraitsEditor; import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommendationEngineFactory; -import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.prompt.Preset; +import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.preset.Preset; import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.prompt.PromptingModeSelect; import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.response.ExtractionModeSelect; import de.tudarmstadt.ukp.inception.support.lambda.LambdaAjaxFormComponentUpdatingBehavior; diff --git a/inception/inception-imls-azureai-openai/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/azureaiopenai/AzureAiOpenAiRecommenderFactory.java b/inception/inception-imls-azureai-openai/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/azureaiopenai/AzureAiOpenAiRecommenderFactory.java index 2c121846362..a0ca211d2e9 100644 --- a/inception/inception-imls-azureai-openai/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/azureaiopenai/AzureAiOpenAiRecommenderFactory.java +++ b/inception/inception-imls-azureai-openai/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/azureaiopenai/AzureAiOpenAiRecommenderFactory.java @@ -17,20 +17,11 @@ */ package de.tudarmstadt.ukp.inception.recommendation.imls.llm.azureaiopenai; -import static java.util.Collections.emptyList; import static org.apache.uima.cas.CAS.TYPE_NAME_STRING; -import java.lang.invoke.MethodHandles; -import java.util.ArrayList; -import java.util.List; - import org.apache.wicket.markup.html.panel.Panel; import org.apache.wicket.model.IModel; import org.apache.wicket.model.util.ListModel; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.fasterxml.jackson.core.type.TypeReference; import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature; import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer; @@ -39,10 +30,8 @@ import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommendationEngine; import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommendationEngineFactoryImplBase; import de.tudarmstadt.ukp.inception.recommendation.imls.llm.azureaiopenai.client.AzureAiOpenAiClient; -import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.prompt.Preset; +import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.preset.Presets; import de.tudarmstadt.ukp.inception.schema.api.AnnotationSchemaService; -import de.tudarmstadt.ukp.inception.support.io.WatchedResourceFile; -import de.tudarmstadt.ukp.inception.support.yaml.YamlUtil; import de.tudarmstadt.ukp.inception.ui.core.docanno.layer.DocumentMetadataLayerSupport; public class AzureAiOpenAiRecommenderFactory @@ -52,24 +41,14 @@ public class AzureAiOpenAiRecommenderFactory // and without the database starting to refer to non-existing recommendation tools. public static final String ID = "de.tudarmstadt.ukp.inception.recommendation.imls.azureaiopenai.AzureAiOpenAiRecommender"; - private final static Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - private final AzureAiOpenAiClient client; private final AnnotationSchemaService schemaService; - private WatchedResourceFile> presets; - public AzureAiOpenAiRecommenderFactory(AzureAiOpenAiClient aClient, AnnotationSchemaService aSchemaService) { client = aClient; schemaService = aSchemaService; - - var presetsResource = getClass().getResource("presets.yaml"); - presets = new WatchedResourceFile<>(presetsResource, is -> YamlUtil.getObjectMapper() - .readValue(is, new TypeReference>() - { - })); } @Override @@ -103,7 +82,8 @@ public boolean accepts(AnnotationLayer aLayer, AnnotationFeature aFeature) public AzureAiOpenAiRecommenderTraitsEditor createTraitsEditor(String aId, IModel aModel) { - return new AzureAiOpenAiRecommenderTraitsEditor(aId, aModel, new ListModel<>(getPresets())); + return new AzureAiOpenAiRecommenderTraitsEditor(aId, aModel, + new ListModel<>(Presets.getPresets())); } @Override @@ -133,17 +113,7 @@ public boolean isInteractive(Recommender aRecommender) @Override public Panel createInteractionPanel(String aId, IModel aModel) { - return new AzureAiOpenAiInteractionPanel(aId, aModel, new ListModel<>(getPresets())); - } - - private List getPresets() - { - try { - return presets.get().get(); - } - catch (Exception e) { - LOG.error("Unable to load presets", e); - return emptyList(); - } + return new AzureAiOpenAiInteractionPanel(aId, aModel, + new ListModel<>(Presets.getPresets())); } } diff --git a/inception/inception-imls-azureai-openai/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/azureaiopenai/AzureAiOpenAiRecommenderTraitsEditor.java b/inception/inception-imls-azureai-openai/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/azureaiopenai/AzureAiOpenAiRecommenderTraitsEditor.java index d0b572a757c..8fc8fec8510 100644 --- a/inception/inception-imls-azureai-openai/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/azureaiopenai/AzureAiOpenAiRecommenderTraitsEditor.java +++ b/inception/inception-imls-azureai-openai/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/azureaiopenai/AzureAiOpenAiRecommenderTraitsEditor.java @@ -27,7 +27,7 @@ import de.tudarmstadt.ukp.inception.recommendation.api.model.Recommender; import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommendationEngineFactory; import de.tudarmstadt.ukp.inception.recommendation.imls.llm.azureaiopenai.client.ChatCompletionRequest; -import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.prompt.Preset; +import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.preset.Preset; import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.traits.LlmRecommenderTraits; import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.traits.LlmRecommenderTraitsEditor_ImplBase; import de.tudarmstadt.ukp.inception.security.client.auth.AuthenticationTraitsEditor; diff --git a/inception/inception-imls-azureai-openai/src/main/resources/de/tudarmstadt/ukp/inception/recommendation/imls/azureaiopenai/presets.yaml b/inception/inception-imls-azureai-openai/src/main/resources/de/tudarmstadt/ukp/inception/recommendation/imls/azureaiopenai/presets.yaml deleted file mode 100644 index 6bfad8554a9..00000000000 --- a/inception/inception-imls-azureai-openai/src/main/resources/de/tudarmstadt/ukp/inception/recommendation/imls/azureaiopenai/presets.yaml +++ /dev/null @@ -1,80 +0,0 @@ -- name: Extract named entities from sentenes - promptingMode: per-sentence - format: json - extractionMode: mentions-from-json - prompt: |- - Identify all named entities in the following text and return them as JSON. - - {{ text }} - -- name: Extract named entities from sentenes (dynamic few-shot) - promptingMode: per-sentence - format: json - extractionMode: mentions-from-json - prompt: |- - Identify all named entities in the following text and return them as JSON. - - {% if examples %} - {% for example in examples %} - Text: - ''' - {{ example.getText() }} - ''' - - Response: - {{ example.getLabelledMentions() | tojson }} - {% endfor %} - - Text: - {% endif %} - - ''' - {{ text }} - ''' - - {% if examples %} - Response: - {% endif %} - - -- name: Summarize each sentence in a word - promptingMode: per-sentence - extractionMode: response-as-label - prompt: |- - Summarize the following sentence in a single word. - - ``` - {{ text }} - ``` - -- name: Summarize document - promptingMode: per-document - extractionMode: response-as-label - prompt: |- - Briefly describe what the following text is about. - - ``` - {{ text }} - ``` - -- name: Summarize annotated spans - promptingMode: per-document - extractionMode: response-as-label - prompt: |- - Briefly summarize the following text. - - ``` - {% for x in cas.select('custom.Span') %} - {{ x }} - {% endfor %} - ``` - -- name: Disambiguate in sentence - promptingMode: per-annotation - extractionMode: response-as-label - prompt: |- - Very briefly describe the meaning of `{{ text }}` in the following sentence. - - ``` - {{ sentence }} - ``` diff --git a/inception/inception-imls-chatgpt/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/chatgpt/ChatGptInteractionPanel.java b/inception/inception-imls-chatgpt/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/chatgpt/ChatGptInteractionPanel.java index 38e6a39e3ae..835849ac73f 100644 --- a/inception/inception-imls-chatgpt/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/chatgpt/ChatGptInteractionPanel.java +++ b/inception/inception-imls-chatgpt/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/chatgpt/ChatGptInteractionPanel.java @@ -37,7 +37,7 @@ import de.tudarmstadt.ukp.inception.recommendation.api.model.Recommender; import de.tudarmstadt.ukp.inception.recommendation.api.recommender.AbstractTraitsEditor; import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommendationEngineFactory; -import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.prompt.Preset; +import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.preset.Preset; import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.prompt.PromptingModeSelect; import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.response.ExtractionModeSelect; import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.response.ResponseFormat; diff --git a/inception/inception-imls-chatgpt/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/chatgpt/ChatGptRecommenderFactory.java b/inception/inception-imls-chatgpt/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/chatgpt/ChatGptRecommenderFactory.java index 98c0b6f3149..9c463440e3c 100644 --- a/inception/inception-imls-chatgpt/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/chatgpt/ChatGptRecommenderFactory.java +++ b/inception/inception-imls-chatgpt/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/chatgpt/ChatGptRecommenderFactory.java @@ -19,18 +19,9 @@ import static org.apache.uima.cas.CAS.TYPE_NAME_STRING; -import java.lang.invoke.MethodHandles; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - import org.apache.wicket.markup.html.panel.Panel; import org.apache.wicket.model.IModel; import org.apache.wicket.model.util.ListModel; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.fasterxml.jackson.core.type.TypeReference; import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature; import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer; @@ -40,10 +31,8 @@ import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommendationEngineFactoryImplBase; import de.tudarmstadt.ukp.inception.recommendation.imls.llm.chatgpt.client.ChatCompletionRequest; import de.tudarmstadt.ukp.inception.recommendation.imls.llm.chatgpt.client.ChatGptClient; -import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.prompt.Preset; +import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.preset.Presets; import de.tudarmstadt.ukp.inception.schema.api.AnnotationSchemaService; -import de.tudarmstadt.ukp.inception.support.io.WatchedResourceFile; -import de.tudarmstadt.ukp.inception.support.yaml.YamlUtil; import de.tudarmstadt.ukp.inception.ui.core.docanno.layer.DocumentMetadataLayerSupport; public class ChatGptRecommenderFactory @@ -53,23 +42,13 @@ public class ChatGptRecommenderFactory // and without the database starting to refer to non-existing recommendation tools. public static final String ID = "de.tudarmstadt.ukp.inception.recommendation.imls.chatgpt.ChatGptRecommender"; - private final static Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - private final ChatGptClient client; private final AnnotationSchemaService schemaService; - private WatchedResourceFile> presets; - public ChatGptRecommenderFactory(ChatGptClient aClient, AnnotationSchemaService aSchemaService) { client = aClient; schemaService = aSchemaService; - - var presetsResource = getClass().getResource("presets.yaml"); - presets = new WatchedResourceFile<>(presetsResource, is -> YamlUtil.getObjectMapper() - .readValue(is, new TypeReference>() - { - })); } @Override @@ -102,7 +81,8 @@ public boolean accepts(AnnotationLayer aLayer, AnnotationFeature aFeature) @Override public ChatGptRecommenderTraitsEditor createTraitsEditor(String aId, IModel aModel) { - return new ChatGptRecommenderTraitsEditor(aId, aModel, new ListModel<>(getPresets()), + return new ChatGptRecommenderTraitsEditor(aId, aModel, + new ListModel<>(Presets.getPresets()), new ListModel<>(ChatCompletionRequest.getAllOptions())); } @@ -133,17 +113,6 @@ public boolean isInteractive(Recommender aRecommender) @Override public Panel createInteractionPanel(String aId, IModel aModel) { - return new ChatGptInteractionPanel(aId, aModel, new ListModel<>(getPresets())); - } - - private List getPresets() - { - try { - return presets.get().get(); - } - catch (Exception e) { - LOG.error("Unable to load presets", e); - return Collections.emptyList(); - } + return new ChatGptInteractionPanel(aId, aModel, new ListModel<>(Presets.getPresets())); } } diff --git a/inception/inception-imls-chatgpt/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/chatgpt/ChatGptRecommenderTraitsEditor.java b/inception/inception-imls-chatgpt/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/chatgpt/ChatGptRecommenderTraitsEditor.java index 02b3cd8c95e..3ebb0c096f9 100644 --- a/inception/inception-imls-chatgpt/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/chatgpt/ChatGptRecommenderTraitsEditor.java +++ b/inception/inception-imls-chatgpt/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/chatgpt/ChatGptRecommenderTraitsEditor.java @@ -38,7 +38,7 @@ import de.tudarmstadt.ukp.inception.recommendation.imls.llm.chatgpt.client.ChatGptClientImpl; import de.tudarmstadt.ukp.inception.recommendation.imls.llm.chatgpt.client.ChatGptModel; import de.tudarmstadt.ukp.inception.recommendation.imls.llm.chatgpt.client.ListModelsRequest; -import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.prompt.Preset; +import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.preset.Preset; import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.traits.LlmRecommenderTraits; import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.traits.LlmRecommenderTraitsEditor_ImplBase; import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.traits.Option; diff --git a/inception/inception-imls-llm-support/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/support/prompt/Preset.java b/inception/inception-imls-llm-support/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/support/preset/Preset.java similarity index 96% rename from inception/inception-imls-llm-support/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/support/prompt/Preset.java rename to inception/inception-imls-llm-support/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/support/preset/Preset.java index 8a71b2d7da8..1b7eb71183c 100644 --- a/inception/inception-imls-llm-support/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/support/prompt/Preset.java +++ b/inception/inception-imls-llm-support/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/support/preset/Preset.java @@ -15,12 +15,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.prompt; +package de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.preset; import java.io.Serializable; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.prompt.PromptingMode; import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.response.ExtractionMode; import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.response.ResponseFormat; diff --git a/inception/inception-imls-llm-support/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/support/preset/Presets.java b/inception/inception-imls-llm-support/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/support/preset/Presets.java new file mode 100644 index 00000000000..af0853ae242 --- /dev/null +++ b/inception/inception-imls-llm-support/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/support/preset/Presets.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Technische Universität Darmstadt under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The Technische Universität Darmstadt + * licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. + * + * 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. + */ +package de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.preset; + +import static java.util.Collections.emptyList; + +import java.lang.invoke.MethodHandles; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.fasterxml.jackson.core.type.TypeReference; + +import de.tudarmstadt.ukp.inception.support.io.WatchedResourceFile; +import de.tudarmstadt.ukp.inception.support.yaml.YamlUtil; + +public final class Presets +{ + private final static Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + + private static final WatchedResourceFile> PRESETS; + + static { + var presetsResource = MethodHandles.lookup().lookupClass().getResource("presets.yaml"); + PRESETS = new WatchedResourceFile<>(presetsResource, is -> YamlUtil.getObjectMapper() + .readValue(is, new TypeReference>() + { + })); + } + + private Presets() + { + // No instances; + } + + public static List getPresets() + { + try { + if (PRESETS.get().isPresent()) { + return PRESETS.get().get(); + } + + return emptyList(); + } + catch (Exception e) { + LOG.error("Unable to load presets", e); + return Collections.emptyList(); + } + } +} diff --git a/inception/inception-imls-llm-support/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/support/traits/LlmRecommenderTraitsEditor_ImplBase.java b/inception/inception-imls-llm-support/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/support/traits/LlmRecommenderTraitsEditor_ImplBase.java index a5fef7c0629..d64c377ac01 100644 --- a/inception/inception-imls-llm-support/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/support/traits/LlmRecommenderTraitsEditor_ImplBase.java +++ b/inception/inception-imls-llm-support/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/support/traits/LlmRecommenderTraitsEditor_ImplBase.java @@ -57,7 +57,7 @@ import de.tudarmstadt.ukp.inception.recommendation.api.model.Recommender; import de.tudarmstadt.ukp.inception.recommendation.api.recommender.AbstractTraitsEditor; import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommendationEngineFactory; -import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.prompt.Preset; +import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.preset.Preset; import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.prompt.PromptingModeSelect; import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.response.ExtractionModeSelect; import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.response.ResponseFormatSelect; diff --git a/inception/inception-imls-chatgpt/src/main/resources/de/tudarmstadt/ukp/inception/recommendation/imls/chatgpt/presets.yaml b/inception/inception-imls-llm-support/src/main/resources/de/tudarmstadt/ukp/inception/recommendation/imls/llm/support/preset/presets.yaml similarity index 100% rename from inception/inception-imls-chatgpt/src/main/resources/de/tudarmstadt/ukp/inception/recommendation/imls/chatgpt/presets.yaml rename to inception/inception-imls-llm-support/src/main/resources/de/tudarmstadt/ukp/inception/recommendation/imls/llm/support/preset/presets.yaml diff --git a/inception/inception-imls-ollama/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/ollama/OllamaInteractionPanel.java b/inception/inception-imls-ollama/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/ollama/OllamaInteractionPanel.java index 50f8c427b49..727e8f1b404 100644 --- a/inception/inception-imls-ollama/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/ollama/OllamaInteractionPanel.java +++ b/inception/inception-imls-ollama/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/ollama/OllamaInteractionPanel.java @@ -38,7 +38,7 @@ import de.tudarmstadt.ukp.inception.recommendation.api.model.Recommender; import de.tudarmstadt.ukp.inception.recommendation.api.recommender.AbstractTraitsEditor; import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommendationEngineFactory; -import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.prompt.Preset; +import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.preset.Preset; import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.prompt.PromptingModeSelect; import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.response.ExtractionModeSelect; import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.response.ResponseFormatSelect; diff --git a/inception/inception-imls-ollama/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/ollama/OllamaRecommenderFactory.java b/inception/inception-imls-ollama/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/ollama/OllamaRecommenderFactory.java index 70884e8e596..705eec18455 100644 --- a/inception/inception-imls-ollama/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/ollama/OllamaRecommenderFactory.java +++ b/inception/inception-imls-ollama/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/ollama/OllamaRecommenderFactory.java @@ -19,18 +19,9 @@ import static org.apache.uima.cas.CAS.TYPE_NAME_STRING; -import java.lang.invoke.MethodHandles; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - import org.apache.wicket.markup.html.panel.Panel; import org.apache.wicket.model.IModel; import org.apache.wicket.model.util.ListModel; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.fasterxml.jackson.core.type.TypeReference; import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature; import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer; @@ -39,10 +30,8 @@ import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommendationEngine; import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommendationEngineFactoryImplBase; import de.tudarmstadt.ukp.inception.recommendation.imls.llm.ollama.client.OllamaClient; -import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.prompt.Preset; +import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.preset.Presets; import de.tudarmstadt.ukp.inception.schema.api.AnnotationSchemaService; -import de.tudarmstadt.ukp.inception.support.io.WatchedResourceFile; -import de.tudarmstadt.ukp.inception.support.yaml.YamlUtil; import de.tudarmstadt.ukp.inception.ui.core.docanno.layer.DocumentMetadataLayerSupport; public class OllamaRecommenderFactory @@ -52,23 +41,13 @@ public class OllamaRecommenderFactory // and without the database starting to refer to non-existing recommendation tools. public static final String ID = "de.tudarmstadt.ukp.inception.recommendation.imls.ollama.OllamaRecommenderFactory"; - private final static Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - private final AnnotationSchemaService schemaService; private final OllamaClient client; - private WatchedResourceFile> presets; - public OllamaRecommenderFactory(OllamaClient aClient, AnnotationSchemaService aSchemaService) { client = aClient; schemaService = aSchemaService; - - var presetsResource = getClass().getResource("presets.yaml"); - presets = new WatchedResourceFile<>(presetsResource, is -> YamlUtil.getObjectMapper() - .readValue(is, new TypeReference>() - { - })); } @Override @@ -101,7 +80,8 @@ public boolean accepts(AnnotationLayer aLayer, AnnotationFeature aFeature) @Override public OllamaRecommenderTraitsEditor createTraitsEditor(String aId, IModel aModel) { - return new OllamaRecommenderTraitsEditor(aId, aModel, new ListModel<>(getPresets())); + return new OllamaRecommenderTraitsEditor(aId, aModel, + new ListModel<>(Presets.getPresets())); } @Override @@ -131,17 +111,6 @@ public boolean isInteractive(Recommender aRecommender) @Override public Panel createInteractionPanel(String aId, IModel aModel) { - return new OllamaInteractionPanel(aId, aModel, new ListModel<>(getPresets())); - } - - private List getPresets() - { - try { - return presets.get().get(); - } - catch (Exception e) { - LOG.error("Unable to load presets", e); - return Collections.emptyList(); - } + return new OllamaInteractionPanel(aId, aModel, new ListModel<>(Presets.getPresets())); } } diff --git a/inception/inception-imls-ollama/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/ollama/OllamaRecommenderTraitsEditor.java b/inception/inception-imls-ollama/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/ollama/OllamaRecommenderTraitsEditor.java index 99586157958..f071cadbd20 100644 --- a/inception/inception-imls-ollama/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/ollama/OllamaRecommenderTraitsEditor.java +++ b/inception/inception-imls-ollama/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/llm/ollama/OllamaRecommenderTraitsEditor.java @@ -34,7 +34,7 @@ import de.tudarmstadt.ukp.inception.recommendation.imls.llm.ollama.client.OllamaClientImpl; import de.tudarmstadt.ukp.inception.recommendation.imls.llm.ollama.client.OllamaGenerateRequest; import de.tudarmstadt.ukp.inception.recommendation.imls.llm.ollama.client.OllamaModel; -import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.prompt.Preset; +import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.preset.Preset; import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.traits.LlmRecommenderTraits; import de.tudarmstadt.ukp.inception.recommendation.imls.llm.support.traits.LlmRecommenderTraitsEditor_ImplBase; diff --git a/inception/inception-imls-ollama/src/main/resources/de/tudarmstadt/ukp/inception/recommendation/imls/ollama/presets.yaml b/inception/inception-imls-ollama/src/main/resources/de/tudarmstadt/ukp/inception/recommendation/imls/ollama/presets.yaml deleted file mode 100644 index 7e8c13bbe74..00000000000 --- a/inception/inception-imls-ollama/src/main/resources/de/tudarmstadt/ukp/inception/recommendation/imls/ollama/presets.yaml +++ /dev/null @@ -1,80 +0,0 @@ -- name: Extract named entities from sentenes (mistral) - promptingMode: per-sentence - format: json - extractionMode: mentions-from-json - raw: true - prompt: |- - [INST]Identify all named entities in the following text and return them as JSON.[/INST] - - {{ text }} - -- name: Extract named entities from sentenes (dynamic few-shot) - promptingMode: per-sentence - format: json - extractionMode: mentions-from-json - prompt: |- - Identify all named entities in the following text and return them as JSON. - - {% if examples %} - {% for example in examples %} - Text: - ''' - {{ example.getText() }} - ''' - - Response: - {{ example.getLabelledMentions() | tojson }} - {% endfor %} - - Text: - {% endif %} - - ''' - {{ text }} - ''' - - {% if examples %} - Response: - {% endif %} - -- name: Summarize each sentence in a word - promptingMode: per-sentence - extractionMode: response-as-label - prompt: |- - Summarize the following sentence in a single word. - - ``` - {{ text }} - ``` - -- name: Summarize document - promptingMode: per-document - extractionMode: response-as-label - prompt: |- - Briefly describe what the following text is about. - - ``` - {{ text }} - ``` - -- name: Summarize annotated spans - promptingMode: per-document - extractionMode: response-as-label - prompt: |- - Briefly summarize the following text. - - ``` - {% for x in cas.select('custom.Span') %} - {{ x }} - {% endfor %} - ``` - -- name: Disambiguate in sentence - promptingMode: per-annotation - extractionMode: response-as-label - prompt: |- - Very briefly describe the meaning of `{{ text }}` in the following sentence. - - ``` - {{ sentence }} - ``` diff --git a/inception/inception-support/src/main/java/de/tudarmstadt/ukp/inception/support/io/WatchedResourceFile.java b/inception/inception-support/src/main/java/de/tudarmstadt/ukp/inception/support/io/WatchedResourceFile.java index f197edb5ede..4c99ae53365 100644 --- a/inception/inception-support/src/main/java/de/tudarmstadt/ukp/inception/support/io/WatchedResourceFile.java +++ b/inception/inception-support/src/main/java/de/tudarmstadt/ukp/inception/support/io/WatchedResourceFile.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.io.InputStream; +import java.lang.invoke.MethodHandles; import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; @@ -36,7 +37,7 @@ public class WatchedResourceFile { - private final Logger log = LoggerFactory.getLogger(getClass()); + private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private final FailableFunction loader; private final URL resourceLocation; @@ -67,7 +68,7 @@ public WatchedResourceFile(Path aResourcePath, public Optional get() throws IOException { if (resourceLocation == null) { - log.trace("No resource has been set."); + LOG.trace("No resource has been set."); return Optional.empty(); } @@ -84,12 +85,12 @@ public Optional get() throws IOException Instant mtime = getLastModifiedTime(resourcePath).toInstant(); if (resourceMTime == null || mtime.isAfter(resourceMTime)) { if (resourceMTime == null) { - log.trace( + LOG.trace( "Updatable resource [{}] has not been loaded yet - loading resource...", resourceLocation); } else { - log.trace( + LOG.trace( "Updatable resource [{}] has changed at [{}] - reloading resource...", resourceLocation, mtime); } @@ -101,7 +102,7 @@ public Optional get() throws IOException } } else { - log.trace( + LOG.trace( "Updatable resource [{}] has not changed since [{}] [{}] - using already loaded resource", resourceLocation, resourceMTime, mtime); } @@ -110,11 +111,11 @@ public Optional get() throws IOException } if (resourceMTime != null) { - log.trace("Updatable resource [{}] last changed at [{}] has disappeared", + LOG.trace("Updatable resource [{}] last changed at [{}] has disappeared", resourceLocation, resourceMTime); } else { - log.trace("Updatable resource [{}] does not exist", resourceLocation); + LOG.trace("Updatable resource [{}] does not exist", resourceLocation); } resourceMTime = null; @@ -124,7 +125,7 @@ public Optional get() throws IOException if (resourceMTime == null) { resourceMTime = Instant.now(); - log.trace("Static resource [{}] has not been loaded yet - loading resource...", + LOG.trace("Static resource [{}] has not been loaded yet - loading resource...", resourceLocation); try (var is = resourceLocation.openStream()) { resource = loader.apply(is);