lm-lib: Merged with tp fork;
git-svn-id: svn://home0/lm-lib@3723 71dcc7fd-b1f2-4e5d-bb8e-274146e81173
This commit is contained in:
152
README.md
152
README.md
@@ -1,21 +1,151 @@
|
||||
This suite of Java packages provides a comprehensive framework for building and deploying conversational agents powered by language models.
|
||||
# Purpose
|
||||
|
||||
**Purpose:**
|
||||
The purpose of this application is to provide a comprehensive conversational AI system that enables efficient and effective human-computer interactions through natural language processing, conversation management, and text completion capabilities, utilizing caching, tokenization, and integration with external AI models and services to deliver a robust and scalable solution for applications such as chatbots, virtual assistants, and customer service platforms.
|
||||
|
||||
The primary purpose is to simplify the development and management of AI-driven chatbot applications.
|
||||
# Program Description
|
||||
|
||||
**Functionality:**
|
||||
The program is a comprehensive conversational AI system that provides natural language processing functionality, conversation management, and text completion capabilities. The purpose of the program is to enable efficient and effective human-computer interactions through AI-powered conversations.
|
||||
|
||||
* **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.
|
||||
The program consists of several packages that work together to achieve this goal. These packages include:
|
||||
|
||||
**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.**
|
||||
1. **Caching layer (com.transporeon.exchange.lmlib.client.cached)**: Improves performance by reducing requests to the underlying client through caching and retrieving completion responses.
|
||||
2. **Natural Language Processing (com.transporeon.exchange.lmlib.client)**: Provides conversation management and text completion functionality, generating completions, processing conversations, and managing models.
|
||||
3. **Azure AI Integration (com.transporeon.exchange.lmlib.client.azureai)**: Integrates with Azure AI services, managing model profiles and handling conversation completions.
|
||||
4. **Text Completion (com.transporeon.exchange.lmlib.client.textcompletion)**: Provides text completion functionality using AI models, including model selection, prompt generation, and response handling.
|
||||
5. **Text Tokenization (com.transporeon.exchange.lmlib.token)**: Tokenizes text into numerical tokens and detokenizes numerical tokens back into human-readable text.
|
||||
6. **Conversation Prompts (com.transporeon.exchange.lmlib.prompt)**: Manages conversation prompts, creating new prompts, continuing conversations, and removing end-of-text markers.
|
||||
7. **Agent Executor (com.transporeon.exchange.lmlib.agent)**: Executes agent graphs concurrently, handles agent responses, and tracks request statistics.
|
||||
|
||||
*gemma2-27b requests=50, requestDuration=PT3M36.921314511S, inTokens=26737, outTokens=2207, tps=10.217592592592593*
|
||||
The program's key features include:
|
||||
|
||||
*[Below announcement has been generated by the unit test AgentTest#agenticFlow:]*
|
||||
* Agent graph execution
|
||||
* Conversation management and text completion
|
||||
* Integration with external AI models and services (e.g., Azure AI)
|
||||
* Support for multiple prompt strategies and tokenization implementations
|
||||
* Caching and performance optimization
|
||||
|
||||
Overall, the program is designed to provide a robust and efficient conversational AI system that can be used in various applications, such as chatbots, virtual assistants, and customer service platforms.
|
||||
|
||||
*AgentRequestStatistic [requests=43, cachedPrompts=2, inTokens=23437, outTokens=7403, requestDuration=PT2M31.7349284S, getEffectiveDuration()=PT1M37.2400495S, getTps()=317.15, getOutTps()=76.13, getCost()=0.01458674]*
|
||||
|
||||
# Setup
|
||||
|
||||
To keep this library lean and compatible with different dependency trees, all dependencies must be provided by the application.
|
||||
|
||||
## Mandatory dependencies
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||
</dependency>
|
||||
|
||||
## Optional dependencies
|
||||
|
||||
Some services benefit from Spring cache framework, e.g. the model profile service:
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-cache</artifactId>
|
||||
</dependency>
|
||||
|
||||
Don't forget to activate a CacheManager afterwards:
|
||||
|
||||
@Bean
|
||||
public CacheManager cacheManager() {
|
||||
return new CaffeineCacheManager();
|
||||
}
|
||||
|
||||
## Model profiles
|
||||
|
||||
Models are managed with profiles. You can maintain multiple profiles for different models and parameters such as temperature.
|
||||
|
||||
These profiles must be mapped to fixed categories with the following application properties:
|
||||
|
||||
profile.model.s=
|
||||
profile.model.m=
|
||||
profile.model.l=
|
||||
profile.model.hot=
|
||||
profile.model.cold=
|
||||
|
||||
The value is the name of the model profile .properties file, for example "llama3.3-70b-azure".
|
||||
|
||||
Profiles must be located in the main resources location.
|
||||
|
||||
Examples can be found in test resources.
|
||||
|
||||
## OpenAi compatible text completion client
|
||||
|
||||
Use tokenizer strategy jtokkit or llamaServer (if the model is hosted on a llama.cpp server)
|
||||
|
||||
Property:
|
||||
|
||||
tokenizer.strategy=llamaServer
|
||||
|
||||
If you use jtokkit tokenizer:
|
||||
|
||||
<dependency>
|
||||
<groupId>com.knuddels</groupId>
|
||||
<artifactId>jtokkit</artifactId>
|
||||
</dependency>
|
||||
|
||||
It is required to select the right prompt template. See package com.transporeon.exchange.lmlib.prompt for available prompt templates or implement your own PromptStrategy (must be a bean in the spring context).
|
||||
|
||||
Set the following property in your model profile:
|
||||
|
||||
prompts=llama3
|
||||
|
||||
Example profile: src/test/resources/llama3-local.properties
|
||||
|
||||
## Azure AI client
|
||||
|
||||
Use tokenizer strategy jtokkit.
|
||||
|
||||
Property:
|
||||
|
||||
tokenizer.strategy=jtokkit
|
||||
|
||||
Example profile: src/test/resources/llama3.3-70b-azure.properties
|
||||
|
||||
<dependency>
|
||||
<groupId>com.azure</groupId>
|
||||
<artifactId>azure-ai-inference</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.knuddels</groupId>
|
||||
<artifactId>jtokkit</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.ben-manes.caffeine</groupId>
|
||||
<artifactId>caffeine</artifactId>
|
||||
</dependency>
|
||||
|
||||
# Completions Cache
|
||||
|
||||
All language model requests will be cached if you add a CachedClientRepository bean to your context.
|
||||
|
||||
# Agentic Flows
|
||||
|
||||
This library contains a graph executor for implementing comprehensive processes using agent-based design patterns. See class AgentTest for examples.
|
||||
|
||||
# Usage
|
||||
|
||||
1. Setup dependencies, see above
|
||||
2. Configure model profiles, see above
|
||||
3. Implement a CachedClientRepository if you need your requests cached
|
||||
4. For chats or completions, use ClientService service bean
|
||||
5. For agentic flows, create an AgentContext and use AgentExecutorService service bean
|
||||
|
||||
# Examples
|
||||
|
||||
Text completions: AzureAiClientTest#completion
|
||||
Chat: AzureAiClientTest#chat
|
||||
Agentic flow: AgentTest#agenticFlow
|
||||
|
||||
# Announcement generated by AgentTest#agenticFlow
|
||||
|
||||
Title: Introducing a Powerful Framework for Building Intelligent Agents
|
||||
|
||||
|
||||
Reference in New Issue
Block a user