@@ -16,69 +16,32 @@ namespace Azure.AI.OpenAI
1616 /// <summary> Azure OpenAI APIs for completions and search. </summary>
1717 public partial class OpenAIClient
1818 {
19- private readonly string _completionsDeploymentId ;
20- private readonly string _embeddingsDeploymentId ;
21-
22- /// <summary> Initializes a new instance of OpenAIClient. </summary>
23- /// <param name="endpoint">
24- /// Supported Cognitive Services endpoints (protocol and hostname, for example:
25- /// https://westus.api.cognitive.microsoft.com).
26- /// </param>
27- /// <param name="deploymentId"> default deployment id to use for operations </param>
28- /// <param name="credential"> A credential used to authenticate to an Azure Service. </param>
29- /// <exception cref="ArgumentNullException"> <paramref name="endpoint"/> or <paramref name="credential"/> is null. </exception>
30- public OpenAIClient ( Uri endpoint , string deploymentId , TokenCredential credential ) : this ( endpoint , deploymentId , credential , new OpenAIClientOptions ( ) )
31- {
32- }
33-
34- /// <summary> Initializes a new instance of OpenAIClient. </summary>
35- /// <param name="endpoint">
36- /// Supported Cognitive Services endpoints (protocol and hostname, for example:
37- /// https://westus.api.cognitive.microsoft.com).
38- /// </param>
39- /// <param name="deploymentId"> default deployment id to use for operations </param>
40- /// <param name="credential"> A credential used to authenticate to an Azure Service. </param>
41- /// <param name="options"> The options for configuring the client. </param>
42- /// <exception cref="ArgumentNullException"> <paramref name="endpoint"/> or <paramref name="credential"/> is null. </exception>
43- public OpenAIClient ( Uri endpoint , string deploymentId , TokenCredential credential , OpenAIClientOptions options )
44- {
45- Argument . AssertNotNull ( endpoint , nameof ( endpoint ) ) ;
46- Argument . AssertNotNull ( credential , nameof ( credential ) ) ;
47- options ??= new OpenAIClientOptions ( ) ;
48-
49- ClientDiagnostics = new ClientDiagnostics ( options , true ) ;
50- _tokenCredential = credential ;
51- _pipeline = HttpPipelineBuilder . Build ( options , Array . Empty < HttpPipelinePolicy > ( ) , new HttpPipelinePolicy [ ] { new BearerTokenAuthenticationPolicy ( _tokenCredential , AuthorizationScopes ) } , new ResponseClassifier ( ) ) ;
52- _endpoint = endpoint ;
53- _apiVersion = options . Version ;
54- _completionsDeploymentId ??= deploymentId ;
55- _embeddingsDeploymentId ??= deploymentId ;
56- }
57-
5819 /// <summary> Return the completion for a given prompt. </summary>
20+ /// <param name="deploymentId"> Deployment id (also known as model name) to use for operations </param>
5921 /// <param name="prompt"> Input string prompt to create a prompt completion from a deployment. </param>
6022 /// <param name="cancellationToken"> The cancellation token to use. </param>
61- public virtual async Task < Response < Completions > > GetCompletionsAsync ( string prompt , CancellationToken cancellationToken = default )
23+ public virtual async Task < Response < Completions > > GetCompletionsAsync ( string deploymentId , string prompt , CancellationToken cancellationToken = default )
6224 {
63- Argument . AssertNotNullOrEmpty ( _completionsDeploymentId , nameof ( _completionsDeploymentId ) ) ;
25+ Argument . AssertNotNullOrEmpty ( deploymentId , nameof ( deploymentId ) ) ;
6426 Argument . AssertNotNullOrEmpty ( prompt , nameof ( prompt ) ) ;
6527
6628 CompletionsOptions completionsOptions = new CompletionsOptions ( ) ;
6729 completionsOptions . Prompt . Add ( prompt ) ;
68- return await GetCompletionsAsync ( _completionsDeploymentId , completionsOptions , cancellationToken ) . ConfigureAwait ( false ) ;
30+ return await GetCompletionsAsync ( deploymentId , completionsOptions , cancellationToken ) . ConfigureAwait ( false ) ;
6931 }
7032
7133 /// <summary> Return the completions for a given prompt. </summary>
34+ /// <param name="deploymentId"> Deployment id (also known as model name) to use for operations </param>
7235 /// <param name="prompt"> Input string prompt to create a prompt completion from a deployment. </param>
7336 /// <param name="cancellationToken"> The cancellation token to use. </param>
74- public virtual Response < Completions > GetCompletions ( string prompt , CancellationToken cancellationToken = default )
37+ public virtual Response < Completions > GetCompletions ( string deploymentId , string prompt , CancellationToken cancellationToken = default )
7538 {
76- Argument . AssertNotNullOrEmpty ( _completionsDeploymentId , nameof ( _completionsDeploymentId ) ) ;
39+ Argument . AssertNotNullOrEmpty ( deploymentId , nameof ( deploymentId ) ) ;
7740 Argument . AssertNotNullOrEmpty ( prompt , nameof ( prompt ) ) ;
7841
7942 CompletionsOptions completionsOptions = new CompletionsOptions ( ) ;
8043 completionsOptions . Prompt . Add ( prompt ) ;
81- return GetCompletions ( _completionsDeploymentId , completionsOptions , cancellationToken ) ;
44+ return GetCompletions ( deploymentId , completionsOptions , cancellationToken ) ;
8245 }
8346 }
8447}
0 commit comments