llm.rb 0.2.1 → 0.3.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 +4 -4
- data/README.md +264 -110
- data/lib/llm/buffer.rb +83 -0
- data/lib/llm/chat.rb +131 -0
- data/lib/llm/file.rb +26 -40
- data/lib/llm/http_client.rb +10 -5
- data/lib/llm/message.rb +14 -8
- data/lib/llm/mime.rb +54 -0
- data/lib/llm/multipart.rb +98 -0
- data/lib/llm/provider.rb +96 -19
- data/lib/llm/providers/anthropic/error_handler.rb +2 -0
- data/lib/llm/providers/anthropic/format.rb +2 -0
- data/lib/llm/providers/anthropic/response_parser.rb +3 -1
- data/lib/llm/providers/anthropic.rb +14 -5
- data/lib/llm/providers/gemini/audio.rb +77 -0
- data/lib/llm/providers/gemini/error_handler.rb +2 -0
- data/lib/llm/providers/gemini/files.rb +160 -0
- data/lib/llm/providers/gemini/format.rb +12 -6
- data/lib/llm/providers/gemini/images.rb +99 -0
- data/lib/llm/providers/gemini/response_parser.rb +27 -1
- data/lib/llm/providers/gemini.rb +62 -6
- data/lib/llm/providers/ollama/error_handler.rb +2 -0
- data/lib/llm/providers/ollama/format.rb +13 -5
- data/lib/llm/providers/ollama/response_parser.rb +3 -1
- data/lib/llm/providers/ollama.rb +30 -7
- data/lib/llm/providers/openai/audio.rb +97 -0
- data/lib/llm/providers/openai/error_handler.rb +2 -0
- data/lib/llm/providers/openai/files.rb +148 -0
- data/lib/llm/providers/openai/format.rb +21 -8
- data/lib/llm/providers/openai/images.rb +109 -0
- data/lib/llm/providers/openai/response_parser.rb +58 -5
- data/lib/llm/providers/openai/responses.rb +78 -0
- data/lib/llm/providers/openai.rb +52 -6
- data/lib/llm/providers/voyageai.rb +2 -2
- data/lib/llm/response/audio.rb +13 -0
- data/lib/llm/response/audio_transcription.rb +14 -0
- data/lib/llm/response/audio_translation.rb +14 -0
- data/lib/llm/response/download_file.rb +15 -0
- data/lib/llm/response/file.rb +42 -0
- data/lib/llm/response/filelist.rb +18 -0
- data/lib/llm/response/image.rb +29 -0
- data/lib/llm/response/output.rb +56 -0
- data/lib/llm/response.rb +18 -6
- data/lib/llm/utils.rb +19 -0
- data/lib/llm/version.rb +1 -1
- data/lib/llm.rb +5 -2
- data/llm.gemspec +1 -6
- data/spec/anthropic/completion_spec.rb +1 -1
- data/spec/gemini/completion_spec.rb +1 -1
- data/spec/gemini/conversation_spec.rb +31 -0
- data/spec/gemini/files_spec.rb +124 -0
- data/spec/gemini/images_spec.rb +47 -0
- data/spec/llm/conversation_spec.rb +101 -61
- data/spec/ollama/completion_spec.rb +1 -1
- data/spec/ollama/conversation_spec.rb +31 -0
- data/spec/openai/audio_spec.rb +55 -0
- data/spec/openai/completion_spec.rb +1 -1
- data/spec/openai/files_spec.rb +150 -0
- data/spec/openai/images_spec.rb +95 -0
- data/spec/openai/responses_spec.rb +51 -0
- data/spec/setup.rb +8 -0
- metadata +31 -49
- data/LICENSE.txt +0 -21
- data/lib/llm/conversation.rb +0 -90
- data/lib/llm/message_queue.rb +0 -54
data/lib/llm/message_queue.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module LLM
|
4
|
-
##
|
5
|
-
# {LLM::MessageQueue LLM::MessageQueue} provides an Enumerable
|
6
|
-
# object that yields each message in a conversation on-demand,
|
7
|
-
# and only sends a request to the LLM when a response is needed.
|
8
|
-
class MessageQueue
|
9
|
-
include Enumerable
|
10
|
-
|
11
|
-
##
|
12
|
-
# @param [LLM::Provider] provider
|
13
|
-
# @return [LLM::MessageQueue]
|
14
|
-
def initialize(provider)
|
15
|
-
@provider = provider
|
16
|
-
@pending = []
|
17
|
-
@completed = []
|
18
|
-
end
|
19
|
-
|
20
|
-
##
|
21
|
-
# @yield [LLM::Message]
|
22
|
-
# Yields each message in the conversation thread
|
23
|
-
# @raise (see LLM::Provider#complete)
|
24
|
-
# @return [void]
|
25
|
-
def each
|
26
|
-
complete! unless @pending.empty?
|
27
|
-
@completed.each { yield(_1) }
|
28
|
-
end
|
29
|
-
|
30
|
-
##
|
31
|
-
# @param [[LLM::Message, Hash]] item
|
32
|
-
# A message and its parameters
|
33
|
-
# @return [void]
|
34
|
-
def <<(item)
|
35
|
-
@pending << item
|
36
|
-
self
|
37
|
-
end
|
38
|
-
alias_method :push, :<<
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
def complete!
|
43
|
-
message, params = @pending[-1]
|
44
|
-
messages = @pending[0..-2].map { _1[0] }
|
45
|
-
completion = @provider.complete(
|
46
|
-
message.content,
|
47
|
-
message.role,
|
48
|
-
**params.merge(messages:)
|
49
|
-
)
|
50
|
-
@completed.concat([*messages, message, completion.choices[0]])
|
51
|
-
@pending.clear
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|