Module: CPEE::LLM::RubyLLM_Requests
- Included in:
- Functions
- Defined in:
- lib/cpee/llm/rubyllm_requests.rb
Overview
}}}
Instance Method Summary collapse
-
#adapt_mermaid_model(llm, user_input, process_model, llms = {}) ⇒ Object
}}}.
-
#adapt_xml_model(llm, user_input, process_model, api_specification, llms = {}) ⇒ Object
}}}.
-
#connect_llm(myllm, llms) ⇒ Object
{{{.
-
#generate_content(myllm, system_prompt, user_prompt, max_tokens, temperature, llms) ⇒ Object
}}}.
-
#generate_dataflow_content(llm, mermaid_model, api_specification, llms = {}) ⇒ Object
}}}.
-
#generate_endpoint_mermaid_model(llm, user_input, endpoints, llms = {}) ⇒ Object
}}}.
-
#generate_generic_content(llm, user_input, system_prompt, json, temperature, llms = {}) ⇒ Object
}}}.
-
#generate_json_content(myllm, system_prompt, user_prompt, max_tokens, temperature, llms) ⇒ Object
}}}.
-
#generate_mermaid_model(llm, user_input, temperature, llms = {}) ⇒ Object
}}}.
-
#generate_plain_text(llm, user_input, llms = {}) ⇒ Object
}}}.
-
#validate_xml_model(llm, cpee_model, llms = {}) ⇒ Object
}}}.
Instance Method Details
#adapt_mermaid_model(llm, user_input, process_model, llms = {}) ⇒ Object
}}}
103 104 105 106 107 108 109 110 |
# File 'lib/cpee/llm/rubyllm_requests.rb', line 103 def adapt_mermaid_model(llm, user_input, process_model, llms={}) #{{{ max_tokens = 4000 temperature = 0 system_prompt = File.read(File.join(__dir__,"prompts/apply.txt")) user_prompt = "Consider following process model: #{process_model}. Update this process model according to provided changes #{user_input}." new_mermaid = generate_content(llm,system_prompt,user_prompt,max_tokens,temperature,llms) return new_mermaid end |
#adapt_xml_model(llm, user_input, process_model, api_specification, llms = {}) ⇒ Object
}}}
112 113 114 115 116 117 118 119 |
# File 'lib/cpee/llm/rubyllm_requests.rb', line 112 def adapt_xml_model(llm, user_input, process_model, api_specification, llms={}) #{{{ max_tokens = 20000 temperature = 0 system_prompt = File.read(File.join(__dir__,"prompts/adapt_xml.txt")) user_prompt = "Consider following process model: #{process_model.to_s} and task specification #{api_specification} with endpoint data. Update this process model according to provided changes #{user_input}." new_cpee = generate_content(llm,system_prompt,user_prompt,max_tokens,temperature,llms) return new_cpee end |
#connect_llm(myllm, llms) ⇒ Object
{{{
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/cpee/llm/rubyllm_requests.rb', line 36 def connect_llm(myllm,llms) #{{{ chat = nil RubyLLM.configure do |config| config.request_timeout = llms[:request_timeout] config.max_retries = llms[:max_retries] llms[:connectors].each do |k,v| if myllm =~ /#{k}/ && chat.nil? chat = eval(v) end end if chat.nil? raise LLMError.new("Selected LLM model does not exist or is not supported. Please, select another LLM model.", 400) end end return chat end |
#generate_content(myllm, system_prompt, user_prompt, max_tokens, temperature, llms) ⇒ Object
}}}
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/cpee/llm/rubyllm_requests.rb', line 55 def generate_content(myllm, system_prompt, user_prompt, max_tokens, temperature, llms) #{{{ chat = connect_llm(myllm,llms) chat.with_instructions system_prompt chat.with_temperature(temperature) if max_tokens != 0 if myllm.include?("gemini") chat.with_params(generationConfig:{maxOutputTokens: max_tokens}) elsif myllm.include?("gpt") chat.with_params(max_completion_tokens: max_tokens) else chat.with_params(max_tokens: max_tokens) end end response = chat.ask user_prompt return response.content rescue Faraday::TimeoutError => e raise LLMError.new(e., 504) rescue Exception => e raise LLMError.new(e., 500) end |
#generate_dataflow_content(llm, mermaid_model, api_specification, llms = {}) ⇒ Object
}}}
141 142 143 144 145 146 147 148 |
# File 'lib/cpee/llm/rubyllm_requests.rb', line 141 def generate_dataflow_content(llm, mermaid_model, api_specification, llms={}) #{{{ max_tokens = 10000 temperature = 0.1 system_prompt = File.read(File.join(__dir__,"prompts/dataflow.txt")) user_prompt = "Given process mode #{mermaid_model} and task specification #{api_specification} with endpoint data, define the execution context and return a JSON specification." dataflow = generate_content(llm,system_prompt,user_prompt,max_tokens,temperature,llms) return dataflow end |
#generate_endpoint_mermaid_model(llm, user_input, endpoints, llms = {}) ⇒ Object
}}}
150 151 152 153 154 155 156 157 |
# File 'lib/cpee/llm/rubyllm_requests.rb', line 150 def generate_endpoint_mermaid_model(llm, user_input, endpoints, llms={}) #{{{ max_tokens = 4000 temperature = 0.1 system_prompt = File.read(File.join(__dir__,"prompts/generate_enpoints.txt")) user_prompt = "Consider the following process description: #{user_input} and the provided endpoint list: #{endpoints}. Interpret the process description as business intent and generate an executable BPMN model in Mermaid.js format using only the available endpoint capabilities." new_mermaid = generate_content(llm,system_prompt,user_prompt,max_tokens,temperature,llms) return new_mermaid end |
#generate_generic_content(llm, user_input, system_prompt, json, temperature, llms = {}) ⇒ Object
}}}
130 131 132 133 134 135 136 137 138 139 |
# File 'lib/cpee/llm/rubyllm_requests.rb', line 130 def generate_generic_content(llm, user_input, system_prompt, json, temperature, llms={}) #{{{ max_tokens = 20000 temperature = temperature.nil? ? 0 : temperature.to_f if json == 'true' process_description = generate_json_content(llm,system_prompt,user_input,max_tokens,temperature,llms) else process_description = generate_content(llm,system_prompt,user_input,max_tokens,temperature,llms) end return process_description end |
#generate_json_content(myllm, system_prompt, user_prompt, max_tokens, temperature, llms) ⇒ Object
}}}
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/cpee/llm/rubyllm_requests.rb', line 76 def generate_json_content(myllm,system_prompt,user_prompt,max_tokens,temperature,llms) #{{{ chat = connect_llm(myllm,llms) #set parameters chat.with_params(max_tokens: max_tokens,response_format:{type:'json_object'}) chat.with_instructions system_prompt chat.with_temperature(temperature) response = chat.ask user_prompt #puts JSON.parse(response.content) return response.content rescue Faraday::TimeoutError => e raise LLMError.new(e., 504) rescue Exception => e raise LLMError.new(e., 500) end |
#generate_mermaid_model(llm, user_input, temperature, llms = {}) ⇒ Object
}}}
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/cpee/llm/rubyllm_requests.rb', line 92 def generate_mermaid_model(llm, user_input, temperature, llms={}) #{{{ max_tokens = 4000 temperature = temperature.nil? ? 0.1 : temperature.to_f pp "here" pp temperature system_prompt = File.read(File.join(__dir__,"prompts/generate1.txt")) user_prompt = "Consider following process description: #{user_input}. Generate a BPMN model in Mermaid.js format." new_mermaid = generate_content(llm,system_prompt,user_prompt,max_tokens,temperature,llms) return new_mermaid end |
#generate_plain_text(llm, user_input, llms = {}) ⇒ Object
}}}
121 122 123 124 125 126 127 128 |
# File 'lib/cpee/llm/rubyllm_requests.rb', line 121 def generate_plain_text(llm, user_input, llms={}) #{{{ max_tokens = 4000 temperature = 0 system_prompt = File.read(File.join(__dir__,"prompts/describe.txt")) user_prompt = "Consider following process process model: #{user_input}. Generate a text describing provided process description." process_description = generate_content(llm,system_prompt,user_prompt,max_tokens,temperature,llms) return process_description end |
#validate_xml_model(llm, cpee_model, llms = {}) ⇒ Object
}}}
159 160 161 162 163 164 165 166 |
# File 'lib/cpee/llm/rubyllm_requests.rb', line 159 def validate_xml_model(llm, cpee_model, llms={}) #{{{ max_tokens = 0 temperature = 0.1 system_prompt = File.read(File.join(__dir__,"prompts/validate_xml.txt")) user_prompt = "Consider following CPEE XML promcess model created by autobpmn.ai: #{cpee_model}. Repair the model so that it becomes executable. Return only the repaired XML without any comments or markdown formatting." repaired_cpee = generate_content(llm,system_prompt,user_prompt,max_tokens,temperature,llms) return repaired_cpee end |