Class: Langfuse::ChatPromptClient
- Inherits:
-
Object
- Object
- Langfuse::ChatPromptClient
- Defined in:
- lib/langfuse/chat_prompt_client.rb
Overview
Chat prompt client for compiling chat prompts with variable substitution
Handles chat-based prompts from Langfuse, providing Mustache templating for variable substitution in role-based messages.
Constant Summary collapse
- PLACEHOLDER_TYPE =
"placeholder"
Instance Attribute Summary collapse
-
#commit_message ⇒ String?
readonly
Optional commit message for this prompt version.
-
#config ⇒ Hash
readonly
Prompt configuration.
-
#is_fallback ⇒ Boolean
readonly
Whether this client uses caller-provided fallback content.
-
#labels ⇒ Array<String>
readonly
Labels assigned to this prompt.
-
#name ⇒ String
readonly
Prompt name.
-
#prompt ⇒ Array<Hash>
readonly
Array of message hashes and placeholder entries.
-
#resolution_graph ⇒ Hash?
readonly
Optional dependency resolution graph for composed prompts.
-
#tags ⇒ Array<String>
readonly
Tags assigned to this prompt.
-
#version ⇒ Integer
readonly
Prompt version number.
Instance Method Summary collapse
-
#compile(**kwargs) ⇒ Array<Hash>
Compile the chat prompt with variable substitution and message placeholders.
-
#initialize(prompt_data, is_fallback: false) ⇒ ChatPromptClient
constructor
Initialize a new chat prompt client.
-
#type ⇒ String
Prompt type (“chat”).
Constructor Details
#initialize(prompt_data, is_fallback: false) ⇒ ChatPromptClient
Initialize a new chat prompt client
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/langfuse/chat_prompt_client.rb', line 57 def initialize(prompt_data, is_fallback: false) validate_prompt_data!(prompt_data) @name = prompt_data["name"] @version = prompt_data["version"] @prompt = prompt_data["prompt"] @labels = prompt_data["labels"] || [] @tags = prompt_data["tags"] || [] @config = prompt_data["config"] || {} @commit_message = prompt_data["commitMessage"] @resolution_graph = prompt_data["resolutionGraph"] @is_fallback = is_fallback end |
Instance Attribute Details
#commit_message ⇒ String? (readonly)
Returns Optional commit message for this prompt version.
44 45 46 |
# File 'lib/langfuse/chat_prompt_client.rb', line 44 def @commit_message end |
#config ⇒ Hash (readonly)
Returns Prompt configuration.
38 39 40 |
# File 'lib/langfuse/chat_prompt_client.rb', line 38 def config @config end |
#is_fallback ⇒ Boolean (readonly)
Returns Whether this client uses caller-provided fallback content.
50 51 52 |
# File 'lib/langfuse/chat_prompt_client.rb', line 50 def is_fallback @is_fallback end |
#labels ⇒ Array<String> (readonly)
Returns Labels assigned to this prompt.
32 33 34 |
# File 'lib/langfuse/chat_prompt_client.rb', line 32 def labels @labels end |
#name ⇒ String (readonly)
Returns Prompt name.
26 27 28 |
# File 'lib/langfuse/chat_prompt_client.rb', line 26 def name @name end |
#prompt ⇒ Array<Hash> (readonly)
Returns Array of message hashes and placeholder entries.
41 42 43 |
# File 'lib/langfuse/chat_prompt_client.rb', line 41 def prompt @prompt end |
#resolution_graph ⇒ Hash? (readonly)
Returns Optional dependency resolution graph for composed prompts.
47 48 49 |
# File 'lib/langfuse/chat_prompt_client.rb', line 47 def resolution_graph @resolution_graph end |
#tags ⇒ Array<String> (readonly)
Returns Tags assigned to this prompt.
35 36 37 |
# File 'lib/langfuse/chat_prompt_client.rb', line 35 def @tags end |
#version ⇒ Integer (readonly)
Returns Prompt version number.
29 30 31 |
# File 'lib/langfuse/chat_prompt_client.rb', line 29 def version @version end |
Instance Method Details
#compile(**kwargs) ⇒ Array<Hash>
Compile the chat prompt with variable substitution and message placeholders
Returns an array of message hashes with roles and compiled content. Placeholder entries are resolved from keyword arguments: arrays are expanded, empty arrays are skipped, unresolved placeholders stay in the output, and malformed values raise before invalid messages are sent to an LLM provider.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/langfuse/chat_prompt_client.rb', line 94 def compile(**kwargs) unresolved = [] compiled = [] prompt.each do || normalized = symbolize_keys() if normalized[:type].to_s == PLACEHOLDER_TYPE append_placeholder(normalized, kwargs, compiled, unresolved) else compiled << (normalized, kwargs) end end warn_unresolved(unresolved) compiled end |
#type ⇒ String
Returns Prompt type (“chat”).
72 73 74 |
# File 'lib/langfuse/chat_prompt_client.rb', line 72 def type "chat" end |