Class: CPEE::LLM::CreateDataFlow

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



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/cpee/llm/implementation.rb', line 142

def response
  llms = @a[0]

  #get parameters
  begin
    input_cpee = @p[0].value().read()
    myllm = @p[1].value().read()
    doc = XML::Smart.string(input_cpee)
  rescue Exception => e
    @status = 400
    return Riddl::Parameter::Complex.new("llm_out","application/json",{:error => e}.to_json())
  end
  begin
    mermaid_model = cpee_to_mermaid(doc.to_s())
    #get endpoints (hardcoded for demo, in future separate step)
    endpoints_description = get_demo_endpoints()
    #match tasks and endpoints
    api_speck = get_matching_endpoints(doc,endpoints_description)
  rescue Exception => e
    @status = 500
    return Riddl::Parameter::Complex.new('llm_out', 'application/json', { error: e }.to_json)
  end

  #generate data flow
  begin
    dataflow = generate_dataflow(myllm,mermaid_model,api_speck,llms)
  rescue LLMError => e
    pp e.http_response
    @status = e.http_response || 400
    return Riddl::Parameter::Complex.new("llm_out","application/json",{:error => e.message}.to_json())
  end

  #integrate dataflow in cpee_model
  final_cpee, endpoints = integrate_dataflow(doc,dataflow)

  return(Riddl::Parameter::Complex.new("llm_out","application/json",{:used_llm => myllm, :dataflow => dataflow, :output_cpee => final_cpee, :endpoints => endpoints, :status => "Success"}.to_json()))
end