forked from github/copilot-sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProviderConfig.java
More file actions
198 lines (177 loc) · 4.86 KB
/
ProviderConfig.java
File metadata and controls
198 lines (177 loc) · 4.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
package com.github.copilot.sdk.json;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* Configuration for a custom API provider (BYOK - Bring Your Own Key).
* <p>
* This allows using your own OpenAI, Azure OpenAI, or other compatible API
* endpoints instead of the default Copilot backend. All setter methods return
* {@code this} for method chaining.
*
* <h2>Example Usage - OpenAI</h2>
*
* <pre>{@code
* var provider = new ProviderConfig().setType("openai").setBaseUrl("https://api.openai.com/v1").setApiKey("sk-...");
* }</pre>
*
* <h2>Example Usage - Azure OpenAI</h2>
*
* <pre>{@code
* var provider = new ProviderConfig().setType("azure")
* .setAzure(new AzureOptions().setEndpoint("https://my-resource.openai.azure.com").setDeployment("gpt-4"));
* }</pre>
*
* @see SessionConfig#setProvider(ProviderConfig)
* @since 1.0.0
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ProviderConfig {
@JsonProperty("type")
private String type;
@JsonProperty("wireApi")
private String wireApi;
@JsonProperty("baseUrl")
private String baseUrl;
@JsonProperty("apiKey")
private String apiKey;
@JsonProperty("bearerToken")
private String bearerToken;
@JsonProperty("azure")
private AzureOptions azure;
/**
* Gets the provider type.
*
* @return the provider type (e.g., "openai", "azure")
*/
public String getType() {
return type;
}
/**
* Sets the provider type.
* <p>
* Supported types include:
* <ul>
* <li>"openai" - OpenAI API</li>
* <li>"azure" - Azure OpenAI Service</li>
* </ul>
*
* @param type
* the provider type
* @return this config for method chaining
*/
public ProviderConfig setType(String type) {
this.type = type;
return this;
}
/**
* Gets the wire API format.
*
* @return the wire API format
*/
public String getWireApi() {
return wireApi;
}
/**
* Sets the wire API format for custom providers.
* <p>
* This specifies the API format when using a custom provider that has a
* different wire protocol.
*
* @param wireApi
* the wire API format
* @return this config for method chaining
*/
public ProviderConfig setWireApi(String wireApi) {
this.wireApi = wireApi;
return this;
}
/**
* Gets the base URL for the API.
*
* @return the API base URL
*/
public String getBaseUrl() {
return baseUrl;
}
/**
* Sets the base URL for the API.
* <p>
* For OpenAI, this is typically "https://api.openai.com/v1".
*
* @param baseUrl
* the API base URL
* @return this config for method chaining
*/
public ProviderConfig setBaseUrl(String baseUrl) {
this.baseUrl = baseUrl;
return this;
}
/**
* Gets the API key.
*
* @return the API key
*/
public String getApiKey() {
return apiKey;
}
/**
* Sets the API key for authentication.
*
* @param apiKey
* the API key
* @return this config for method chaining
*/
public ProviderConfig setApiKey(String apiKey) {
this.apiKey = apiKey;
return this;
}
/**
* Gets the bearer token.
*
* @return the bearer token
*/
public String getBearerToken() {
return bearerToken;
}
/**
* Sets a bearer token for authentication.
* <p>
* This is an alternative to API key authentication.
* <p>
* <strong>Note:</strong> The bearer token is a <strong>static token
* string</strong>. The SDK does not refresh this token automatically. If your
* token expires, requests will fail and you'll need to create a new session
* with a fresh token.
*
* @param bearerToken
* the bearer token
* @return this config for method chaining
*/
public ProviderConfig setBearerToken(String bearerToken) {
this.bearerToken = bearerToken;
return this;
}
/**
* Gets the Azure-specific options.
*
* @return the Azure options
*/
public AzureOptions getAzure() {
return azure;
}
/**
* Sets Azure-specific options for Azure OpenAI Service.
*
* @param azure
* the Azure options
* @return this config for method chaining
* @see AzureOptions
*/
public ProviderConfig setAzure(AzureOptions azure) {
this.azure = azure;
return this;
}
}