From 79ecccc8a3747c380f632d5c7792599bb3aeb61e Mon Sep 17 00:00:00 2001 From: Junhui Li Date: Wed, 25 Mar 2026 16:15:51 -0700 Subject: [PATCH] Remove Partner API section and examples --- MIGRATION.md | 27 +---- README.md | 29 +---- examples/partner/README.md | 20 ---- .../partner/openai/BasicChatCompletion.java | 65 ---------- .../openai/BasicChatCompletionApiKey.java | 45 ------- .../openai/StreamingChatCompletion.java | 61 ---------- .../openai/ToolCallChatCompletion.java | 113 ------------------ 7 files changed, 2 insertions(+), 358 deletions(-) delete mode 100644 examples/partner/README.md delete mode 100644 examples/partner/openai/BasicChatCompletion.java delete mode 100644 examples/partner/openai/BasicChatCompletionApiKey.java delete mode 100644 examples/partner/openai/StreamingChatCompletion.java delete mode 100644 examples/partner/openai/ToolCallChatCompletion.java diff --git a/MIGRATION.md b/MIGRATION.md index fb353bb..dbb803f 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -7,9 +7,7 @@ This guide helps existing `oci-genai-openai` users migrate to `oci-genai-auth-ja - Replace dependency `oci-genai-openai` with `oci-genai-auth-java-core`. - Continue using the `openai-java` SDK client. - Use `OciOkHttpClientFactory` to build a signed OkHttpClient. -- Choose endpoint/config based on API mode: - - OCI Enterprise AI Agents: `https://inference.generativeai..oci.oraclecloud.com/openai/v1` + `openai-project` header - - Partner : `https://inference.generativeai..oci.oraclecloud.com/20231130/actions/v1` + `compartmentId` +- Use the OCI Enterprise AI Agents endpoint: `https://inference.generativeai..oci.oraclecloud.com/openai/v1` + `openai-project` header ## 1) Dependency Changes @@ -78,31 +76,8 @@ OpenAIClient client = OpenAIOkHttpClient.builder() .build(); ``` -### Partner APIs - -Use `/20231130/actions/v1` and include compartment ID: - -```java -OciAuthConfig config = OciAuthConfig.builder() - .authType("security_token") - .profile("DEFAULT") - .compartmentId("") - .build(); - -OkHttpClient ociHttpClient = OciOkHttpClientFactory.build(config); - -OpenAIClient client = OpenAIOkHttpClient.builder() - .baseUrl("https://inference.generativeai..oci.oraclecloud.com/20231130/actions/v1") - .okHttpClient(ociHttpClient) - .apiKey("not-used") - .build(); -``` - ## 4) Endpoint and required parameters - OCI Enterprise AI Agents: - `baseUrl`: `https://inference.generativeai..oci.oraclecloud.com/openai/v1` - required: `openai-project` header with project OCID -- Partner: - - `baseUrl`: `https://inference.generativeai..oci.oraclecloud.com/20231130/actions/v1` - - required: `compartmentId` in `OciAuthConfig` diff --git a/README.md b/README.md index f9655d5..8123cb8 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,6 @@ The **OCI GenAI Auth** Java library provides OCI request-signing helpers for the - [Using OCI IAM Auth](#using-oci-iam-auth) - [Using API Key Auth](#using-api-key-auth) - [Using OCI Enterprise AI Agents APIs](#using-oci-enterprise-ai-agents-apis) -- [Using Partner APIs (passthrough)](#using-partner-apis-passthrough) - [Examples](#examples) - [Contributing](#contributing) - [Security](#security) @@ -113,34 +112,8 @@ OpenAIClient client = OpenAIOkHttpClient.builder() .build(); ``` -## Using Partner APIs (passthrough) - -OCI also offers Partner API which passes through your calls to partners such as OpenAI. We will support more partners in the future. - -You can leverage Partner API when you want to use OpenAI's API and GPT models, but with OCI auth and billing. - -Note: Currently Partner API is only available to Oracle internal teams. Only features that meet partner's Zero Data Retention are available through Partner API. - -If you want multi-provider model access and features unavailable under partner's Zero Data Retention (such as File Search), use the OCI Enterprise AI Agents APIs above. - -```java -OciAuthConfig config = OciAuthConfig.builder() - .authType("security_token") - .profile("DEFAULT") - .compartmentId("ocid1.compartment.oc1..aaaaaaaaexample") - .build(); - -OkHttpClient ociHttpClient = OciOkHttpClientFactory.build(config); - -OpenAIClient client = OpenAIOkHttpClient.builder() - .baseUrl("https://inference.generativeai.us-chicago-1.oci.oraclecloud.com/20231130/actions/v1") - .okHttpClient(ociHttpClient) - .apiKey("not-used") - .build(); -``` - ## Examples -Demo code and instructions on how to run them, for both OCI Enterprise AI Agents and partner usecases can be found in [examples](examples/) folder. +Demo code and instructions on how to run them can be found in [examples](examples/) folder. ## Contributing diff --git a/examples/partner/README.md b/examples/partner/README.md deleted file mode 100644 index 7330ec6..0000000 --- a/examples/partner/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# Partner Examples - -This folder contains partner API examples using the OpenAI Java SDK. - -## Prerequisites - -1. Install dependencies: - - ```bash - mvn install -DskipTests - ``` - -2. Configure constants in each example file: - - `COMPARTMENT_ID` - - `REGION` - -## Notes - -- Partner endpoints use pass-through mode and require the `opc-compartment-id` header. -- These examples use IAM signing through `oci-genai-auth-java`. diff --git a/examples/partner/openai/BasicChatCompletion.java b/examples/partner/openai/BasicChatCompletion.java deleted file mode 100644 index e00acd1..0000000 --- a/examples/partner/openai/BasicChatCompletion.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2026 Oracle and/or its affiliates. - * Licensed under the Universal Permissive License v 1.0 as shown at - * https://oss.oracle.com/licenses/upl/ - */ - -/** - * Demonstrates a basic chat completion request for the Partner endpoint. - * - *

