Add @stdlib/prompt module for LLM prompt templating#440
Open
nbeerbower wants to merge 1 commit into
Open
Conversation
Provides structured utilities for building multi-turn LLM conversations on top of the existing @stdlib/jinja template engine: - Message constructors: system(), user(), assistant(), tool(), message() - Built-in chat templates: chatml, llama3, alpaca, vicuna, zephyr, gemma, plain - format_chat() for applying named templates to message arrays - apply_template() for custom Jinja templates with extra context - conversation() builder with chaining, filtering, and format methods - templates() and get_template_source() for template introspection Includes parity test (interpreter + compiler), documentation, and CLAUDE.md updates (43 stdlib modules). https://claude.ai/code/session_01DFb8Pffjwa7EoWdiE9xbds
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
@stdlib/promptmodule to the standard library for building and formatting multi-turn LLM conversations. This module provides utilities for creating messages, applying chat templates, and managing conversation state.Key Changes
New module:
stdlib/prompt.hml- Core implementation with 244 linesmessage(),system(),user(),assistant(),tool()format_chat()andapply_template()using Jinja renderingconversation()object with chainable methods for incremental message constructiontemplates()andget_template_source()Built-in chat templates (7 formats):
chatml- OpenAI/Qwen/Yi formatllama3- Meta Llama 3/3.1 formatalpaca- Stanford Alpaca instruction formatvicuna- Vicuna/LMSys formatzephyr- HuggingFace Zephyr (Mistral-based)gemma- Google Gemma formatplain- Simple text format for debuggingDocumentation:
stdlib/docs/prompt.md- Comprehensive guide with API reference, examples, and template specifications (329 lines)Tests:
tests/parity/modules/stdlib_prompt.hml- Full test coverage including message construction, template formatting, conversation builder, and utility functionsUpdated documentation:
CLAUDE.md- Incremented stdlib module count from 42 to 43 and added prompt module to the module listImplementation Details
@stdlib/jinjafor template rendering, allowing both built-in and custom Jinja templatesnamefield for function/tool identificationhttps://claude.ai/code/session_01DFb8Pffjwa7EoWdiE9xbds