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

Allow overriding OpenAI compatible API endpoint #52

Merged
merged 2 commits into from
Dec 11, 2023
Merged
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
3 changes: 2 additions & 1 deletion lib/chat_models/chat_open_ai.ex
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ defmodule LangChain.ChatModels.ChatOpenAI do
| {:error, String.t()}

@create_fields [
:endpoint,
:model,
:temperature,
:frequency_penalty,
Expand All @@ -76,7 +77,7 @@ defmodule LangChain.ChatModels.ChatOpenAI do
:receive_timeout,
:json_response
]
@required_fields [:model]
@required_fields [:endpoint, :model]

@spec get_api_key(t) :: String.t()
defp get_api_key(%ChatOpenAI{api_key: api_key}) do
Expand Down
11 changes: 11 additions & 0 deletions test/chat_models/chat_open_ai_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ defmodule LangChain.ChatModels.ChatOpenAITest do
refute changeset.valid?
assert {"can't be blank", _} = changeset.errors[:model]
end

test "supports overriding the API endpoint" do
override_url = "http://localhost:1234/v1/chat/completions"

model =
ChatOpenAI.new!(%{
endpoint: override_url
})

assert model.endpoint == override_url
end
end

describe "for_api/3" do
Expand Down
Loading