-
Notifications
You must be signed in to change notification settings - Fork 5
External templates #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…and tests Included a new SimpleTemplateRenderer implementing the TemplateRenderer interface with functionality to replace placeholders in templates with corresponding values from a variables map. Added comprehensive tests to validate single and multiple placeholder replacements, as well as undefined placeholders throwing exceptions.
Introduced a `Configuration` object to handle properties loading from `langchain4j-kotlin.properties` file. This ensures configurations are loaded at runtime, promoting better management and flexibility of application settings.
This change updates the .editorconfig file to explicitly unset the Kotlin import-on-demand rule. It ensures that Kotlin packages do not use import-on-demand by default, improving code readability and management.
Added specific configuration for Mustache files in .editorconfig to not insert a final newline. This ensures consistent formatting for Mustache template files across different editors.
Introduced methods to load and instantiate `PromptTemplateSource` and `TemplateRenderer` using configuration properties. Enhanced the configuration class to support dynamic instance creation by class name, which improves flexibility and maintainability.
Introduced the TemplateSystemMessageProvider class, which fetches and renders templates for system messages. Added corresponding unit tests to ensure proper functionality, including cases where templates are found and not found.
Converted SimpleTemplateRenderer from an object to a class to allow instance creation. Updated tests to create instances of the class and call the render method. This change provides more flexibility for future enhancements and testing.
Introduced `PromptTemplateFactory` along with supporting interfaces and classes to streamline prompt template creation and management. Renamed `ExtendedPromptTemplate` to `RenderablePromptTemplate` and added properties to the configuration file for template source and renderer.
Introduce `ServiceWithPromptTemplatesTest` to verify that system and user prompt templates work correctly. The test sets up a mock `ChatLanguageModel` and checks the messages against predefined templates.
Standardized the use of type aliases for template-related types in various classes and improved logging practices by replacing println with a logger. This enhances type clarity and ensures uniform handling of sensitive information.
Added comprehensive Kotlin documentation (KDoc) comments to clarify the purpose and usage of key classes and interfaces in the langchain4j-kotlin module. This includes descriptions for classes, methods, properties, and type aliases to improve code readability and maintainability.
Specify the Logger type explicitly in PromptTemplateFactory to ensure type safety and readability. Introduce simplelogger.properties for configuring logging levels and formatting for better diagnostics and debugging during tests.
Created `docs/PromptTemplates.md` to guide users on configuring and using prompt templates within the AiServices module. Updated README to mention the new feature, including a link to the documentation and an overview of prompt template support.
Annotated the ChatLanguageModelIT test class with @EnabledIfEnvironmentVariable to run tests only when the OPENAI_API_KEY environment variable is set. This ensures that tests depending on the OpenAI API are skipped if the API key is not available.
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferencesCodacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more |
This pull request introduces several enhancements and new features to the LangChain4j Kotlin module, primarily focusing on prompt templates and configuration improvements. The most important changes include the addition of prompt template support, configuration management, and various type aliases for better code clarity.
Enhancements to Prompt Templates:
docs/PromptTemplates.md)PromptTemplate,SimplePromptTemplate,PromptTemplateSource,ClasspathPromptTemplateSource,PromptTemplateFactory,RenderablePromptTemplate, andTemplateRenderer. (langchain4j-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/prompt/) [1] [2] [3] [4] [5] [6] [7]Configuration Improvements:
Configurationobject responsible for loading and providing access to application properties, including prompt templates and their renderers. (langchain4j-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/Configuration.kt)Codebase Simplification:
ChatMemoryId,TemplateName,TemplateContent, andPromptContent. (langchain4j-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/TypeAliases.kt)Miscellaneous Changes:
PIImarker withSENSITIVEfor logging sensitive data. (langchain4j-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/internal/Logging.kt,langchain4j-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/model/chat/StreamingChatLanguageModelExtensions.kt) [1] [2] [3] [4]Documentation Updates:
README.md)These changes collectively enhance the functionality, clarity, and maintainability of the LangChain4j Kotlin module.