lammy 0.2.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lammy/chat.rb +10 -7
- data/lib/lammy/embeddings.rb +2 -2
- data/lib/lammy/openai.rb +11 -3
- data/lib/lammy.rb +1 -0
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bab0a835c9ce12e44b4c5f0d4252eb3040e0d5cb3336aeefe24856f59a74a2a9
|
4
|
+
data.tar.gz: a627a3d18b19a86785a1c70d95304b5bc8ab820766faf15f7893a79d563aeb44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0cd66977d719fb4bf752b96c9d5fcaeb1d776fda9d3f929366b4ac41a9913f2e16de6cb1454f0116214f1a7b404b815506f3e0375ac781f5ef2304aa01e54b6c
|
7
|
+
data.tar.gz: 8c39fea57e23ce2c39a926b039c01e132482237a5c9e6af4fd1bd9de20b884845f05930be747a202f5a3982fe22bbf2f3e308f9f605d934c9897b57b095c72c0
|
data/lib/lammy/chat.rb
CHANGED
@@ -26,13 +26,16 @@ module L
|
|
26
26
|
# Call the original method to get the user message
|
27
27
|
user_message = original_method.bind(self).call(*args, &block)
|
28
28
|
|
29
|
-
case settings[:model]
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
29
|
+
client = case settings[:model]
|
30
|
+
when *OpenAI::MODELS
|
31
|
+
OpenAI.new(settings)
|
32
|
+
when *Claude::MODELS
|
33
|
+
Claude.new(settings)
|
34
|
+
else
|
35
|
+
raise "Unsupported model: #{settings[:model]}"
|
36
|
+
end
|
37
|
+
|
38
|
+
client.chat(user_message, @system_message)
|
36
39
|
end
|
37
40
|
end
|
38
41
|
end
|
data/lib/lammy/embeddings.rb
CHANGED
data/lib/lammy/openai.rb
CHANGED
@@ -4,7 +4,7 @@ require 'openai'
|
|
4
4
|
require 'hashie'
|
5
5
|
|
6
6
|
module L
|
7
|
-
# Use the OpenAI API's
|
7
|
+
# Use the OpenAI API's Ruby library
|
8
8
|
class OpenAI
|
9
9
|
MODELS = %w[
|
10
10
|
gpt-4o-mini gpt-4o gpt-4-turbo gpt-4 gpt-3.5-turbo gpt-4o-mini-2024-07-18 gpt-4o-2024-08-06
|
@@ -15,8 +15,14 @@ module L
|
|
15
15
|
text-embedding-3-small text-embedding-3-large text-embedding-ada-002
|
16
16
|
].freeze
|
17
17
|
|
18
|
+
attr_reader :settings
|
19
|
+
|
20
|
+
def initialize(settings)
|
21
|
+
@settings = settings
|
22
|
+
end
|
23
|
+
|
18
24
|
# Generate a response with support for structured output
|
19
|
-
def chat(
|
25
|
+
def chat(user_message, system_message = nil)
|
20
26
|
schema = schema(settings)
|
21
27
|
response = client.chat(
|
22
28
|
parameters: {
|
@@ -34,7 +40,7 @@ module L
|
|
34
40
|
# OpenAI’s text embeddings measure the relatedness of text strings. An embedding is a vector of floating point
|
35
41
|
# numbers. The distance between two vectors measures their relatedness. Small distances suggest high relatedness
|
36
42
|
# and large distances suggest low relatedness.
|
37
|
-
def embeddings(
|
43
|
+
def embeddings(chunks)
|
38
44
|
responses = chunks.map do |chunk|
|
39
45
|
response = client.embeddings(
|
40
46
|
parameters: { model: settings[:model], dimensions: settings[:dimensions], input: chunk }
|
@@ -65,6 +71,8 @@ module L
|
|
65
71
|
end
|
66
72
|
|
67
73
|
def client
|
74
|
+
return settings[:client] if settings[:client]
|
75
|
+
|
68
76
|
@client ||= ::OpenAI::Client.new(
|
69
77
|
access_token: ENV.fetch('OPENAI_ACCESS_TOKEN')
|
70
78
|
)
|
data/lib/lammy.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lammy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kamil Nicieja
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: anthropic
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.3'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: hashie
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -61,7 +75,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
61
75
|
requirements:
|
62
76
|
- - ">="
|
63
77
|
- !ruby/object:Gem::Version
|
64
|
-
version:
|
78
|
+
version: 2.6.0
|
65
79
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
80
|
requirements:
|
67
81
|
- - ">="
|