This file is a standalone example — it is NOT compiled as part of the Maven build. - * Copy it into your own project and add the required dependencies. - */ - -import com.openai.client.OpenAIClient; -import com.openai.client.okhttp.OpenAIOkHttpClient; -import com.openai.models.chat.completions.ChatCompletion; -import com.openai.models.chat.completions.ChatCompletionCreateParams; - -import com.oracle.genai.auth.OciAuthConfig; -import com.oracle.genai.auth.OciOkHttpClientFactory; - -import okhttp3.OkHttpClient; - -public class BasicChatCompletion { - - // ── Configuration ────────────────────────────────────────────────── - private static final String REGION = "us-chicago-1"; - private static final String COMPARTMENT_ID = "<>"; - private static final String MODEL = "openai.gpt-4.1"; - // ──────────────────────────────────────────────────────────────────── - - private static final String BASE_URL = - "https://inference.generativeai." + REGION + ".oci.oraclecloud.com/20231130/actions/v1"; - - public static void main(String[] args) { - // 1. Build an OCI-signed OkHttpClient - OciAuthConfig config = OciAuthConfig.builder() - .authType("security_token") - .profile("DEFAULT") - .compartmentId(COMPARTMENT_ID) - .build(); - - OkHttpClient ociHttpClient = OciOkHttpClientFactory.build(config); - - // 2. Plug the OCI-signed client into the OpenAI SDK - OpenAIClient client = OpenAIOkHttpClient.builder() - .baseUrl(BASE_URL) - .okHttpClient(ociHttpClient) - .apiKey("not-used") - .build(); - - // 3. Send a chat completion request - ChatCompletion completion = client.chat().completions().create( - ChatCompletionCreateParams.builder() - .model(MODEL) - .addSystemMessage("You are a concise assistant.") - .addUserMessage("List three creative uses for a paperclip.") - .maxTokens(128) - .build()); - - // 4. Print the response - completion.choices().forEach(choice -> - choice.message().content().ifPresent(System.out::println)); - } -} diff --git a/examples/partner/openai/BasicChatCompletionApiKey.java b/examples/partner/openai/BasicChatCompletionApiKey.java deleted file mode 100644 index be528ec..0000000 --- a/examples/partner/openai/BasicChatCompletionApiKey.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2026 Oracle and/or its affiliates. - * Licensed under the Universal Permissive License v 1.0 as shown at - * https://oss.oracle.com/licenses/upl/ - */ - -/** - * Demonstrates chat completion using OCI Generative AI API Key authentication. - * - *

No oci-genai-auth package needed for API Key auth — just the official OpenAI SDK. - * - *

Steps: - *

    - *
  1. Create API keys in Console: Generative AI → API Keys
  2. - *
  3. Set OPENAI_API_KEY environment variable
  4. - *
  5. Run this example
  6. - *
- */ - -import com.openai.client.OpenAIClient; -import com.openai.client.okhttp.OpenAIOkHttpClient; -import com.openai.models.chat.completions.ChatCompletion; -import com.openai.models.chat.completions.ChatCompletionCreateParams; - -public class BasicChatCompletionApiKey { - - private static final String MODEL = "openai.gpt-4.1"; - - public static void main(String[] args) { - OpenAIClient client = OpenAIOkHttpClient.builder() - .baseUrl("https://inference.generativeai.us-chicago-1.oci.oraclecloud.com/openai/v1") - .apiKey(System.getenv("OCI_GENAI_API_KEY")) - .build(); - - ChatCompletion completion = client.chat().completions().create( - ChatCompletionCreateParams.builder() - .model(MODEL) - .addSystemMessage("You are a concise assistant who answers in one paragraph.") - .addUserMessage("Explain why the sky is blue as if you were a physics teacher.") - .build()); - - completion.choices().forEach(choice -> - choice.message().content().ifPresent(System.out::println)); - } -} diff --git a/examples/partner/openai/StreamingChatCompletion.java b/examples/partner/openai/StreamingChatCompletion.java deleted file mode 100644 index 38e1128..0000000 --- a/examples/partner/openai/StreamingChatCompletion.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2026 Oracle and/or its affiliates. - * Licensed under the Universal Permissive License v 1.0 as shown at - * https://oss.oracle.com/licenses/upl/ - */ - -/** - * Demonstrates streaming chat completion responses for the Partner endpoint. - */ - -import com.openai.client.OpenAIClient; -import com.openai.client.okhttp.OpenAIOkHttpClient; -import com.openai.models.chat.completions.ChatCompletionChunk; -import com.openai.models.chat.completions.ChatCompletionCreateParams; - -import com.oracle.genai.auth.OciAuthConfig; -import com.oracle.genai.auth.OciOkHttpClientFactory; - -import okhttp3.OkHttpClient; - -public class StreamingChatCompletion { - - // ── Configuration ────────────────────────────────────────────────── - private static final String REGION = "us-chicago-1"; - private static final String COMPARTMENT_ID = "<>"; - private static final String MODEL = "openai.gpt-4.1"; - // ──────────────────────────────────────────────────────────────────── - - private static final String BASE_URL = - "https://inference.generativeai." + REGION + ".oci.oraclecloud.com/20231130/actions/v1"; - - public static void main(String[] args) { - OciAuthConfig config = OciAuthConfig.builder() - .authType("security_token") - .profile("DEFAULT") - .compartmentId(COMPARTMENT_ID) - .build(); - - OkHttpClient ociHttpClient = OciOkHttpClientFactory.build(config); - - OpenAIClient client = OpenAIOkHttpClient.builder() - .baseUrl(BASE_URL) - .okHttpClient(ociHttpClient) - .apiKey("not-used") - .build(); - - // Stream the response - client.chat().completions().createStreaming( - ChatCompletionCreateParams.builder() - .model(MODEL) - .addSystemMessage("You are a concise assistant who answers in one paragraph.") - .addUserMessage("Explain why the sky is blue as if you were a physics teacher.") - .build()) - .stream() - .flatMap(chunk -> chunk.choices().stream()) - .forEach(choice -> choice.delta().content().ifPresent( - content -> System.out.print(content))); - - System.out.println(); - } -} diff --git a/examples/partner/openai/ToolCallChatCompletion.java b/examples/partner/openai/ToolCallChatCompletion.java deleted file mode 100644 index 685c964..0000000 --- a/examples/partner/openai/ToolCallChatCompletion.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2026 Oracle and/or its affiliates. - * Licensed under the Universal Permissive License v 1.0 as shown at - * https://oss.oracle.com/licenses/upl/ - */ - -/** - * Demonstrates tool calling with chat completions for the Partner endpoint. - */ - -import com.openai.client.OpenAIClient; -import com.openai.client.okhttp.OpenAIOkHttpClient; -import com.openai.models.chat.completions.*; - -import com.oracle.genai.auth.OciAuthConfig; -import com.oracle.genai.auth.OciOkHttpClientFactory; - -import okhttp3.OkHttpClient; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -public class ToolCallChatCompletion { - - // ── Configuration ────────────────────────────────────────────────── - private static final String REGION = "us-chicago-1"; - private static final String COMPARTMENT_ID = "<>"; - private static final String MODEL = "openai.gpt-4.1"; - // ──────────────────────────────────────────────────────────────────── - - private static final String BASE_URL = - "https://inference.generativeai." + REGION + ".oci.oraclecloud.com/20231130/actions/v1"; - - /** Mock weather function. */ - private static String getCurrentWeather(String location) { - return """ - {"location": "%s", "temperature": "72", "unit": "fahrenheit", "forecast": ["sunny", "windy"]} - """.formatted(location).trim(); - } - - public static void main(String[] args) { - OciAuthConfig config = OciAuthConfig.builder() - .authType("security_token") - .profile("DEFAULT") - .compartmentId(COMPARTMENT_ID) - .build(); - - OkHttpClient ociHttpClient = OciOkHttpClientFactory.build(config); - - OpenAIClient client = OpenAIOkHttpClient.builder() - .baseUrl(BASE_URL) - .okHttpClient(ociHttpClient) - .apiKey("not-used") - .build(); - - // Define the function tool - ChatCompletionTool weatherTool = ChatCompletionTool.builder() - .function(FunctionDefinition.builder() - .name("get_current_weather") - .description("Get the current weather for a specific location.") - .parameters(ChatCompletionTool.Function.Parameters.builder() - .putAdditionalProperty("type", "object") - .putAdditionalProperty("properties", Map.of( - "location", Map.of( - "type", "string", - "description", "City and state, for example Boston, MA."))) - .putAdditionalProperty("required", List.of("location")) - .build()) - .build()) - .build(); - - // First request - ChatCompletion first = client.chat().completions().create( - ChatCompletionCreateParams.builder() - .model(MODEL) - .addUserMessage("What is the weather in Boston and San Francisco?") - .addTool(weatherTool) - .toolChoice(ChatCompletionToolChoiceOption.AUTO) - .build()); - - ChatCompletion.Choice firstChoice = first.choices().get(0); - - if ("tool_calls".equals(firstChoice.finishReason().toString())) { - // Execute tool calls and send results back - List messages = new ArrayList<>(); - messages.add(ChatCompletionCreateParams.Message.ofUser( - UserMessage.of("What is the weather in Boston and San Francisco?"))); - messages.add(ChatCompletionCreateParams.Message.ofAssistant( - firstChoice.message())); - - for (var toolCall : firstChoice.message().toolCalls().orElse(List.of())) { - String result = getCurrentWeather(toolCall.function().name()); - messages.add(ChatCompletionCreateParams.Message.ofTool( - ToolMessage.builder() - .toolCallId(toolCall.id()) - .content(result) - .build())); - } - - ChatCompletion followUp = client.chat().completions().create( - ChatCompletionCreateParams.builder() - .model(MODEL) - .messages(messages) - .build()); - - followUp.choices().forEach(choice -> - choice.message().content().ifPresent(System.out::println)); - } else { - firstChoice.message().content().ifPresent(System.out::println); - } - } -}