Skip to content

Commit

Permalink
add optional bearer token
Browse files Browse the repository at this point in the history
  • Loading branch information
denys281 committed Jul 13, 2024
1 parent 9b3fb7a commit 6dd29d9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ GEM
uri (0.13.0)

PLATFORMS
arm64-darwin-23
x86_64-linux

DEPENDENCIES
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,17 @@ client = Ollama.new(
)
```

If your server protected with Bearer token, you could pass it in configs:

```ruby
require 'ollama-ai'

client = Ollama.new(
credentials: { address: 'http://localhost:11434', bearer_token: <your_token> },
options: { server_sent_events: true }
)
```

### Methods

```ruby
Expand Down
2 changes: 2 additions & 0 deletions controllers/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def initialize(config)
else
"#{config[:credentials][:address].to_s.sub(%r{/$}, '')}/"
end
@bearer_token = config[:credentials][:bearer_token]

@request_options = config.dig(:options, :connection, :request)

Expand Down Expand Up @@ -97,6 +98,7 @@ def request(path, payload = nil, server_sent_events: nil, request_method: 'POST'
response = Faraday.new(request: @request_options) do |faraday|
faraday.adapter @faraday_adapter
faraday.response :raise_error
faraday.request :authorization, 'Bearer', @bearer_token if @bearer_token
end.send(method_to_call) do |request|
request.url url
request.headers['Content-Type'] = 'application/json'
Expand Down
11 changes: 11 additions & 0 deletions template.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ client = Ollama.new(
)
```

If your server protected with Bearer token, you could pass it in configs:

```ruby
require 'ollama-ai'

client = Ollama.new(
credentials: { address: 'http://localhost:11434', bearer_token: <your_token> },
options: { server_sent_events: true }
)
```

### Methods

```ruby
Expand Down

0 comments on commit 6dd29d9

Please sign in to comment.