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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0992b774797e59eeae152cacb65110b83cec70002e6afb7a40153ae05f942490'
4
- data.tar.gz: d2680e0acfc73a28f89e5468a9d4292cd2a4bc9573a5570b9c40b86e3ffa8a14
3
+ metadata.gz: bab0a835c9ce12e44b4c5f0d4252eb3040e0d5cb3336aeefe24856f59a74a2a9
4
+ data.tar.gz: a627a3d18b19a86785a1c70d95304b5bc8ab820766faf15f7893a79d563aeb44
5
5
  SHA512:
6
- metadata.gz: ee429f696a2dfcf9f79582db94bdf696c6b4900f903880daddc48d32d9ea13c60a76138b2e47dc47d9c9efb9ed94196af1221827fbcd3c0b9e5b2384d74b2611
7
- data.tar.gz: d44d1b6161a805fce9f5da44ac481b909c1edfccd50eb74a61c3498e55642da5782637b1105c07408594de46b1162f5ac7004bdca6bc03caccac4ac48f190f28
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
- when *OpenAI::MODELS
31
- client = OpenAI.new
32
- client.chat(settings, user_message, @system_message)
33
- else
34
- raise "Unsupported model: #{settings[:model]}"
35
- end
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
@@ -37,8 +37,8 @@ module L
37
37
 
38
38
  case settings[:model]
39
39
  when *OpenAI::EMBEDDINGS
40
- client = OpenAI.new
41
- client.embeddings(settings, input)
40
+ client = OpenAI.new(settings)
41
+ client.embeddings(input)
42
42
  else
43
43
  raise "Unsupported model: #{settings[:model]}"
44
44
  end
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 official Ruby library
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(settings, user_message, system_message = nil)
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(settings, chunks)
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
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'lammy/embeddings'
4
+ require 'lammy/claude'
4
5
  require 'lammy/openai'
5
6
  require 'lammy/schema'
6
7
  require 'lammy/chat'
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.2.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-01 00:00:00.000000000 Z
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: '0'
78
+ version: 2.6.0
65
79
  required_rubygems_version: !ruby/object:Gem::Requirement
66
80
  requirements:
67
81
  - - ">="