Skip to content

Commit 3e4ca7c

Browse files
added numbering and clarification on breaking glass
1 parent 1d81d2d commit 3e4ca7c

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

docs/decisions/001X-python-client-constructors.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,19 @@ There is likely not a single best solution, the goal here is consistency across
2222
- Make client creation inside our classes the default and cover as many backends as possible.
2323
- Make clients easy to use and discover, so that users can easily find the right client for their use case.
2424
- Allow client creation based on environment variables, so that users can easily configure their clients without having to pass in parameters.
25+
- A breaking glass scenario should always be possible, so that users can pass in their own clients if needed, and it should also be easy to figure out how to do that.
2526

2627
## Considered Options
2728

28-
- Separate clients for each backend, such as OpenAI and Azure OpenAI, Anthropic and AnthropicBedrock, etc.
29-
- Separate parameter set per backend with a single client, such as OpenAIClient with parameters, for endpoint/base_url, api_key, and entra auth.
30-
- Single client with a explicit parameter for the backend to use, such as OpenAIClient(backend="azure") or AnthropicClient(backend="vertex").
31-
- Single client with a customized `__new__` method that can create the right client based on the parameters passed in, such as OpenAIClient(api_key="...", backend="azure") which returns a AzureOpenAIClient.
32-
- Map clients to underlying SDK clients, OpenAI's SDK client allows both OpenAI and Azure OpenAI, so would be a single client, while Anthropic's SDK has explicit clients for Bedrock and Vertex, so would be a separate client for AnthropicBedrock and AnthropicVertex.
29+
1. Separate clients for each backend, such as OpenAI and Azure OpenAI, Anthropic and AnthropicBedrock, etc.
30+
1. Separate parameter set per backend with a single client, such as OpenAIClient with parameters, for endpoint/base_url, api_key, and entra auth.
31+
1. Single client with a explicit parameter for the backend to use, such as OpenAIClient(backend="azure") or AnthropicClient(backend="vertex").
32+
1. Single client with a customized `__new__` method that can create the right client based on the parameters passed in, such as OpenAIClient(api_key="...", backend="azure") which returns a AzureOpenAIClient.
33+
1. Map clients to underlying SDK clients, OpenAI's SDK client allows both OpenAI and Azure OpenAI, so would be a single client, while Anthropic's SDK has explicit clients for Bedrock and Vertex, so would be a separate client for AnthropicBedrock and AnthropicVertex.
3334

3435
## Pros and Cons of the Options
3536

36-
### Separate clients for each backend, such as OpenAI and Azure OpenAI, Anthropic and AnthropicBedrock, etc.
37+
### 1. Separate clients for each backend, such as OpenAI and Azure OpenAI, Anthropic and AnthropicBedrock, etc.
3738
This option would entail potentially a large number of clients, and keeping track of additional backend implementation being created by vendors.
3839
- Good, because it is clear which client is used
3940
- Good, because we can easily have aliases of parameters, that are then mapped internally, such as `deployment_name` for Azure OpenAI mapping to `model_id` internally
@@ -54,13 +55,14 @@ openai_client = OpenAIClient(api_key="...")
5455
azure_client = AzureOpenAIClient(deployment_name="...", ad_token_provider=...)
5556
```
5657

57-
### Separate parameter set per backend with a single client, such as OpenAIClient with parameters, for endpoint/base_url, api_key, and entra auth.
58+
### 2. Separate parameter set per backend with a single client, such as OpenAIClient with parameters, for endpoint/base_url, api_key, and entra auth.
5859
This option would entail a single client that can be used with different backends, but requires the user to pass in the right parameters.
5960
- Good, because it reduces the number of clients and makes it easier to discover the right client with the right parameters
6061
- Good, because it allows for a single client to be used with different backends and additional backends can be added easily
6162
- Good, because the user does not have to worry about which client to use, they can just use the `OpenAIClient` or `AnthropicClient` and pass in the right parameters, and we create the right client for them, if that client changes, then we do that in the code, without any changes to the api.
6263
- Good, because in many cases, the differences between the backends are just a few parameters, such as endpoint/base_url and authentication method.
6364
- Good, because client resolution logic could be encapsulated in a factory method, making it easier to maintain and even extend by users.
65+
- Neutral, this would be a one-time breaking change for users of the existing clients, but would make it easier to use in the long run.
6466
- Bad, because it requires the user to know which parameters to pass in for the specific backend and when using environment variables, it is not always clear which parameters are used for which backend, or what the order of precedence is.
6567
- Bad, because it can lead to confusion if the user passes in the wrong parameters for the specific backend
6668
- Bad, because the name for a parameter that is similar but not the same between backends can be confusing, such as `deployment_name` for Azure OpenAI and `model_id` for OpenAI, would we then only have `model_id` for both, or have both parameters?
@@ -81,7 +83,7 @@ azure_client = OpenAIClient(
8183
)
8284
```
8385

84-
### Single client with a explicit parameter for the backend to use, such as OpenAIClient(backend="azure") or AnthropicClient(backend="vertex").
86+
### 3. Single client with a explicit parameter for the backend to use, such as OpenAIClient(backend="azure") or AnthropicClient(backend="vertex").
8587
This option would entail a single client that can be used with different backends, but requires the user to pass in the right backend as a parameter.
8688
- Same list as the option above, and:
8789
- Good, because it is explicit about which backend to try and target, including for environment variables
@@ -103,7 +105,7 @@ azure_client = OpenAIClient(
103105
)
104106
```
105107

106-
### Single client with a customized `__new__` method that can create the right client based on the parameters passed in, such as OpenAIClient(backend="azure") which returns a AzureOpenAIClient.
108+
### 4. Single client with a customized `__new__` method that can create the right client based on the parameters passed in, such as OpenAIClient(backend="azure") which returns a AzureOpenAIClient.
107109
This option would entail a single client that can be used with different backends, and the right client is created based on the parameters passed in.
108110
- Good, because the entry point for a user is very clear
109111
- Good, because it allows for customization of the client based on the parameters passed in
@@ -128,7 +130,7 @@ print(type(openai_client)) # OpenAIClient
128130
print(type(azure_client)) # AzureOpenAIClient
129131
```
130132

131-
### Map clients to underlying SDK clients, OpenAI's SDK client allows both OpenAI and Azure OpenAI, so would be a single client, while Anthropic's SDK has explicit clients for Bedrock and Vertex, so would be a separate client for AnthropicBedrock and AnthropicVertex.
133+
### 5. Map clients to underlying SDK clients, OpenAI's SDK client allows both OpenAI and Azure OpenAI, so would be a single client, while Anthropic's SDK has explicit clients for Bedrock and Vertex, so would be a separate client for AnthropicBedrock and AnthropicVertex.
132134
This option would entail a mix of the above options, depending on the underlying SDK clients.
133135
- Good, because it aligns with the underlying SDK clients and their capabilities
134136
- Good, because it reduces the number of clients where possible

0 commit comments

Comments
 (0)