lex-pilot-knowledge-assist 0.1.0
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
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 91485d59b7e75c54a9286e9d00980805194dd57211a7773a3dba1dbbcac1dcce
|
|
4
|
+
data.tar.gz: e37c2062983e8884623cbce58a2a7ba706349c8fcd37501f7a4e039a13d0c109
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 74ad9e20db90b0e32ce186b50a3f271284ab3115ebe2b9ef5b6d5d41c8b233bc6c3c178cdeac4031e593d3238fd607fd104f5913ed547df3ffd2b2dce526a928
|
|
7
|
+
data.tar.gz: 84046dbe69849dabe06e924534a72fd115a1438b3d2953daa231cd3b1d7c41992be93ae20c0916086a07c6d5185484581e48f6e12c22c7a127fb1f87e617cc4a
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module PilotKnowledgeAssist
|
|
6
|
+
module Runners
|
|
7
|
+
module Assistant
|
|
8
|
+
def answer_question(question:, agent_id: 'knowledge-assist')
|
|
9
|
+
context = retrieve_context(question, agent_id)
|
|
10
|
+
answer = generate_answer(question, context)
|
|
11
|
+
|
|
12
|
+
{
|
|
13
|
+
question: question,
|
|
14
|
+
answer: answer,
|
|
15
|
+
sources: context.map { |c| c[:id] },
|
|
16
|
+
confidence: context.any? ? 0.8 : 0.3
|
|
17
|
+
}
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def retrieve_context(question, agent_id)
|
|
23
|
+
return [] unless defined?(Legion::Extensions::Apollo::Client)
|
|
24
|
+
|
|
25
|
+
client = Legion::Extensions::Apollo::Client.new(agent_id: agent_id)
|
|
26
|
+
client.query_knowledge(query: question, limit: 5)
|
|
27
|
+
rescue StandardError
|
|
28
|
+
[]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def generate_answer(question, context)
|
|
32
|
+
return 'LLM unavailable' unless defined?(Legion::LLM)
|
|
33
|
+
|
|
34
|
+
context_text = context.map { |c| c[:content] }.join("\n\n")
|
|
35
|
+
prompt = if context_text.empty?
|
|
36
|
+
question
|
|
37
|
+
else
|
|
38
|
+
"Context:\n#{context_text}\n\nQuestion: #{question}"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
result = Legion::LLM.chat(message: prompt)
|
|
42
|
+
result[:content]
|
|
43
|
+
rescue StandardError => e
|
|
44
|
+
"Error: #{e.message}"
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: lex-pilot-knowledge-assist
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Esity
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
description: RAG-based knowledge assistant using Apollo and LLM for LegionIO
|
|
13
|
+
email:
|
|
14
|
+
- matthewdiverson@gmail.com
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/legion/extensions/pilot_knowledge_assist.rb
|
|
20
|
+
- lib/legion/extensions/pilot_knowledge_assist/runners/assistant.rb
|
|
21
|
+
- lib/legion/extensions/pilot_knowledge_assist/version.rb
|
|
22
|
+
homepage: https://github.com/LegionIO
|
|
23
|
+
licenses:
|
|
24
|
+
- MIT
|
|
25
|
+
metadata:
|
|
26
|
+
rubygems_mfa_required: 'true'
|
|
27
|
+
rdoc_options: []
|
|
28
|
+
require_paths:
|
|
29
|
+
- lib
|
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
31
|
+
requirements:
|
|
32
|
+
- - ">="
|
|
33
|
+
- !ruby/object:Gem::Version
|
|
34
|
+
version: '3.4'
|
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
40
|
+
requirements: []
|
|
41
|
+
rubygems_version: 3.6.9
|
|
42
|
+
specification_version: 4
|
|
43
|
+
summary: LEX::PilotKnowledgeAssist
|
|
44
|
+
test_files: []
|