Skip to content

Commit

Permalink
chore: add documentation for maven and custom hosts (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtaub committed Nov 24, 2023
1 parent 61c2733 commit 00989ce
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 3 deletions.
31 changes: 29 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<dependencies>
<!-- https://mvnrepository.com/artifact/com.aallam.openai/openai-client-jvm -->
<dependency>
<groupId>com.aallam.openai</groupId>
<artifactId>openai-client-jvm</artifactId>
<version>3.6.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/io.ktor/ktor-client-okhttp-jvm -->
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-client-okhttp-jvm</artifactId>
<version>2.3.2</version>
<scope>runtime</scope>
</dependency>
</dependencies>
```

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).
Expand Down Expand Up @@ -131,7 +158,7 @@ repositories {

</details>

## 🛠️ Throubleshooting
## 🛠️ Troubleshooting

For common issues and their solutions, check the [Troubleshooting Guide](TROUBLESHOOTING.md).

Expand Down
43 changes: 42 additions & 1 deletion guides/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 00989ce

Please sign in to comment.