Skip to content

Commit ecbdac7

Browse files
committed
update
1 parent 2e5c5dc commit ecbdac7

File tree

1 file changed

+3
-64
lines changed

1 file changed

+3
-64
lines changed

articles/ai-services/openai/includes/chatgpt-java.md

Lines changed: 3 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -91,57 +91,6 @@ dependencies {
9191

9292
1. Open *OpenAIQuickstart.java* in your preferred editor or IDE and paste in the following code.
9393

94-
```java
95-
import com.azure.ai.openai.OpenAIClient;
96-
import com.azure.ai.openai.OpenAIClientBuilder;
97-
import com.azure.ai.openai.models.ChatChoice;
98-
import com.azure.ai.openai.models.ChatCompletions;
99-
import com.azure.ai.openai.models.ChatCompletionsOptions;
100-
import com.azure.ai.openai.models.ChatMessage;
101-
import com.azure.ai.openai.models.ChatRole;
102-
import com.azure.ai.openai.models.CompletionsUsage;
103-
import com.azure.core.credential.AzureKeyCredential;
104-
105-
import java.util.ArrayList;
106-
import java.util.List;
107-
108-
public class OpenAIQuickstart {
109-
110-
public static void main(String[] args) {
111-
String azureOpenaiKey = System.getenv("AZURE_OPENAI_API_KEY");;
112-
String endpoint = System.getenv("AZURE_OPENAI_ENDPOINT");;
113-
String deploymentOrModelId = "gpt-35-turbo"; //Change to match your deployment name
114-
115-
OpenAIClient client = new OpenAIClientBuilder()
116-
.endpoint(endpoint)
117-
.credential(new AzureKeyCredential(azureOpenaiKey))
118-
.buildClient();
119-
120-
List<ChatMessage> chatMessages = new ArrayList<>();
121-
chatMessages.add(new ChatMessage(ChatRole.SYSTEM, "You are a helpful assistant"));
122-
chatMessages.add(new ChatMessage(ChatRole.USER, "Does Azure OpenAI support customer managed keys?"));
123-
chatMessages.add(new ChatMessage(ChatRole.ASSISTANT, "Yes, customer managed keys are supported by Azure OpenAI?"));
124-
chatMessages.add(new ChatMessage(ChatRole.USER, "Do other Azure AI services support this too?"));
125-
126-
ChatCompletions chatCompletions = client.getChatCompletions(deploymentOrModelId, new ChatCompletionsOptions(chatMessages));
127-
128-
System.out.printf("Model ID=%s is created at %s.%n", chatCompletions.getId(), chatCompletions.getCreatedAt());
129-
for (ChatChoice choice : chatCompletions.getChoices()) {
130-
ChatMessage message = choice.getMessage();
131-
System.out.printf("Index: %d, Chat Role: %s.%n", choice.getIndex(), message.getRole());
132-
System.out.println("Message:");
133-
System.out.println(message.getContent());
134-
}
135-
136-
System.out.println();
137-
CompletionsUsage usage = chatCompletions.getUsage();
138-
System.out.printf("Usage: number of prompt token is %d, "
139-
+ "number of completion token is %d, and number of total tokens in request and response is %d.%n",
140-
usage.getPromptTokens(), usage.getCompletionTokens(), usage.getTotalTokens());
141-
}
142-
}
143-
```
144-
14594
```java
14695
package com.azure.ai.openai.usage;
14796

@@ -162,19 +111,9 @@ dependencies {
162111
import java.util.ArrayList;
163112
import java.util.List;
164113
165-
/**
166-
* Sample demonstrates how to get chat completions for the provided chat messages.
167-
* Completions support a wide variety of tasks and generate text that continues from or "completes" provided
168-
* prompt data.
169-
*/
114+
170115
public class GetChatCompletionsSample {
171-
/**
172-
* Runs the sample algorithm and demonstrates how to get chat completions for the provided chat messages.
173-
* Completions support a wide variety of tasks and generate text that continues from or "completes" provided
174-
* prompt data.
175-
*
176-
* @param args Unused. Arguments to the program.
177-
*/
116+
178117
public static void main(String[] args) {
179118
String azureOpenaiKey = Configuration.getGlobalConfiguration().get("AZURE_OPENAI_API_KEY");
180119
String endpoint = Configuration.getGlobalConfiguration().get("AZURE_OPENAI_ENDPOINT");
@@ -209,7 +148,7 @@ dependencies {
209148
}
210149
}
211150
```
212-
151+
213152

214153
> [!IMPORTANT]
215154
> For production, use a secure way of storing and accessing your credentials like [Azure Key Vault](../../../key-vault/general/overview.md). For more information about credential security, see the Azure AI services [security](../../security-features.md) article.

0 commit comments

Comments
 (0)