Class: Langfuse::TextPromptClient
- Inherits:
-
Object
- Object
- Langfuse::TextPromptClient
- Defined in:
- lib/langfuse/text_prompt_client.rb
Overview
Text prompt client for compiling text prompts with variable substitution
Handles text-based prompts from Langfuse, providing Mustache templating for variable substitution.
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 ⇒ String
readonly
Raw prompt template.
-
#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) ⇒ String
Compile the prompt with variable substitution.
-
#initialize(prompt_data, is_fallback: false) ⇒ TextPromptClient
constructor
Initialize a new text prompt client.
-
#type ⇒ String
Prompt type ("text").
-
#variables ⇒ Array<String>
Return the unique variables referenced by the prompt template.
Constructor Details
#initialize(prompt_data, is_fallback: false) ⇒ TextPromptClient
Initialize a new text prompt client
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/langfuse/text_prompt_client.rb', line 56 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.
43 44 45 |
# File 'lib/langfuse/text_prompt_client.rb', line 43 def @commit_message end |
#config ⇒ Hash (readonly)
Returns Prompt configuration.
37 38 39 |
# File 'lib/langfuse/text_prompt_client.rb', line 37 def config @config end |
#is_fallback ⇒ Boolean (readonly)
Returns Whether this client uses caller-provided fallback content.
49 50 51 |
# File 'lib/langfuse/text_prompt_client.rb', line 49 def is_fallback @is_fallback end |
#labels ⇒ Array<String> (readonly)
Returns Labels assigned to this prompt.
31 32 33 |
# File 'lib/langfuse/text_prompt_client.rb', line 31 def labels @labels end |
#name ⇒ String (readonly)
Returns Prompt name.
25 26 27 |
# File 'lib/langfuse/text_prompt_client.rb', line 25 def name @name end |
#prompt ⇒ String (readonly)
Returns Raw prompt template.
40 41 42 |
# File 'lib/langfuse/text_prompt_client.rb', line 40 def prompt @prompt end |
#resolution_graph ⇒ Hash? (readonly)
Returns Optional dependency resolution graph for composed prompts.
46 47 48 |
# File 'lib/langfuse/text_prompt_client.rb', line 46 def resolution_graph @resolution_graph end |
#tags ⇒ Array<String> (readonly)
Returns Tags assigned to this prompt.
34 35 36 |
# File 'lib/langfuse/text_prompt_client.rb', line 34 def @tags end |
#version ⇒ Integer (readonly)
Returns Prompt version number.
28 29 30 |
# File 'lib/langfuse/text_prompt_client.rb', line 28 def version @version end |
Instance Method Details
#compile(**kwargs) ⇒ String
Compile the prompt with variable substitution
95 96 97 98 99 |
# File 'lib/langfuse/text_prompt_client.rb', line 95 def compile(**kwargs) return prompt if kwargs.empty? PromptRenderer.render(prompt, kwargs) end |
#type ⇒ String
Returns Prompt type ("text").
71 72 73 |
# File 'lib/langfuse/text_prompt_client.rb', line 71 def type "text" end |
#variables ⇒ Array<String>
Return the unique variables referenced by the prompt template
Section names are included because callers must provide their values. Variables inside sections include the full section path.
82 83 84 |
# File 'lib/langfuse/text_prompt_client.rb', line 82 def variables PromptVariables.extract(prompt) end |