From 00989ce123f2ee7ad9bcf3f2033eb66c39e246bd Mon Sep 17 00:00:00 2001 From: jtaub <65861679+jtaub@users.noreply.github.com> Date: Fri, 24 Nov 2023 13:10:18 -0500 Subject: [PATCH] chore: add documentation for maven and custom hosts (#265) --- README.md | 31 +++++++++++++++++++++++++++-- guides/GettingStarted.md | 43 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 71 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c7b5aadb..d2261b3a 100644 --- a/README.md +++ b/README.md @@ -38,11 +38,38 @@ dependencies { } ``` -### Multiplaform +### Multiplatform In multiplatform projects, add openai client dependency to `commonMain`, and choose an [engine](https://ktor.io/docs/http-client-engines.html) for each target. +### Maven + +Gradle is required for multiplatform support, but there's nothing stopping you from using the jvm client in a Maven +project. You still need to add to your dependencies one +of [Ktor's engines](https://ktor.io/docs/http-client-engines.html). For example: + +```xml + + + + com.aallam.openai + openai-client-jvm + 3.6.0 + + + + + io.ktor + ktor-client-okhttp-jvm + 2.3.2 + runtime + + +``` + +The BOM is not supported for Maven projects. + ## ⚡️ Getting Started > **Note**: OpenAI encourages using environment variables for the API key. [Read more](https://help.openai.com/en/articles/5112595-best-practices-for-api-key-safety). @@ -131,7 +158,7 @@ repositories { -## 🛠️ Throubleshooting +## 🛠️ Troubleshooting For common issues and their solutions, check the [Troubleshooting Guide](TROUBLESHOOTING.md). diff --git a/guides/GettingStarted.md b/guides/GettingStarted.md index c2a58a2a..247f3798 100644 --- a/guides/GettingStarted.md +++ b/guides/GettingStarted.md @@ -39,7 +39,10 @@ Use your `OpenAI` instance to make API requests. - [Retrieve file](#retrieve-file) - [Retrieve file content](#retrieve-file-content) - [Moderations](#moderations) - - [Create moderation](#create-moderation)- + - [Create moderation](#create-moderation) +- [Hosts](#hosts) + - [Azure](#azure) + - [Other hosts](#other-hosts) #### Beta @@ -391,6 +394,44 @@ val moderation = openAI.moderations( ) ```` +## Hosts + +This library has support for custom ChatGPT URLs. The host used by default is `https://api.openai.com/v1/`, as you would +expect, and support for Azure hosted ChatGPT is built in as well. + +### Azure + +To connect to an Azure hosted instance, use the `OpenAIHost.azure` function like so: + +````kotlin +val host = OpenAIHost.azure( + resourceName = "The name of your Azure OpenAI Resource.", + deploymentId = "The name of your model deployment.", + apiVersion = "The API version to use for this operation. This parameter should follow the YYYY-MM-DD format.", +) +val config = OpenAIConfig( + host = host, + token = "Your API token", +) +val openAI = OpenAI(config) +```` + +### Other hosts + +You can connect to whatever host you like by constructing your own `OpenAIHost` instance. Otherwise, it's exactly the +same as the above Azure example. + +````kotlin +val host = OpenAIHost( + baseUrl = "http://localhost:8080", +) +val config = OpenAIConfig( + host = host, + token = "Your API token", +) +val openAI = OpenAI(config) +```` + --- ## Completions