Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit fc8d128

Browse files
committed
more code removal
1 parent 56f54b5 commit fc8d128

File tree

3 files changed

+11
-28
lines changed

3 files changed

+11
-28
lines changed

lib/completions/endpoints/anthropic.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ def model_uri
6363
URI(llm_model.url)
6464
end
6565

66+
def xml_tools_enabled?
67+
!@native_tool_support
68+
end
69+
6670
def prepare_payload(prompt, model_params, dialect)
6771
@native_tool_support = dialect.native_tool_support?
6872

@@ -97,15 +101,15 @@ def decode_chunk(partial_data)
97101
end.compact
98102
end
99103

104+
def decode(response_data)
105+
processor.process_message(response_data)
106+
end
107+
100108
def processor
101109
@processor ||=
102110
DiscourseAi::Completions::AnthropicMessageProcessor.new(streaming_mode: @streaming_mode)
103111
end
104112

105-
def extract_completion_from(response_raw)
106-
processor.process_message(response_raw)
107-
end
108-
109113
def has_tool?(_response_data)
110114
processor.tool_calls.present?
111115
end
@@ -118,10 +122,6 @@ def final_log_update(log)
118122
log.request_tokens = processor.input_tokens if processor.input_tokens
119123
log.response_tokens = processor.output_tokens if processor.output_tokens
120124
end
121-
122-
def partials_from(decoded_chunk)
123-
decoded_chunk.split("\n").map { |line| line.split("data: ", 2)[1] }.compact
124-
end
125125
end
126126
end
127127
end

lib/completions/endpoints/aws_bedrock.rb

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -176,24 +176,13 @@ def processor
176176
DiscourseAi::Completions::AnthropicMessageProcessor.new(streaming_mode: @streaming_mode)
177177
end
178178

179-
def add_to_function_buffer(function_buffer, partial: nil, payload: nil)
180-
processor.to_xml_tool_calls(function_buffer) if !partial
181-
end
182-
183-
184179
def has_tool?(_response_data)
185180
processor.tool_calls.present?
186181
end
187182

188183
def xml_tools_enabled?
189184
!@native_tool_support
190185
end
191-
192-
def chunk_to_string(chunk)
193-
joined = +chunk.join("\n")
194-
joined << "\n" if joined.length > 0
195-
joined
196-
end
197186
end
198187
end
199188
end

lib/completions/endpoints/base.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ def perform_completion!(
123123

124124
if !@streaming_mode
125125
response_raw = response.read_body
126+
partials_raw = response_raw
126127
response_data = decode(response_raw)
127-
partials_raw = response_data.to_s
128128

129129
if xml_tool_processor
130130
processed = (xml_tool_processor << response_data)
@@ -143,9 +143,10 @@ def perform_completion!(
143143
end
144144
}
145145
response_data << xml_stripper.finish
146-
response_data.compact!
147146
end
148147

148+
response_data.reject!(&:blank?)
149+
149150
# this is to keep stuff backwards compatible
150151
response_data = response_data.first if response_data.length == 1
151152

@@ -264,13 +265,6 @@ def xml_tools_enabled?
264265
raise NotImplementedError
265266
end
266267

267-
def build_buffer
268-
Nokogiri::HTML5.fragment(<<~TEXT)
269-
<function_calls>
270-
#{noop_function_call_text}
271-
</function_calls>
272-
TEXT
273-
end
274268

275269
def self.noop_function_call_text
276270
(<<~TEXT).strip

0 commit comments

Comments
 (0)