Class: CPEE::LLM::CreateMermaid

Inherits:
Riddl::Implementation
  • Object
show all
Includes:
DataFlow, Functions
Defined in:
lib/cpee/llm/implementation.rb

Overview

{{{

Constant Summary

Constants included from DataFlow

DataFlow::EMBED_CACHE

Instance Method Summary collapse

Methods included from DataFlow

#embed_cached, #get_data_from_url, #get_demo_endpoints, #get_idlabel_from_model, #get_input, #get_matching_endpoints, #integrate_dataflow, #text_similarity

Methods included from Functions

#adapt_cpee_model, #adapt_model, #cpee_to_mermaid, #generate_dataflow, #generate_endpoint_model, #generate_generic, #generate_model, #generate_text, #mermaid_to_cpee, #validate_cpee_model

Methods included from RubyLLM_Requests

#adapt_mermaid_model, #adapt_xml_model, #connect_llm, #generate_content, #generate_dataflow_content, #generate_endpoint_mermaid_model, #generate_generic_content, #generate_json_content, #generate_mermaid_model, #generate_plain_text, #validate_xml_model

Instance Method Details

#responseObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/cpee/llm/implementation.rb', line 34

def response
  llms = @a[0]
  input_cpee  = @p.shift.value.read
  user_input  = @p.shift.value.read
  myllm       = @p.shift.value.read
  prompt_type = @p.shift.value.read if @p[0]&.name == 'prompt_type'
  endpoints   = @p.shift.value.read if @p[0]&.name == 'endpoints'
  temperature = @p.shift.value.read if @p[0]&.name == 'temperature'

  doc = XML::Smart.string(input_cpee)
  pp temperature
  begin
    output_cpee = if prompt_type == 'generate_noendpoints'
      llm_response = generate_model(myllm,user_input,temperature,llms)
      mermaid_to_cpee(llm_response)
    elsif prompt_type == 'generate_endpoints'
      # get endpoints (hardcoded for demo, in future separate step)
      llm_response = generate_endpoint_model(myllm,user_input,get_demo_endpoints(),llms)
      mermaid_to_cpee(llm_response)
    elsif prompt_type == 'adapt_noendpoints'
      llm_response = adapt_model(myllm,doc,user_input,llms)
      mermaid_to_cpee(llm_response)
    elsif prompt_type == 'adapt_endpoints'
      xml_endpoints = XML::Smart.string(endpoints)
      adapt_cpee_model(myllm,doc,user_input,xml_endpoints,get_demo_endpoints(),llms)
    end
  rescue Exception => e
    @status = 500
    return Riddl::Parameter::Complex.new('llm_out', 'application/json', { error: e }.to_json)
  end

  return(Riddl::Parameter::Complex.new("llm_out","application/json",{:user_input => user_input, :used_llm => myllm, :input_cpee => input_cpee, :input_intermediate => doc.root().empty?() ? "" : cpee_to_mermaid(doc.to_s()), :output_intermediate => llm_response, :output_cpee => output_cpee, :status => "Success"}.to_json()))
rescue LLMError => e
  pp 'here in error'
  @status = e&.http_response || 400
  return Riddl::Parameter::Complex.new("llm_out","application/json",{ :error => "#{prompt_type} #{e.message}"}.to_json())
end