|
| 1 | +# Migration Guide: `oci-genai-openai` to `oci-genai-auth-java` |
| 2 | + |
| 3 | +This guide helps existing `oci-genai-openai` users migrate to `oci-genai-auth-java`. |
| 4 | + |
| 5 | +## Summary |
| 6 | + |
| 7 | +- Replace dependency `oci-genai-openai` with `oci-genai-auth-java-core`. |
| 8 | +- Continue using the `openai-java` SDK client. |
| 9 | +- Use `OciOkHttpClientFactory` to build a signed OkHttpClient. |
| 10 | +- Choose endpoint/config based on API mode: |
| 11 | + - AgentHub: `https://inference.generativeai.<region>.oci.oraclecloud.com/openai/v1` + `openai-project` header |
| 12 | + - Partner : `https://inference.generativeai.<region>.oci.oraclecloud.com/20231130/actions/v1` + `compartmentId` |
| 13 | + |
| 14 | +## 1) Dependency Changes |
| 15 | + |
| 16 | +Replace the old dependency with the new one in your `pom.xml`: |
| 17 | + |
| 18 | +```xml |
| 19 | +<!-- Remove old dependency --> |
| 20 | +<!-- <artifactId>oci-genai-openai</artifactId> --> |
| 21 | + |
| 22 | +<!-- Add new dependency --> |
| 23 | +<dependencyManagement> |
| 24 | + <dependencies> |
| 25 | + <dependency> |
| 26 | + <groupId>com.oracle.genai</groupId> |
| 27 | + <artifactId>oci-genai-auth-java-bom</artifactId> |
| 28 | + <version>1.0.0</version> |
| 29 | + <type>pom</type> |
| 30 | + <scope>import</scope> |
| 31 | + </dependency> |
| 32 | + </dependencies> |
| 33 | +</dependencyManagement> |
| 34 | + |
| 35 | +<dependencies> |
| 36 | + <dependency> |
| 37 | + <groupId>com.oracle.genai</groupId> |
| 38 | + <artifactId>oci-genai-auth-java-core</artifactId> |
| 39 | + </dependency> |
| 40 | +</dependencies> |
| 41 | +``` |
| 42 | + |
| 43 | +## 2) Import Changes |
| 44 | + |
| 45 | +```java |
| 46 | +// Old |
| 47 | +import com.oracle.genai.openai.OciOpenAI; |
| 48 | + |
| 49 | +// New |
| 50 | +import com.oracle.genai.auth.OciAuthConfig; |
| 51 | +import com.oracle.genai.auth.OciOkHttpClientFactory; |
| 52 | +``` |
| 53 | + |
| 54 | +## 3) Client Initialization Changes |
| 55 | + |
| 56 | +### AgentHub |
| 57 | + |
| 58 | +Use the OpenAI-compatible endpoint and provide project OCID: |
| 59 | + |
| 60 | +```java |
| 61 | +import com.oracle.genai.auth.OciAuthConfig; |
| 62 | +import com.oracle.genai.auth.OciOkHttpClientFactory; |
| 63 | +import com.openai.client.OpenAIClient; |
| 64 | +import com.openai.client.okhttp.OpenAIOkHttpClient; |
| 65 | + |
| 66 | +OciAuthConfig config = OciAuthConfig.builder() |
| 67 | + .authType("security_token") |
| 68 | + .profile("DEFAULT") |
| 69 | + .build(); |
| 70 | + |
| 71 | +OkHttpClient ociHttpClient = OciOkHttpClientFactory.build(config); |
| 72 | + |
| 73 | +OpenAIClient client = OpenAIOkHttpClient.builder() |
| 74 | + .baseUrl("https://inference.generativeai.<region>.oci.oraclecloud.com/openai/v1") |
| 75 | + .okHttpClient(ociHttpClient) |
| 76 | + .apiKey("not-used") |
| 77 | + .addHeader("openai-project", "<ocid1.generativeaiproject...>") |
| 78 | + .build(); |
| 79 | +``` |
| 80 | + |
| 81 | +### Partner APIs |
| 82 | + |
| 83 | +Use `/20231130/actions/v1` and include compartment ID: |
| 84 | + |
| 85 | +```java |
| 86 | +OciAuthConfig config = OciAuthConfig.builder() |
| 87 | + .authType("security_token") |
| 88 | + .profile("DEFAULT") |
| 89 | + .compartmentId("<ocid1.compartment...>") |
| 90 | + .build(); |
| 91 | + |
| 92 | +OkHttpClient ociHttpClient = OciOkHttpClientFactory.build(config); |
| 93 | + |
| 94 | +OpenAIClient client = OpenAIOkHttpClient.builder() |
| 95 | + .baseUrl("https://inference.generativeai.<region>.oci.oraclecloud.com/20231130/actions/v1") |
| 96 | + .okHttpClient(ociHttpClient) |
| 97 | + .apiKey("not-used") |
| 98 | + .build(); |
| 99 | +``` |
| 100 | + |
| 101 | +## 4) Endpoint and required parameters |
| 102 | + |
| 103 | +- AgentHub: |
| 104 | + - `baseUrl`: `https://inference.generativeai.<region>.oci.oraclecloud.com/openai/v1` |
| 105 | + - required: `openai-project` header with project OCID |
| 106 | +- Partner: |
| 107 | + - `baseUrl`: `https://inference.generativeai.<region>.oci.oraclecloud.com/20231130/actions/v1` |
| 108 | + - required: `compartmentId` in `OciAuthConfig` |
0 commit comments