Skip to content

Commit

Permalink
#5140 - Support access to tag sets in prompt template
Browse files Browse the repository at this point in the history
- Consolidate presets
  • Loading branch information
reckart committed Nov 10, 2024
1 parent d977e76 commit f284800
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 281 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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<ArrayList<Preset>> 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<ArrayList<Preset>>()
{
}));
}

@Override
Expand Down Expand Up @@ -103,7 +82,8 @@ public boolean accepts(AnnotationLayer aLayer, AnnotationFeature aFeature)
public AzureAiOpenAiRecommenderTraitsEditor createTraitsEditor(String aId,
IModel<Recommender> aModel)
{
return new AzureAiOpenAiRecommenderTraitsEditor(aId, aModel, new ListModel<>(getPresets()));
return new AzureAiOpenAiRecommenderTraitsEditor(aId, aModel,
new ListModel<>(Presets.getPresets()));
}

@Override
Expand Down Expand Up @@ -133,17 +113,7 @@ public boolean isInteractive(Recommender aRecommender)
@Override
public Panel createInteractionPanel(String aId, IModel<Recommender> aModel)
{
return new AzureAiOpenAiInteractionPanel(aId, aModel, new ListModel<>(getPresets()));
}

private List<Preset> 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()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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<ArrayList<Preset>> 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<ArrayList<Preset>>()
{
}));
}

@Override
Expand Down Expand Up @@ -102,7 +81,8 @@ public boolean accepts(AnnotationLayer aLayer, AnnotationFeature aFeature)
@Override
public ChatGptRecommenderTraitsEditor createTraitsEditor(String aId, IModel<Recommender> aModel)
{
return new ChatGptRecommenderTraitsEditor(aId, aModel, new ListModel<>(getPresets()),
return new ChatGptRecommenderTraitsEditor(aId, aModel,
new ListModel<>(Presets.getPresets()),
new ListModel<>(ChatCompletionRequest.getAllOptions()));
}

Expand Down Expand Up @@ -133,17 +113,6 @@ public boolean isInteractive(Recommender aRecommender)
@Override
public Panel createInteractionPanel(String aId, IModel<Recommender> aModel)
{
return new ChatGptInteractionPanel(aId, aModel, new ListModel<>(getPresets()));
}

private List<Preset> 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()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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<ArrayList<Preset>> PRESETS;

static {
var presetsResource = MethodHandles.lookup().lookupClass().getResource("presets.yaml");
PRESETS = new WatchedResourceFile<>(presetsResource, is -> YamlUtil.getObjectMapper()
.readValue(is, new TypeReference<ArrayList<Preset>>()
{
}));
}

private Presets()
{
// No instances;
}

public static List<Preset> 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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit f284800

Please sign in to comment.