lm-lib refactoring;
git-svn-id: svn://home0/lm-lib@3610 71dcc7fd-b1f2-4e5d-bb8e-274146e81173
This commit is contained in:
26
README.md
26
README.md
@@ -1,19 +1,23 @@
|
|||||||
This suite of Java packages provides a comprehensive framework for building, deploying, and interacting with conversational AI agents powered by language models.
|
This suite of Java packages provides a comprehensive framework for building and deploying conversational agents powered by language models.
|
||||||
|
|
||||||
**Core Functionality:**
|
|
||||||
|
|
||||||
* **Agent Framework:** Enables the creation of modular and scalable agents with complex branching logic and concurrent execution capabilities.
|
|
||||||
* **Language Model Interaction:** Provides tools for accessing and interacting with various language models, including Azure AI's text generation service. This includes retrieving model information, managing conversations, generating completions, and customizing parameters.
|
|
||||||
* **Prompt Engineering:** Offers functionalities for constructing and manipulating prompts tailored to specific language models, supporting various formatting strategies.
|
|
||||||
* **Text Processing:** Includes tools for tokenizing and detokenizing text, essential for preparing input for language models and interpreting their output.
|
|
||||||
|
|
||||||
**Purpose:**
|
**Purpose:**
|
||||||
|
|
||||||
The primary purpose of this program is to simplify the development and deployment of sophisticated conversational AI agents. By providing a robust set of tools for agent management, language model interaction, prompt engineering, and text processing, the program empowers developers to create powerful and engaging AI-driven conversational experiences.
|
The primary purpose is to simplify the development and management of AI-driven chatbot applications.
|
||||||
|
|
||||||
*gemma2-27b requests=49, requestDuration=PT7M4.534240136S, inTokens=26243, outTokens=2159, tps=5.091981132075472*
|
**Functionality:**
|
||||||
|
|
||||||
## Introducing a Powerful Framework for Building Intelligent Agents
|
* **Agent Framework:** The core package enables the creation of agents capable of interacting with language models, processing text, maintaining conversation context, tracking statistics, and executing in a structured manner. It supports chaining agents, handling responses, and flexible configuration.
|
||||||
|
* **Language Model Interaction:** Several packages provide tools for interacting with various language models, including Azure AI's text generation service and remote text completion models. These tools handle tasks like retrieving models, managing conversations, generating completions, and tracking API usage.
|
||||||
|
* **Prompt Engineering:** A dedicated package focuses on constructing and manipulating prompts tailored to specific language models. It supports different formatting strategies and allows for fine-grained control over prompt structure.
|
||||||
|
* **Tokenization:** Another package handles text tokenization and detokenization, crucial for preparing text for input to language models and interpreting their outputs.
|
||||||
|
|
||||||
|
**Overall, this collection of packages offers a powerful and flexible toolkit for developers looking to build sophisticated conversational agents leveraging the capabilities of modern language models.**
|
||||||
|
|
||||||
|
*gemma2-27b requests=50, requestDuration=PT3M36.921314511S, inTokens=26737, outTokens=2207, tps=10.217592592592593*
|
||||||
|
|
||||||
|
*[Below announcement has been generated by the unit test AgentTest#agenticFlow:]*
|
||||||
|
|
||||||
|
Title: Introducing a Powerful Framework for Building Intelligent Agents
|
||||||
|
|
||||||
We're excited to announce the development of a new Java codebase designed to build intelligent agents capable of interacting with language models like GPT. This framework offers a flexible and extensible architecture, empowering developers to create sophisticated conversational agents for a wide range of applications.
|
We're excited to announce the development of a new Java codebase designed to build intelligent agents capable of interacting with language models like GPT. This framework offers a flexible and extensible architecture, empowering developers to create sophisticated conversational agents for a wide range of applications.
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import de.extio.lmlib.client.Client;
|
|||||||
import de.extio.lmlib.client.Completion;
|
import de.extio.lmlib.client.Completion;
|
||||||
import de.extio.lmlib.client.Conversation;
|
import de.extio.lmlib.client.Conversation;
|
||||||
import de.extio.lmlib.client.Conversation.TurnType;
|
import de.extio.lmlib.client.Conversation.TurnType;
|
||||||
import de.extio.lmlib.client.profile.ModelCategory;
|
import de.extio.lmlib.profile.ModelCategory;
|
||||||
|
|
||||||
public record Agent(String name, AgentType agentType, ModelCategory modelCategory, String systemPrompt, String textTemplate, AgentResponseHandler responseHandler, Consumer<AgentContext> preProcessor, Consumer<AgentContext> postProcessor, Function<List<AgentContext>, List<AgentContext>> merger, Function<AgentContext, AgentNext> chooseNext) {
|
public record Agent(String name, AgentType agentType, ModelCategory modelCategory, String systemPrompt, String textTemplate, AgentResponseHandler responseHandler, Consumer<AgentContext> preProcessor, Consumer<AgentContext> postProcessor, Function<List<AgentContext>, List<AgentContext>> merger, Function<AgentContext, AgentNext> chooseNext) {
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package de.extio.lmlib.client;
|
package de.extio.lmlib.client;
|
||||||
|
|
||||||
import de.extio.lmlib.client.profile.ModelCategory;
|
import de.extio.lmlib.profile.ModelCategory;
|
||||||
import de.extio.lmlib.client.profile.ModelProfile.ModelProvider;
|
import de.extio.lmlib.profile.ModelProfile.ModelProvider;
|
||||||
|
|
||||||
public interface Client {
|
public interface Client {
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import java.util.List;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import de.extio.lmlib.client.profile.ModelCategory;
|
import de.extio.lmlib.profile.ModelCategory;
|
||||||
import de.extio.lmlib.client.profile.ModelProfileService;
|
import de.extio.lmlib.profile.ModelProfileService;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class ClientService {
|
public class ClientService {
|
||||||
|
|||||||
@@ -32,11 +32,11 @@ import de.extio.lmlib.client.Client;
|
|||||||
import de.extio.lmlib.client.Completion;
|
import de.extio.lmlib.client.Completion;
|
||||||
import de.extio.lmlib.client.Conversation;
|
import de.extio.lmlib.client.Conversation;
|
||||||
import de.extio.lmlib.client.Conversation.Turn;
|
import de.extio.lmlib.client.Conversation.Turn;
|
||||||
import de.extio.lmlib.client.profile.ModelCategory;
|
import de.extio.lmlib.profile.ModelCategory;
|
||||||
import de.extio.lmlib.client.profile.ModelProfile;
|
import de.extio.lmlib.profile.ModelProfile;
|
||||||
import de.extio.lmlib.client.profile.ModelProfile.ModelProvider;
|
import de.extio.lmlib.profile.ModelProfileService;
|
||||||
import de.extio.lmlib.client.profile.ModelProfileService;
|
import de.extio.lmlib.profile.ModelProfile.ModelProvider;
|
||||||
import de.extio.lmlib.client.token.Tokenizer;
|
import de.extio.lmlib.token.Tokenizer;
|
||||||
|
|
||||||
public final class AzureAiClient implements Client {
|
public final class AzureAiClient implements Client {
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import org.springframework.boot.autoconfigure.AutoConfiguration;
|
|||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
|
||||||
import de.extio.lmlib.client.profile.ModelProfileService;
|
import de.extio.lmlib.profile.ModelProfileService;
|
||||||
import de.extio.lmlib.client.token.Tokenizer;
|
import de.extio.lmlib.token.Tokenizer;
|
||||||
|
|
||||||
@AutoConfiguration
|
@AutoConfiguration
|
||||||
@ConditionalOnClass(name = "com.azure.ai.inference.ChatCompletionsClient")
|
@ConditionalOnClass(name = "com.azure.ai.inference.ChatCompletionsClient")
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.reactive.function.client.WebClient;
|
import org.springframework.web.reactive.function.client.WebClient;
|
||||||
|
|
||||||
import de.extio.lmlib.client.profile.ModelProfile.ModelProvider;
|
import de.extio.lmlib.profile.ModelProfileService;
|
||||||
import de.extio.lmlib.client.profile.ModelProfileService;
|
import de.extio.lmlib.profile.ModelProfile.ModelProvider;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
class ModelNameSupplier implements InitializingBean {
|
class ModelNameSupplier implements InitializingBean {
|
||||||
|
|||||||
@@ -23,16 +23,16 @@ import de.extio.lmlib.client.Client;
|
|||||||
import de.extio.lmlib.client.Completion;
|
import de.extio.lmlib.client.Completion;
|
||||||
import de.extio.lmlib.client.Conversation;
|
import de.extio.lmlib.client.Conversation;
|
||||||
import de.extio.lmlib.client.Conversation.Turn;
|
import de.extio.lmlib.client.Conversation.Turn;
|
||||||
import de.extio.lmlib.client.profile.ModelCategory;
|
|
||||||
import de.extio.lmlib.client.profile.ModelProfile;
|
|
||||||
import de.extio.lmlib.client.profile.ModelProfile.ModelProvider;
|
|
||||||
import de.extio.lmlib.client.profile.ModelProfileService;
|
|
||||||
import de.extio.lmlib.client.prompt.PromptStrategy;
|
|
||||||
import de.extio.lmlib.client.prompt.PromptStrategyFactory;
|
|
||||||
import de.extio.lmlib.client.textcompletion.dto.Choice;
|
import de.extio.lmlib.client.textcompletion.dto.Choice;
|
||||||
import de.extio.lmlib.client.textcompletion.dto.CompletionRequest;
|
import de.extio.lmlib.client.textcompletion.dto.CompletionRequest;
|
||||||
import de.extio.lmlib.client.textcompletion.dto.CompletionResponse;
|
import de.extio.lmlib.client.textcompletion.dto.CompletionResponse;
|
||||||
import de.extio.lmlib.client.token.Tokenizer;
|
import de.extio.lmlib.profile.ModelCategory;
|
||||||
|
import de.extio.lmlib.profile.ModelProfile;
|
||||||
|
import de.extio.lmlib.profile.ModelProfileService;
|
||||||
|
import de.extio.lmlib.profile.ModelProfile.ModelProvider;
|
||||||
|
import de.extio.lmlib.prompt.PromptStrategy;
|
||||||
|
import de.extio.lmlib.prompt.PromptStrategyFactory;
|
||||||
|
import de.extio.lmlib.token.Tokenizer;
|
||||||
|
|
||||||
import reactor.util.retry.Retry;
|
import reactor.util.retry.Retry;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package de.extio.lmlib.client.profile;
|
package de.extio.lmlib.profile;
|
||||||
|
|
||||||
public enum ModelCategory {
|
public enum ModelCategory {
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package de.extio.lmlib.client.profile;
|
package de.extio.lmlib.profile;
|
||||||
|
|
||||||
public record ModelProfile(
|
public record ModelProfile(
|
||||||
String prompt,
|
String prompt,
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package de.extio.lmlib.client.profile;
|
package de.extio.lmlib.profile;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -16,7 +16,7 @@ import org.springframework.core.env.Environment;
|
|||||||
import org.springframework.core.io.support.ResourcePropertySource;
|
import org.springframework.core.io.support.ResourcePropertySource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import de.extio.lmlib.client.profile.ModelProfile.ModelProvider;
|
import de.extio.lmlib.profile.ModelProfile.ModelProvider;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class ModelProfileService {
|
public class ModelProfileService {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package de.extio.lmlib.client.prompt;
|
package de.extio.lmlib.prompt;
|
||||||
|
|
||||||
public class AlpacaShortPromptStrategy implements PromptStrategy {
|
public class AlpacaShortPromptStrategy implements PromptStrategy {
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package de.extio.lmlib.client.prompt;
|
package de.extio.lmlib.prompt;
|
||||||
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package de.extio.lmlib.client.prompt;
|
package de.extio.lmlib.prompt;
|
||||||
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package de.extio.lmlib.client.prompt;
|
package de.extio.lmlib.prompt;
|
||||||
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package de.extio.lmlib.client.prompt;
|
package de.extio.lmlib.prompt;
|
||||||
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package de.extio.lmlib.client.prompt;
|
package de.extio.lmlib.prompt;
|
||||||
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package de.extio.lmlib.client.prompt;
|
package de.extio.lmlib.prompt;
|
||||||
|
|
||||||
public interface PromptStrategy {
|
public interface PromptStrategy {
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package de.extio.lmlib.client.prompt;
|
package de.extio.lmlib.prompt;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package de.extio.lmlib.client.prompt;
|
package de.extio.lmlib.prompt;
|
||||||
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package de.extio.lmlib.client.token;
|
package de.extio.lmlib.token;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -10,7 +10,7 @@ import com.knuddels.jtokkit.api.EncodingRegistry;
|
|||||||
import com.knuddels.jtokkit.api.EncodingType;
|
import com.knuddels.jtokkit.api.EncodingType;
|
||||||
import com.knuddels.jtokkit.api.IntArrayList;
|
import com.knuddels.jtokkit.api.IntArrayList;
|
||||||
|
|
||||||
import de.extio.lmlib.client.profile.ModelProfile;
|
import de.extio.lmlib.profile.ModelProfile;
|
||||||
|
|
||||||
final class JTokkitTokenizer implements Tokenizer {
|
final class JTokkitTokenizer implements Tokenizer {
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package de.extio.lmlib.client.token;
|
package de.extio.lmlib.token;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -9,7 +9,7 @@ import org.springframework.http.HttpMethod;
|
|||||||
import org.springframework.web.reactive.function.client.WebClient;
|
import org.springframework.web.reactive.function.client.WebClient;
|
||||||
import org.springframework.web.reactive.function.client.WebClient.Builder;
|
import org.springframework.web.reactive.function.client.WebClient.Builder;
|
||||||
|
|
||||||
import de.extio.lmlib.client.profile.ModelProfile;
|
import de.extio.lmlib.profile.ModelProfile;
|
||||||
|
|
||||||
import reactor.util.retry.Retry;
|
import reactor.util.retry.Retry;
|
||||||
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package de.extio.lmlib.client.token;
|
package de.extio.lmlib.token;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import de.extio.lmlib.client.profile.ModelProfile;
|
import de.extio.lmlib.profile.ModelProfile;
|
||||||
|
|
||||||
public interface Tokenizer {
|
public interface Tokenizer {
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package de.extio.lmlib.client.token;
|
package de.extio.lmlib.token;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||||
@@ -20,7 +20,7 @@ import org.springframework.context.annotation.ComponentScan;
|
|||||||
import org.springframework.context.annotation.PropertySource;
|
import org.springframework.context.annotation.PropertySource;
|
||||||
|
|
||||||
import de.extio.lmlib.client.ClientService;
|
import de.extio.lmlib.client.ClientService;
|
||||||
import de.extio.lmlib.client.profile.ModelCategory;
|
import de.extio.lmlib.profile.ModelCategory;
|
||||||
|
|
||||||
import io.netty.util.internal.ThreadLocalRandom;
|
import io.netty.util.internal.ThreadLocalRandom;
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import org.springframework.context.annotation.PropertySource;
|
|||||||
import de.extio.lmlib.client.Conversation;
|
import de.extio.lmlib.client.Conversation;
|
||||||
import de.extio.lmlib.client.Conversation.Turn;
|
import de.extio.lmlib.client.Conversation.Turn;
|
||||||
import de.extio.lmlib.client.Conversation.TurnType;
|
import de.extio.lmlib.client.Conversation.TurnType;
|
||||||
import de.extio.lmlib.client.profile.ModelCategory;
|
import de.extio.lmlib.profile.ModelCategory;
|
||||||
|
|
||||||
@Disabled
|
@Disabled
|
||||||
@SpringBootTest(webEnvironment = WebEnvironment.NONE)
|
@SpringBootTest(webEnvironment = WebEnvironment.NONE)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import org.springframework.context.annotation.PropertySource;
|
|||||||
import de.extio.lmlib.client.Conversation;
|
import de.extio.lmlib.client.Conversation;
|
||||||
import de.extio.lmlib.client.Conversation.Turn;
|
import de.extio.lmlib.client.Conversation.Turn;
|
||||||
import de.extio.lmlib.client.Conversation.TurnType;
|
import de.extio.lmlib.client.Conversation.TurnType;
|
||||||
import de.extio.lmlib.client.profile.ModelCategory;
|
import de.extio.lmlib.profile.ModelCategory;
|
||||||
|
|
||||||
@SpringBootTest(webEnvironment = WebEnvironment.NONE)
|
@SpringBootTest(webEnvironment = WebEnvironment.NONE)
|
||||||
@SpringBootConfiguration
|
@SpringBootConfiguration
|
||||||
|
|||||||
@@ -12,8 +12,10 @@ import org.springframework.context.annotation.ComponentScan;
|
|||||||
import org.springframework.context.annotation.PropertySource;
|
import org.springframework.context.annotation.PropertySource;
|
||||||
import org.springframework.web.reactive.function.client.WebClient;
|
import org.springframework.web.reactive.function.client.WebClient;
|
||||||
|
|
||||||
import de.extio.lmlib.client.profile.ModelCategory;
|
import de.extio.lmlib.profile.ModelCategory;
|
||||||
import de.extio.lmlib.client.profile.ModelProfileService;
|
import de.extio.lmlib.profile.ModelProfileService;
|
||||||
|
import de.extio.lmlib.token.JTokkitTokenizer;
|
||||||
|
import de.extio.lmlib.token.LlamaServerTokenizer;
|
||||||
|
|
||||||
@SpringBootTest(webEnvironment = WebEnvironment.NONE)
|
@SpringBootTest(webEnvironment = WebEnvironment.NONE)
|
||||||
@SpringBootConfiguration
|
@SpringBootConfiguration
|
||||||
|
|||||||
Reference in New Issue
Block a user