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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 71622b65b27e1fb702326b0a76a42eebf8fb75d1bd5e4b0444762e74053ca3f4
4
- data.tar.gz: 0bbc546a09e89ebf82b0e4bab19628239f2c0eca6c1189a42039781e27625c60
3
+ metadata.gz: 03df16ecab38449902db8b640f9b818eb1910928263f479f7f240caedbfb9026
4
+ data.tar.gz: f551b094265d28eb2aad140d46db3de952f532ce37ce3f3fc9a801150ef367d5
5
5
  SHA512:
6
- metadata.gz: 5c1d778170f4886135e7392dee43ff3bf7079232d421e141f98796480a65076acac8217319df0fdb32bcbb78b2f50e00fc50b09e1fa62b1a2d8e9c26593a6d44
7
- data.tar.gz: d17ebd04b24fa689dbb26d08935da624a064a814a67b39868c35de0fc575a8cb6bf855f483af3a975ad12b3a253e150e7ea175ab325af320e09ee340c786e45f
6
+ metadata.gz: fb2727cd6d9a89fb1d717f3b69abe75162fa9826e4a4b2f27c520fbe0a91c6c38612ef52f5a88dc245419c79f4c56ac59b4905abb1105554392455b683a73e7d
7
+ data.tar.gz: 309feafb1f1f5fc971c9b7d38cfffd05f5f6b2bee095ccb46182320a734f583990623bccdb9935008bf8c4cdc8206716844c74ef578387215c2b1b4d6e42cab5
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cpee-llm-dnames"
3
- s.version = "1.0.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
- return Riddl::Parameter::Complex.new('response', 'text/plain', user_input) if documents.empty?
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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cpee-llm-dnames
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juergen eTM Mangler