Class: Langfuse::Prompt

Inherits:
Object
  • Object
show all
Defined in:
lib/langfuse/prompt.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Prompt

Returns a new instance of Prompt.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/langfuse/prompt.rb', line 5

def initialize(data)
  @data = data.is_a?(Hash) ? Utils.deep_symbolize_keys(data) : data

  @id = @data[:id]
  @name = @data[:name]
  @version = @data[:version]
  @prompt = @data[:prompt]
  @config = @data[:config] || {}
  @labels = @data[:labels] || []
  @tags = @data[:tags] || []
  @type = @data[:type]
  @created_at = @data[:created_at]
  @updated_at = @data[:updated_at]
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



3
4
5
# File 'lib/langfuse/prompt.rb', line 3

def config
  @config
end

#created_atObject (readonly)

Returns the value of attribute created_at.



3
4
5
# File 'lib/langfuse/prompt.rb', line 3

def created_at
  @created_at
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/langfuse/prompt.rb', line 3

def id
  @id
end

#labelsObject (readonly)

Returns the value of attribute labels.



3
4
5
# File 'lib/langfuse/prompt.rb', line 3

def labels
  @labels
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/langfuse/prompt.rb', line 3

def name
  @name
end

#promptObject (readonly)

Returns the value of attribute prompt.



3
4
5
# File 'lib/langfuse/prompt.rb', line 3

def prompt
  @prompt
end

#tagsObject (readonly)

Returns the value of attribute tags.



3
4
5
# File 'lib/langfuse/prompt.rb', line 3

def tags
  @tags
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/langfuse/prompt.rb', line 3

def type
  @type
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



3
4
5
# File 'lib/langfuse/prompt.rb', line 3

def updated_at
  @updated_at
end

#versionObject (readonly)

Returns the value of attribute version.



3
4
5
# File 'lib/langfuse/prompt.rb', line 3

def version
  @version
end

Instance Method Details

#compile(variables = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/langfuse/prompt.rb', line 32

def compile(variables = {})
  # Compile prompt with variables
  case @type
  when 'text'
    compile_text_prompt(variables)
  when 'chat'
    compile_chat_prompt(variables)
  else
    raise ValidationError, "Unsupported prompt type: #{@type}"
  end
end

#get_langchain_promptObject



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/langfuse/prompt.rb', line 20

def get_langchain_prompt
  # Convert Langfuse prompt format to LangChain format
  case @type
  when 'text'
    text_to_langchain_prompt
  when 'chat'
    chat_to_langchain_prompt
  else
    raise ValidationError, "Unsupported prompt type: #{@type}"
  end
end

#to_dictObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/langfuse/prompt.rb', line 44

def to_dict
  {
    id: @id,
    name: @name,
    version: @version,
    prompt: @prompt,
    config: @config,
    labels: @labels,
    tags: @tags,
    type: @type,
    created_at: @created_at,
    updated_at: @updated_at
  }
end