|
| 1 | +import com.github.copilot.sdk.CopilotClient; |
| 2 | +import com.github.copilot.sdk.json.AzureOptions; |
| 3 | +import com.github.copilot.sdk.json.MessageOptions; |
| 4 | +import com.github.copilot.sdk.json.ProviderConfig; |
| 5 | +import com.github.copilot.sdk.json.SessionConfig; |
| 6 | +import com.github.copilot.sdk.json.SystemMessageConfig; |
| 7 | +import com.github.copilot.sdk.SystemMessageMode; |
| 8 | + |
| 9 | +import java.util.List; |
| 10 | + |
| 11 | +public class Main { |
| 12 | + public static void main(String[] args) throws Exception { |
| 13 | + var endpoint = System.getenv("AZURE_OPENAI_ENDPOINT"); |
| 14 | + var apiKey = System.getenv("AZURE_OPENAI_API_KEY"); |
| 15 | + var model = System.getenv("AZURE_OPENAI_MODEL"); |
| 16 | + if (model == null) model = "claude-haiku-4.5"; |
| 17 | + var apiVersion = System.getenv("AZURE_API_VERSION"); |
| 18 | + if (apiVersion == null) apiVersion = "2024-10-21"; |
| 19 | + |
| 20 | + if (endpoint == null || endpoint.isEmpty() || apiKey == null || apiKey.isEmpty()) { |
| 21 | + System.err.println("Required: AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_API_KEY"); |
| 22 | + System.exit(1); |
| 23 | + } |
| 24 | + |
| 25 | + try (var client = new CopilotClient()) { |
| 26 | + client.start().get(); |
| 27 | + var session = client.createSession( |
| 28 | + new SessionConfig() |
| 29 | + .setModel(model) |
| 30 | + .setProvider(new ProviderConfig() |
| 31 | + .setType("azure") |
| 32 | + .setBaseUrl(endpoint) |
| 33 | + .setApiKey(apiKey) |
| 34 | + .setAzure(new AzureOptions() |
| 35 | + .setApiVersion(apiVersion))) |
| 36 | + .setAvailableTools(List.of()) |
| 37 | + .setSystemMessage(new SystemMessageConfig() |
| 38 | + .setMode(SystemMessageMode.REPLACE) |
| 39 | + .setContent("You are a helpful assistant. Answer concisely."))) |
| 40 | + .get(); |
| 41 | + var response = session.sendAndWait( |
| 42 | + new MessageOptions().setPrompt("What is the capital of France?")) |
| 43 | + .get(); |
| 44 | + if (response != null) { |
| 45 | + System.out.println(response.getData().content()); |
| 46 | + } |
| 47 | + client.stop().get(); |
| 48 | + } |
| 49 | + } |
| 50 | +} |
0 commit comments