llm_gateway 0.2.0 → 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/CHANGELOG.md +16 -0
- data/README.md +80 -2
- data/Rakefile +7 -1
- data/lib/llm_gateway/adapters/claude/bidirectional_message_mapper.rb +83 -0
- data/lib/llm_gateway/adapters/claude/client.rb +4 -0
- data/lib/llm_gateway/adapters/claude/input_mapper.rb +8 -7
- data/lib/llm_gateway/adapters/claude/output_mapper.rb +21 -1
- data/lib/llm_gateway/adapters/groq/bidirectional_message_mapper.rb +18 -0
- data/lib/llm_gateway/adapters/groq/input_mapper.rb +4 -91
- data/lib/llm_gateway/adapters/groq/output_mapper.rb +1 -53
- data/lib/llm_gateway/adapters/open_ai/chat_completions/bidirectional_message_mapper.rb +103 -0
- data/lib/llm_gateway/adapters/open_ai/chat_completions/input_mapper.rb +110 -0
- data/lib/llm_gateway/adapters/open_ai/chat_completions/output_mapper.rb +40 -0
- data/lib/llm_gateway/adapters/open_ai/client.rb +21 -0
- data/lib/llm_gateway/adapters/open_ai/file_output_mapper.rb +25 -0
- data/lib/llm_gateway/adapters/open_ai/responses/bidirectional_message_mapper.rb +72 -0
- data/lib/llm_gateway/adapters/open_ai/responses/input_mapper.rb +62 -0
- data/lib/llm_gateway/adapters/open_ai/responses/output_mapper.rb +47 -0
- data/lib/llm_gateway/base_client.rb +35 -0
- data/lib/llm_gateway/client.rb +111 -15
- data/lib/llm_gateway/errors.rb +2 -0
- data/lib/llm_gateway/version.rb +1 -1
- data/lib/llm_gateway.rb +11 -3
- metadata +11 -4
- data/lib/llm_gateway/adapters/open_ai/input_mapper.rb +0 -63
- data/lib/llm_gateway/adapters/open_ai/output_mapper.rb +0 -10
@@ -1,63 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "base64"
|
4
|
-
|
5
|
-
module LlmGateway
|
6
|
-
module Adapters
|
7
|
-
module OpenAi
|
8
|
-
class InputMapper < LlmGateway::Adapters::Groq::InputMapper
|
9
|
-
def self.map(data)
|
10
|
-
{
|
11
|
-
messages: map_messages(data[:messages]),
|
12
|
-
response_format: map_response_format(data[:response_format]),
|
13
|
-
tools: map_tools(data[:tools]),
|
14
|
-
system: map_system(data[:system])
|
15
|
-
}
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def self.map_messages(messages)
|
21
|
-
return messages unless messages
|
22
|
-
|
23
|
-
# First, handle file transformations
|
24
|
-
messages_with_files = messages.map do |msg|
|
25
|
-
if msg[:content].is_a?(Array)
|
26
|
-
content = msg[:content].map do |content|
|
27
|
-
if content[:type] == "file"
|
28
|
-
# Map text/plain to application/pdf for OpenAI
|
29
|
-
media_type = content[:media_type] == "text/plain" ? "application/pdf" : content[:media_type]
|
30
|
-
{
|
31
|
-
type: "file",
|
32
|
-
file: {
|
33
|
-
filename: content[:name],
|
34
|
-
file_data: "data:#{media_type};base64,#{Base64.encode64(content[:data])}"
|
35
|
-
}
|
36
|
-
}
|
37
|
-
else
|
38
|
-
content
|
39
|
-
end
|
40
|
-
end
|
41
|
-
msg.merge(content: content)
|
42
|
-
else
|
43
|
-
msg
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
# Then apply parent's tool transformation logic
|
48
|
-
super(messages_with_files)
|
49
|
-
end
|
50
|
-
|
51
|
-
def self.map_system(system)
|
52
|
-
if !system || system.empty?
|
53
|
-
[]
|
54
|
-
else
|
55
|
-
system.map do |msg|
|
56
|
-
msg[:role] == "system" ? msg.merge(role: "developer") : msg
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|