Class: HermesAgent::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/hermes_agent/client.rb,
lib/hermes_agent/client/util.rb,
lib/hermes_agent/client/entity.rb,
lib/hermes_agent/client/errors.rb,
lib/hermes_agent/client/stream.rb,
lib/hermes_agent/client/version.rb,
lib/hermes_agent/client/transport.rb,
lib/hermes_agent/client/conversation.rb,
lib/hermes_agent/client/entities/job.rb,
lib/hermes_agent/client/entities/run.rb,
lib/hermes_agent/client/configuration.rb,
lib/hermes_agent/client/entities/model.rb,
lib/hermes_agent/client/resources/chat.rb,
lib/hermes_agent/client/resources/jobs.rb,
lib/hermes_agent/client/resources/runs.rb,
lib/hermes_agent/client/entities/health.rb,
lib/hermes_agent/client/resources/health.rb,
lib/hermes_agent/client/resources/models.rb,
lib/hermes_agent/client/entities/response.rb,
lib/hermes_agent/client/resources/responses.rb,
lib/hermes_agent/client/entities/capabilities.rb,
lib/hermes_agent/client/resources/capabilities.rb,
lib/hermes_agent/client/entities/chat_completion.rb,
lib/hermes_agent/client/entities/session_headers.rb

Overview

A client for the Hermes API server.

Construct a client with the server location and credentials, then reach endpoints through resource accessors such as #health.

client = HermesAgent::Client.new(base_url: "http://127.0.0.1:8642")
client.health.check.status  # => "ok"

Note this class is not thread-safe. When using in a multithreaded application, you should create a separate client object per thread.

Defined Under Namespace

Modules: Entities, Resources Classes: APIError, AuthenticationError, BadRequestError, Configuration, ConnectionError, Conversation, Entity, Error, MalformedResponseError, NotFoundError, PermissionError, RateLimitError, ServerError, Stream, TimeoutError

Constant Summary collapse

VERSION =

Version of the hermes-client gem

Returns:

  • (String)
"0.1.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url: Configuration::DEFAULT_BASE_URL, api_key: UNSET, read_timeout: nil, open_timeout: nil, write_timeout: nil, keep_alive_timeout: Configuration::DEFAULT_KEEP_ALIVE_TIMEOUT) {|config| ... } ⇒ Client

Create a client.

Settings may be supplied as keyword arguments, by yielding the Configuration to a block, or both (the block runs after the keyword arguments are applied).

Parameters:

  • base_url (String) (defaults to: Configuration::DEFAULT_BASE_URL)

    The server root URL. See Configuration.

  • api_key (String, nil) (defaults to: UNSET)

    The bearer token. When omitted, defaults to the HERMES_API_KEY environment variable (see Configuration); pass nil explicitly to send no Authorization header regardless.

  • read_timeout (Numeric, nil) (defaults to: nil)

    The read timeout in seconds.

  • open_timeout (Numeric, nil) (defaults to: nil)

    The connection-open timeout in seconds.

  • write_timeout (Numeric, nil) (defaults to: nil)

    The request-write timeout in seconds.

  • keep_alive_timeout (Numeric) (defaults to: Configuration::DEFAULT_KEEP_ALIVE_TIMEOUT)

    How long an idle persistent connection may be reused before being reopened. See Configuration.

Yield Parameters:

  • config (Configuration)

    The configuration, for customization.



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/hermes_agent/client.rb', line 58

def initialize(base_url: Configuration::DEFAULT_BASE_URL,
               api_key: UNSET,
               read_timeout: nil,
               open_timeout: nil,
               write_timeout: nil,
               keep_alive_timeout: Configuration::DEFAULT_KEEP_ALIVE_TIMEOUT)
  @config = Configuration.new(base_url: base_url, read_timeout: read_timeout,
                              open_timeout: open_timeout, write_timeout: write_timeout,
                              keep_alive_timeout: keep_alive_timeout)
  @config.api_key = api_key unless api_key.equal?(UNSET)
  yield @config if block_given?
  @transport = Transport.new(@config)
end

Instance Attribute Details

#configConfiguration (readonly)

The configuration this client was built with.

Returns:



76
77
78
# File 'lib/hermes_agent/client.rb', line 76

def config
  @config
end

Instance Method Details

#capabilitiesResources::Capabilities

The capabilities resource (the server's advertised endpoints and feature matrix).



83
84
85
# File 'lib/hermes_agent/client.rb', line 83

def capabilities
  @capabilities ||= Resources::Capabilities.new(@transport)
end

#chatResources::Chat

The chat resource (OpenAI-compatible chat completions).

Returns:



91
92
93
# File 'lib/hermes_agent/client.rb', line 91

def chat
  @chat ||= Resources::Chat.new(@transport)
end

#healthResources::Health

The health resource (server health checks).

Returns:



99
100
101
# File 'lib/hermes_agent/client.rb', line 99

def health
  @health ||= Resources::Health.new(@transport)
end

#jobsResources::Jobs

The jobs resource (the Jobs API, for scheduled background work).

Returns:



107
108
109
# File 'lib/hermes_agent/client.rb', line 107

def jobs
  @jobs ||= Resources::Jobs.new(@transport)
end

#modelsResources::Models

The models resource (discovery of advertised models).

Returns:



115
116
117
# File 'lib/hermes_agent/client.rb', line 115

def models
  @models ||= Resources::Models.new(@transport)
end

#responsesResources::Responses

The responses resource (the Responses API, with server-side conversation state).



124
125
126
# File 'lib/hermes_agent/client.rb', line 124

def responses
  @responses ||= Resources::Responses.new(@transport)
end

#runsResources::Runs

The runs resource (the Runs API, for long-running server-side agent runs).

Returns:



133
134
135
# File 'lib/hermes_agent/client.rb', line 133

def runs
  @runs ||= Resources::Runs.new(@transport)
end