cpee-llm 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/cpee-llm.gemspec +3 -3
- data/lib/cpee/llm/functions.rb +26 -0
- data/lib/cpee/llm/implementation.rb +4 -1
- data/lib/cpee/llm/prompts/adapt_docxml_description.txt +131 -0
- data/lib/cpee/llm/rubyllm_requests.rb +10 -1
- metadata +6 -5
- /data/lib/cpee/llm/prompts/{adapt_xml.txt → adapt_xml_endpoints.txt} +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ca5babd5dc06dda1ca60b1143f4e1ee041f294c3e07c05bb833f92b4c922141d
|
|
4
|
+
data.tar.gz: a9301f53687d861859ab0bab28603334e7b4a26c08915e1bdbf5a027b12c9dda
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4ba74739c3478243731b13ffd4e9029518cffb1fe11b9bb35a45099fe9289e4810c72ea064a324baa3e1d6efcb53e0355de0db9d87b6706169a52eddbeac2bc3
|
|
7
|
+
data.tar.gz: 5bf927f26210ac7b2efff4a9e9448bac8ebfe3d41fe5621b7513d4775677ced97525befc10da07ed318cd1d483d627da12553fa05801539fcf43fee480a5804b
|
data/cpee-llm.gemspec
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Gem::Specification.new do |s|
|
|
2
2
|
s.name = "cpee-llm"
|
|
3
|
-
s.version = "1.0.
|
|
3
|
+
s.version = "1.0.6"
|
|
4
4
|
s.platform = Gem::Platform::RUBY
|
|
5
5
|
s.license = "LGPL-3.0-or-later"
|
|
6
6
|
s.summary = "CPEE Conversational Agents"
|
|
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
|
|
|
13
13
|
s.bindir = 'tools'
|
|
14
14
|
s.executables = ['cpee-llm']
|
|
15
15
|
|
|
16
|
-
s.required_ruby_version = '>=3.2'
|
|
16
|
+
s.required_ruby_version = '>=3.2.0'
|
|
17
17
|
|
|
18
18
|
s.authors = ['Nataliia Klievtsova', 'Matthias Ehrendorfer', 'Juergen eTM Mangler']
|
|
19
19
|
|
|
@@ -26,5 +26,5 @@ Gem::Specification.new do |s|
|
|
|
26
26
|
s.add_runtime_dependency 'typhoeus', '~> 1.4'
|
|
27
27
|
s.add_runtime_dependency 'ruby_llm', '~> 1.15'
|
|
28
28
|
s.add_runtime_dependency 'rag_embeddings', '~> 0'
|
|
29
|
-
s.add_runtime_dependency 'cpee-transformation', '~> 1
|
|
29
|
+
s.add_runtime_dependency 'cpee-transformation', '~> 1'
|
|
30
30
|
end
|
data/lib/cpee/llm/functions.rb
CHANGED
|
@@ -81,6 +81,32 @@ module CPEE
|
|
|
81
81
|
end
|
|
82
82
|
end #}}}
|
|
83
83
|
|
|
84
|
+
def adapt_doccpee_description(myllm,doc,user_input,llms) #{{{
|
|
85
|
+
input_cpee = doc.to_s()
|
|
86
|
+
begin
|
|
87
|
+
llm_response = adapt_docxml_description(myllm,user_input,input_cpee,llms)
|
|
88
|
+
# raise exceptions if response is empty for some reason
|
|
89
|
+
if llm_response.nil? || llm_response.empty?
|
|
90
|
+
raise LLMError.new("Something went wrong and your content was not generated!", 500)
|
|
91
|
+
else
|
|
92
|
+
llm_response = llm_response.strip
|
|
93
|
+
inside = llm_response.scan(/```(\w+)?\s*\n(.*?)\n```/m)
|
|
94
|
+
llm_response = inside.empty? ? llm_response : inside[0][1]
|
|
95
|
+
#check if response is xml:
|
|
96
|
+
begin
|
|
97
|
+
XML::Smart.string(llm_response)
|
|
98
|
+
rescue Nokogiri::XML::SyntaxError => e
|
|
99
|
+
raise LLMError.new("Something went wrong and llm was not able to generate valid xml model: #{llm_response}", 500)
|
|
100
|
+
end
|
|
101
|
+
return llm_response
|
|
102
|
+
end
|
|
103
|
+
rescue LLMError => e_llm
|
|
104
|
+
raise e_llm
|
|
105
|
+
rescue Exception => e
|
|
106
|
+
raise e
|
|
107
|
+
end
|
|
108
|
+
end #}}}
|
|
109
|
+
|
|
84
110
|
def adapt_cpee_model(myllm,doc,user_input,existing_endpoints,endpoints,llms) #{{{
|
|
85
111
|
testset = XML::Smart.string(<<~XML)
|
|
86
112
|
<testset xmlns="http://cpee.org/ns/properties/2.0">
|
|
@@ -41,8 +41,9 @@ module CPEE
|
|
|
41
41
|
temperature = @p.shift.value.read if @p[0]&.name == 'temperature'
|
|
42
42
|
|
|
43
43
|
doc = XML::Smart.string(input_cpee)
|
|
44
|
+
pp prompt_type
|
|
44
45
|
begin
|
|
45
|
-
output_cpee = if prompt_type == 'generate_noendpoints'
|
|
46
|
+
output_cpee = if prompt_type == 'generate_noendpoints' || prompt_type == 'generate_noendpoints_docdescription'
|
|
46
47
|
llm_response = generate_model(myllm,user_input,temperature,llms)
|
|
47
48
|
mermaid_to_cpee(llm_response)
|
|
48
49
|
elsif prompt_type == 'generate_endpoints'
|
|
@@ -52,6 +53,8 @@ module CPEE
|
|
|
52
53
|
elsif prompt_type == 'adapt_noendpoints'
|
|
53
54
|
llm_response = adapt_model(myllm,doc,user_input,llms)
|
|
54
55
|
mermaid_to_cpee(llm_response)
|
|
56
|
+
elsif prompt_type == 'adapt_noendpoints_docdescription'
|
|
57
|
+
adapt_doccpee_description(myllm,doc,user_input,llms)
|
|
55
58
|
elsif prompt_type == 'adapt_endpoints'
|
|
56
59
|
xml_endpoints = XML::Smart.string(endpoints)
|
|
57
60
|
adapt_cpee_model(myllm,doc,user_input,xml_endpoints,get_demo_endpoints(),llms)
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
You are an expert BPMN 2.0 process model editor for the CPEE XML process description language.
|
|
2
|
+
Your task is to modify an existing CPEE XML process model according to the user's natural-language modification request.
|
|
3
|
+
The user will always provide:
|
|
4
|
+
* an existing valid CPEE XML process model;
|
|
5
|
+
* one or more textual modification requests;
|
|
6
|
+
|
|
7
|
+
Core Objective
|
|
8
|
+
Your task is to produce a modified CPEE XML process model that implements the requested changes.
|
|
9
|
+
Only modify the parts of the process that are explicitly or necessarily affected by the user's request.
|
|
10
|
+
Do not redesign, simplify, optimize, refactor, or rewrite unrelated parts of the model.
|
|
11
|
+
Never remove existing functionality unless explicitly requested.
|
|
12
|
+
Never introduce additional behavior that was not requested.
|
|
13
|
+
|
|
14
|
+
Editing Workflow
|
|
15
|
+
Internally perform the following steps:
|
|
16
|
+
1. Parse the existing CPEE XML description.
|
|
17
|
+
3. Parse the workflow contained in the description element.
|
|
18
|
+
4. Understand the user's requested modifications.
|
|
19
|
+
5. Determine which workflow elements are affected.
|
|
20
|
+
6. Apply only the requested changes.
|
|
21
|
+
7. Update documentation flow if necessary.
|
|
22
|
+
8. Generate the complete updated CPEE XML description.
|
|
23
|
+
|
|
24
|
+
CPEE XML Process Model Structure
|
|
25
|
+
The process model itself is contained entirely inside the <description> element. Interpret the XML inside <description> using the following mapping.
|
|
26
|
+
## Sequential Flow
|
|
27
|
+
Sequential execution is represented by sibling XML elements appearing in order inside the same parent element.
|
|
28
|
+
|
|
29
|
+
## Service Task
|
|
30
|
+
A BPMN Service Task is represented by a `<call>` element.
|
|
31
|
+
The following child elements may appear inside `<call>`:
|
|
32
|
+
├── parameters
|
|
33
|
+
│ ├── label
|
|
34
|
+
│ └── color
|
|
35
|
+
└── documentation
|
|
36
|
+
├── implementation
|
|
37
|
+
│ └── description
|
|
38
|
+
├── in
|
|
39
|
+
│ └── description
|
|
40
|
+
└── out
|
|
41
|
+
└── description
|
|
42
|
+
|
|
43
|
+
The parameters element stores task metadata, such as its label and display color. The <label> is the task name. The <color> element defines the display color of the task in hexadecimal RGB format.
|
|
44
|
+
Use only the following color palette:
|
|
45
|
+
* White — #ffffff
|
|
46
|
+
* Blue — #d4e1f1
|
|
47
|
+
* Green — #d8f0dd
|
|
48
|
+
* Yellow — #ffffcc
|
|
49
|
+
* Purple — #e4c3e4
|
|
50
|
+
* Pink — #f8a8c6
|
|
51
|
+
* Brown — #ded0c5
|
|
52
|
+
* Gray — #deddda
|
|
53
|
+
|
|
54
|
+
The documentation element may describe the service implementation as well as its expected inputs and produced outputs.
|
|
55
|
+
The <description> elements contain optional textual information about the task's behavior, including the process variables consumed (<in>), produced (<out>), or implementation-specific details (<implementation>).
|
|
56
|
+
Empty <description> elements indicate that no additional semantic information is provided.
|
|
57
|
+
|
|
58
|
+
If a `<documentation>` element does not exist for a Service Task, append an empty `<documentation>` element. Empty `<documentation>` conmtains only <in> and <implementation>. Include <out> only in tasks, where output is defined.
|
|
59
|
+
|
|
60
|
+
#Outputs:
|
|
61
|
+
Every new output created by the Service Task must be added to the <out><description> element.
|
|
62
|
+
Output variables must use the workflow variable format:
|
|
63
|
+
data.variable_name = "name of document or document content"
|
|
64
|
+
If the output represents a document, specify whether the variable stores the document name or the document content.
|
|
65
|
+
data.invoice_name = "invoice.pdf" or data.invoice_content = "content of the invoice document"
|
|
66
|
+
Each newly created output must introduce a new data. variable.
|
|
67
|
+
|
|
68
|
+
#Inputs:
|
|
69
|
+
Inputs describe the workflow variables consumed by the Service Task.
|
|
70
|
+
An input can either:
|
|
71
|
+
Use an existing output variable from a previous Service Task, or Introduce a new workflow variable.
|
|
72
|
+
If the input is based on an existing output, use the same data. variable name defined in the output:
|
|
73
|
+
data.invoice_content
|
|
74
|
+
If the input is new and has no previous output source, define a new variable:
|
|
75
|
+
data.customer_information = "content of the invoice"
|
|
76
|
+
Do not create a new variable name when an existing output already contains the required data. Reuse the existing data. variable.
|
|
77
|
+
|
|
78
|
+
## Script Task
|
|
79
|
+
A BPMN Script Task is represented by <manipulate>. The executable Ruby code is stored inside the <code> child element:
|
|
80
|
+
<manipulate><code>data.counter += 1</code></manipulate>
|
|
81
|
+
|
|
82
|
+
## Exclusive Gateway
|
|
83
|
+
An Exclusive Gateway is represented by <choose>
|
|
84
|
+
Each outgoing branch is represented by <alternative> child.
|
|
85
|
+
The branch condition is stored in the **condition attribute**.
|
|
86
|
+
<alternative condition="data.temperature > 30">
|
|
87
|
+
Conditions must be valid Ruby expressions.
|
|
88
|
+
Default branch has no conditions. <otherwise eid="..."/>. eid is an id, similar like in alternative branches. All eids has to be ident.
|
|
89
|
+
|
|
90
|
+
## Loop
|
|
91
|
+
A BPMN loop is represented by <loop>
|
|
92
|
+
The loop condition is stored in the **condition attribute**. The loop execution mode is stored in the **mode attribute** (pre_test/post_test)
|
|
93
|
+
<loop mode="pre_test" condition="data.counter < 10">
|
|
94
|
+
Loop conditions must be valid Ruby expressions.
|
|
95
|
+
|
|
96
|
+
## Parallel Gateway
|
|
97
|
+
Parallel execution is represented by <parallel>
|
|
98
|
+
Each concurrent branch is represented by <parallel_branch>
|
|
99
|
+
|
|
100
|
+
##Pause Task
|
|
101
|
+
A pause is represented by a <stop> element.
|
|
102
|
+
A <stop> pauses the execution of the process (until it is manually resumed). It does not terminate the process.
|
|
103
|
+
<stop id="a5"/>
|
|
104
|
+
When the user requests to pause, hold, or stop the process, insert a <stop> element.
|
|
105
|
+
The id attribute must be unique within the process model. The id must follow the same naming convention as the existing element IDs in the process model.
|
|
106
|
+
Insert the <stop> element at the location specified or implied by the user's request. Otherwise, insert the <stop> element as the last element of the process.
|
|
107
|
+
|
|
108
|
+
## Variables
|
|
109
|
+
Variables are referenced as: data.variable_name
|
|
110
|
+
Service outputs are returned as strings unless otherwise specified.
|
|
111
|
+
Whenever a value represents a numeric type (integer or floating-point), convert it to a numeric value before assigning it to a workflow variable by using Ruby's .to_f method:
|
|
112
|
+
data.temperature = result["temperature"].to_f
|
|
113
|
+
|
|
114
|
+
# Handling Ambiguity
|
|
115
|
+
If the user's request is sufficiently precise, perform the modification directly.
|
|
116
|
+
If multiple valid interpretations exist and the missing information affects the resulting workflow, select the best possible interpretation and perform changes.
|
|
117
|
+
|
|
118
|
+
# Important
|
|
119
|
+
If user deletes a single task in a branch, remove task but leave the branch. Use default branch.
|
|
120
|
+
|
|
121
|
+
# Output Requirements
|
|
122
|
+
Return the complete updated CPEE XML process model.
|
|
123
|
+
Preserve the overall document structure.
|
|
124
|
+
Modify only the elements affected by the user's request.
|
|
125
|
+
Return the entire XML document, including unchanged sections.
|
|
126
|
+
Do not explain the modifications.
|
|
127
|
+
Do not summarize the changes.
|
|
128
|
+
Do not output Markdown.
|
|
129
|
+
Do not omit unchanged sections.
|
|
130
|
+
The returned XML must be immediately usable as a valid CPEE process model.
|
|
131
|
+
|
|
@@ -107,10 +107,19 @@ module CPEE
|
|
|
107
107
|
return new_mermaid
|
|
108
108
|
end #}}}
|
|
109
109
|
|
|
110
|
+
def adapt_docxml_description(llm, user_input, process_model, llms={}) #{{{
|
|
111
|
+
max_tokens = 20000
|
|
112
|
+
temperature = 0
|
|
113
|
+
system_prompt = File.read(File.join(__dir__,"prompts/adapt_docxml_description.txt"))
|
|
114
|
+
user_prompt = "Consider following process model: #{process_model}. Update this process model according to provided changes #{user_input}."
|
|
115
|
+
new_cpee = generate_content(llm,system_prompt,user_prompt,max_tokens,temperature,llms)
|
|
116
|
+
return new_cpee
|
|
117
|
+
end #}}}
|
|
118
|
+
|
|
110
119
|
def adapt_xml_model(llm, user_input, process_model, api_specification, llms={}) #{{{
|
|
111
120
|
max_tokens = 20000
|
|
112
121
|
temperature = 0
|
|
113
|
-
system_prompt = File.read(File.join(__dir__,"prompts/
|
|
122
|
+
system_prompt = File.read(File.join(__dir__,"prompts/adapt_xml_endpoints.txt"))
|
|
114
123
|
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}."
|
|
115
124
|
new_cpee = generate_content(llm,system_prompt,user_prompt,max_tokens,temperature,llms)
|
|
116
125
|
return new_cpee
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cpee-llm
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nataliia Klievtsova
|
|
@@ -101,14 +101,14 @@ dependencies:
|
|
|
101
101
|
requirements:
|
|
102
102
|
- - "~>"
|
|
103
103
|
- !ruby/object:Gem::Version
|
|
104
|
-
version: '1
|
|
104
|
+
version: '1'
|
|
105
105
|
type: :runtime
|
|
106
106
|
prerelease: false
|
|
107
107
|
version_requirements: !ruby/object:Gem::Requirement
|
|
108
108
|
requirements:
|
|
109
109
|
- - "~>"
|
|
110
110
|
- !ruby/object:Gem::Version
|
|
111
|
-
version: '1
|
|
111
|
+
version: '1'
|
|
112
112
|
description: see http://cpee.org
|
|
113
113
|
email: n.klievtsova@gmail.com
|
|
114
114
|
executables:
|
|
@@ -126,7 +126,8 @@ files:
|
|
|
126
126
|
- lib/cpee/llm/functions.rb
|
|
127
127
|
- lib/cpee/llm/implementation.rb
|
|
128
128
|
- lib/cpee/llm/implementation.xml
|
|
129
|
-
- lib/cpee/llm/prompts/
|
|
129
|
+
- lib/cpee/llm/prompts/adapt_docxml_description.txt
|
|
130
|
+
- lib/cpee/llm/prompts/adapt_xml_endpoints.txt
|
|
130
131
|
- lib/cpee/llm/prompts/apply.txt
|
|
131
132
|
- lib/cpee/llm/prompts/dataflow.txt
|
|
132
133
|
- lib/cpee/llm/prompts/derive.txt
|
|
@@ -157,7 +158,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
157
158
|
requirements:
|
|
158
159
|
- - ">="
|
|
159
160
|
- !ruby/object:Gem::Version
|
|
160
|
-
version:
|
|
161
|
+
version: 3.2.0
|
|
161
162
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
163
|
requirements:
|
|
163
164
|
- - ">="
|
|
File without changes
|