cpee-llm-dnames 1.0.0 → 1.0.1
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-dnames.gemspec +1 -1
- data/lib/cpee-llm-dnames/implementation.rb +13 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 03df16ecab38449902db8b640f9b818eb1910928263f479f7f240caedbfb9026
|
|
4
|
+
data.tar.gz: f551b094265d28eb2aad140d46db3de952f532ce37ce3f3fc9a801150ef367d5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fb2727cd6d9a89fb1d717f3b69abe75162fa9826e4a4b2f27c520fbe0a91c6c38612ef52f5a88dc245419c79f4c56ac59b4905abb1105554392455b683a73e7d
|
|
7
|
+
data.tar.gz: 309feafb1f1f5fc971c9b7d38cfffd05f5f6b2bee095ccb46182320a734f583990623bccdb9935008bf8c4cdc8206716844c74ef578387215c2b1b4d6e42cab5
|
data/cpee-llm-dnames.gemspec
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Gem::Specification.new do |s|
|
|
2
2
|
s.name = "cpee-llm-dnames"
|
|
3
|
-
s.version = "1.0.
|
|
3
|
+
s.version = "1.0.1"
|
|
4
4
|
s.platform = Gem::Platform::RUBY
|
|
5
5
|
s.license = "GPL-3.0-or-later"
|
|
6
6
|
s.summary = "LLM document processing service for the cloud process execution engine (cpee.org)"
|
|
@@ -24,8 +24,15 @@ module CPEE
|
|
|
24
24
|
module LLM
|
|
25
25
|
module Dnames
|
|
26
26
|
SERVER = File.expand_path(File.join(__dir__,'implementation.xml'))
|
|
27
|
+
USED_TOKENS_HEADER = 'CPEE-LLM-Used-Tokens'
|
|
27
28
|
|
|
28
29
|
class FindDocuments < Riddl::Implementation #{{{
|
|
30
|
+
def used_tokens(tokens)
|
|
31
|
+
t = Array(tokens).first.to_s
|
|
32
|
+
@headers << Riddl::Header.new(USED_TOKENS_HEADER, "input=#{t[/input=(\d+)/,1].to_i}, output=#{t[/output=(\d+)/,1].to_i}")
|
|
33
|
+
@headers << Riddl::Header.new('Access-Control-Expose-Headers', USED_TOKENS_HEADER)
|
|
34
|
+
end
|
|
35
|
+
|
|
29
36
|
SYSTEM_PROMPT = <<~PROMPT #{{{
|
|
30
37
|
You resolve references to documents inside free-form process instructions.
|
|
31
38
|
|
|
@@ -55,16 +62,20 @@ module CPEE
|
|
|
55
62
|
documents_raw = @p.find { |p| p.name == 'documents' }.value.read
|
|
56
63
|
documents = JSON.parse(documents_raw)
|
|
57
64
|
|
|
58
|
-
|
|
65
|
+
if documents.empty?
|
|
66
|
+
used_tokens('input=0, output=0')
|
|
67
|
+
return Riddl::Parameter::Complex.new('response', 'text/plain', user_input)
|
|
68
|
+
end
|
|
59
69
|
|
|
60
70
|
system_prompt = "#{SYSTEM_PROMPT}\nKnown documents:\n#{documents_raw}"
|
|
61
71
|
|
|
62
|
-
status, res = Riddl::Client.new(@a[0][:generic_endpoint]).post([
|
|
72
|
+
status, res, rheaders = Riddl::Client.new(@a[0][:generic_endpoint]).post([
|
|
63
73
|
Riddl::Parameter::Complex.new('llm', 'text/plain', llm),
|
|
64
74
|
Riddl::Parameter::Complex.new('user_input', 'text/plain', user_input),
|
|
65
75
|
Riddl::Parameter::Complex.new('system_prompt', 'text/plain', system_prompt),
|
|
66
76
|
Riddl::Parameter::Complex.new('format', 'text/plain', 'false')
|
|
67
77
|
])
|
|
78
|
+
used_tokens((rheaders || {})['CPEE_LLM_USED_TOKENS'])
|
|
68
79
|
|
|
69
80
|
raw = res.first.value
|
|
70
81
|
raw = raw.read if raw.respond_to?(:read)
|