Class: Async::Ollama::Wrapper

Inherits:
REST::Wrapper::Generic
  • Object
show all
Defined in:
lib/async/ollama/wrapper.rb

Defined Under Namespace

Classes: StreamingResponseParser

Constant Summary collapse

APPLICATION_JSON =
"application/json"
APPLICATION_JSON_STREAM =
"application/x-ndjson"

Instance Method Summary collapse

Instance Method Details

#parser_for(response) ⇒ Object



87
88
89
90
91
92
93
94
# File 'lib/async/ollama/wrapper.rb', line 87

def parser_for(response)
	case response.headers["content-type"]
	when APPLICATION_JSON
		return Async::REST::Wrapper::JSON::Parser
	when APPLICATION_JSON_STREAM
		return StreamingResponseParser
	end
end

#prepare_request(request, payload) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/async/ollama/wrapper.rb', line 20

def prepare_request(request, payload)
	request.headers.add("accept", APPLICATION_JSON)
	request.headers.add("accept", APPLICATION_JSON_STREAM)
	
	if payload
		request.headers["content-type"] = APPLICATION_JSON
		
		request.body = ::Protocol::HTTP::Body::Buffered.new([
			::JSON.dump(payload)
		])
	end
end