Async::OllamaSourceAsyncOllamaWrapper

class Wrapper

Wraps HTTP requests and responses for the Ollama API, handling content negotiation and parsing.

Definitions

def prepare_request(request, payload)

Prepares the HTTP request with appropriate headers and body.

Signature

parameter request Protocol::HTTP::Request

The HTTP request object.

parameter payload Protocol::HTTP::Response

The request payload.

Implementation

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

def parser_for(response)

Selects the appropriate parser for the HTTP response.

Signature

parameter response Protocol::HTTP::Response

The HTTP response object.

returns Class

The parser class to use.

Implementation

def parser_for(response)
	content_type = response.headers["content-type"]
	media_type = content_type.split(";").first
	
	case media_type
	when APPLICATION_JSON
		return Async::REST::Wrapper::JSON::Parser
	when APPLICATION_JSON_STREAM
		return StreamingParser
	end
end