initial interfaces

This commit is contained in:
Mark Pollack
2023-08-04 03:08:08 -04:00
parent 0ee86b5b5d
commit 554f584d08
23 changed files with 94 additions and 39 deletions

View File

@@ -0,0 +1,41 @@
package org.springframework.ai.core.llm;/*
* Copyright 2023 the original author or authors.
*
* 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
*
* https://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.
*/
import java.util.List;
import java.util.Map;
import org.springframework.ai.core.prompt.Generation;
public interface LLMResult {
/**
* The list of generated outputs. It iss a list of lists because a single input could
* have multiple outputs, and multiple inputs could be passed in.
* @return
*/
List<List<Generation>> getGenerations();
/**
* Arbitrary LLM-provider specific output
*/
Map<String, Object> getProviderOutput();
/**
* The run metadata information
*/
Map<String, Object> getRunInfo();
}

View File

@@ -0,0 +1,27 @@
/*
* Copyright 2023 the original author or authors.
*
* 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
*
* https://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 org.springframework.ai.core.llm;
import org.springframework.ai.core.prompt.Prompt;
public interface LlmClient {
String generate(String text);
LLMResult generate(Prompt... prompts);
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.ai.core.prompts;
package org.springframework.ai.core.prompt;
public abstract class AbstractPromptTemplate implements PromptOperations {

View File

@@ -14,11 +14,11 @@
* limitations under the License.
*/
package org.springframework.ai.core.prompts;
package org.springframework.ai.core.prompt;
import java.util.Map;
import org.springframework.ai.core.prompts.messages.AiMessage;
import org.springframework.ai.core.prompt.messages.AiMessage;
public class AiPromptTemplate extends PromptTemplate {

View File

@@ -14,11 +14,11 @@
* limitations under the License.
*/
package org.springframework.ai.core.prompts;
package org.springframework.ai.core.prompt;
import java.util.Map;
import org.springframework.ai.core.prompts.messages.ChatMessage;
import org.springframework.ai.core.prompt.messages.ChatMessage;
public class ChatPromptTemplate extends PromptTemplate {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.ai.core.prompts;
package org.springframework.ai.core.prompt;
public class FunctionPromptTemplate extends PromptTemplate {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.ai.core.prompts;
package org.springframework.ai.core.prompt;
import java.util.Map;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.ai.core.prompts;
package org.springframework.ai.core.prompt;
import java.util.List;

View File

@@ -14,13 +14,13 @@
* limitations under the License.
*/
package org.springframework.ai.core.prompts;
package org.springframework.ai.core.prompt;
import java.util.Collections;
import java.util.List;
import org.springframework.ai.core.prompts.messages.HumanMessage;
import org.springframework.ai.core.prompts.messages.Message;
import org.springframework.ai.core.prompt.messages.HumanMessage;
import org.springframework.ai.core.prompt.messages.Message;
public class Prompt {

View File

@@ -14,12 +14,10 @@
* limitations under the License.
*/
package org.springframework.ai.core.prompts;
package org.springframework.ai.core.prompt;
import java.util.Map;
import org.springframework.ai.core.prompts.messages.MessageType;
public interface PromptOperations {
String getTemplate();

View File

@@ -14,9 +14,8 @@
* limitations under the License.
*/
package org.springframework.ai.core.prompts;
package org.springframework.ai.core.prompt;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -30,14 +29,6 @@ import org.antlr.runtime.TokenStream;
import org.stringtemplate.v4.ST;
import org.stringtemplate.v4.compiler.STLexer;
import org.springframework.ai.core.prompts.messages.AiMessage;
import org.springframework.ai.core.prompts.messages.ChatMessage;
import org.springframework.ai.core.prompts.messages.FunctionMessage;
import org.springframework.ai.core.prompts.messages.HumanMessage;
import org.springframework.ai.core.prompts.messages.Message;
import org.springframework.ai.core.prompts.messages.MessageType;
import org.springframework.ai.core.prompts.messages.SystemMessage;
public class PromptTemplate extends AbstractPromptTemplate {
private ST st;

View File

@@ -14,11 +14,11 @@
* limitations under the License.
*/
package org.springframework.ai.core.prompts;
package org.springframework.ai.core.prompt;
import java.util.Map;
import org.springframework.ai.core.prompts.messages.SystemMessage;
import org.springframework.ai.core.prompt.messages.SystemMessage;
public class SystemPromptTemplate extends PromptTemplate {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.ai.core.prompts;
package org.springframework.ai.core.prompt;
public enum TemplateFormat {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.ai.core.prompts.messages;
package org.springframework.ai.core.prompt.messages;
import java.util.HashMap;
import java.util.Map;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.ai.core.prompts.messages;
package org.springframework.ai.core.prompt.messages;
import java.util.Map;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.ai.core.prompts.messages;
package org.springframework.ai.core.prompt.messages;
import java.util.Map;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.ai.core.prompts.messages;
package org.springframework.ai.core.prompt.messages;
import java.util.Map;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.ai.core.prompts.messages;
package org.springframework.ai.core.prompt.messages;
import java.util.Map;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.ai.core.prompts.messages;
package org.springframework.ai.core.prompt.messages;
import java.util.Map;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ai.core.prompts.messages;
package org.springframework.ai.core.prompt.messages;
public enum MessageType {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.ai.core.prompts.messages;
package org.springframework.ai.core.prompt.messages;
import java.util.Map;

View File

@@ -14,9 +14,7 @@
* limitations under the License.
*/
package org.springframework.ai.core.prompts;
import org.junit.jupiter.api.Test;
package org.springframework.ai.core.prompt;
public class ChatTests {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.ai.core.prompts;
package org.springframework.ai.core.prompt;
import java.util.HashMap;
import java.util.Map;