You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/decisions/001X-python-client-constructors.md
+12-10Lines changed: 12 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,18 +22,19 @@ There is likely not a single best solution, the goal here is consistency across
22
22
- Make client creation inside our classes the default and cover as many backends as possible.
23
23
- Make clients easy to use and discover, so that users can easily find the right client for their use case.
24
24
- 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.
25
26
26
27
## Considered Options
27
28
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.
33
34
34
35
## Pros and Cons of the Options
35
36
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.
37
38
This option would entail potentially a large number of clients, and keeping track of additional backend implementation being created by vendors.
38
39
- Good, because it is clear which client is used
39
40
- 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
### 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.
58
59
This option would entail a single client that can be used with different backends, but requires the user to pass in the right parameters.
59
60
- Good, because it reduces the number of clients and makes it easier to discover the right client with the right parameters
60
61
- Good, because it allows for a single client to be used with different backends and additional backends can be added easily
61
62
- 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.
62
63
- Good, because in many cases, the differences between the backends are just a few parameters, such as endpoint/base_url and authentication method.
63
64
- 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.
64
66
- 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.
65
67
- Bad, because it can lead to confusion if the user passes in the wrong parameters for the specific backend
66
68
- 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(
81
83
)
82
84
```
83
85
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").
85
87
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.
86
88
- Same list as the option above, and:
87
89
- Good, because it is explicit about which backend to try and target, including for environment variables
@@ -103,7 +105,7 @@ azure_client = OpenAIClient(
103
105
)
104
106
```
105
107
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.
107
109
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.
108
110
- Good, because the entry point for a user is very clear
109
111
- Good, because it allows for customization of the client based on the parameters passed in
### 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.
132
134
This option would entail a mix of the above options, depending on the underlying SDK clients.
133
135
- Good, because it aligns with the underlying SDK clients and their capabilities
134
136
- Good, because it reduces the number of clients where possible
0 commit comments