Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support OpenAI compatible providers through a base URL #6

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion docs/guides/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ RubyLLM.configure do |config|
end
```

You can optionally provide the base URL for the OpenAI API, through which you can point to OpenAI API compatible engines like [Ollama](https://github.com/ollama/ollama), [KoboldCPP](https://github.com/LostRuins/koboldcpp), [TabbyAPI](https://github.com/theroyallab/tabbyAPI), etc:

```ruby
config.openai_base_url = "http://localhost:11434/v1"
```

## Your First Chat

Let's start with a simple chat interaction:
Expand Down Expand Up @@ -161,4 +167,4 @@ Now that you've got the basics down, you're ready to explore more advanced featu

- [Chatting with AI]({% link guides/chat.md %}) - Learn more about chat capabilities
- [Using Tools]({% link guides/tools.md %}) - Let AI use your Ruby code
- [Rails Integration]({% link guides/rails.md %}) - Persist chats in your Rails apps
- [Rails Integration]({% link guides/rails.md %}) - Persist chats in your Rails apps
1 change: 1 addition & 0 deletions lib/ruby_llm/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module RubyLLM
# end
class Configuration
attr_accessor :openai_api_key,
:openai_base_url,
:anthropic_api_key,
:gemini_api_key,
:deepseek_api_key,
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_llm/providers/openai.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def self.extended(base)
module_function

def api_base
'https://api.openai.com/v1'
RubyLLM.config.openai_base_url || 'https://api.openai.com/v1'
end

def headers
Expand Down