Skip to content

Commit 00989ce

Browse files
authored
chore: add documentation for maven and custom hosts (#265)
1 parent 61c2733 commit 00989ce

File tree

2 files changed

+71
-3
lines changed

2 files changed

+71
-3
lines changed

README.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,38 @@ dependencies {
3838
}
3939
```
4040

41-
### Multiplaform
41+
### Multiplatform
4242

4343
In multiplatform projects, add openai client dependency to `commonMain`, and choose
4444
an [engine](https://ktor.io/docs/http-client-engines.html) for each target.
4545

46+
### Maven
47+
48+
Gradle is required for multiplatform support, but there's nothing stopping you from using the jvm client in a Maven
49+
project. You still need to add to your dependencies one
50+
of [Ktor's engines](https://ktor.io/docs/http-client-engines.html). For example:
51+
52+
```xml
53+
<dependencies>
54+
<!-- https://mvnrepository.com/artifact/com.aallam.openai/openai-client-jvm -->
55+
<dependency>
56+
<groupId>com.aallam.openai</groupId>
57+
<artifactId>openai-client-jvm</artifactId>
58+
<version>3.6.0</version>
59+
</dependency>
60+
61+
<!-- https://mvnrepository.com/artifact/io.ktor/ktor-client-okhttp-jvm -->
62+
<dependency>
63+
<groupId>io.ktor</groupId>
64+
<artifactId>ktor-client-okhttp-jvm</artifactId>
65+
<version>2.3.2</version>
66+
<scope>runtime</scope>
67+
</dependency>
68+
</dependencies>
69+
```
70+
71+
The BOM is not supported for Maven projects.
72+
4673
## ⚡️ Getting Started
4774

4875
> **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 {
131158

132159
</details>
133160

134-
## 🛠️ Throubleshooting
161+
## 🛠️ Troubleshooting
135162

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

guides/GettingStarted.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ Use your `OpenAI` instance to make API requests.
3939
- [Retrieve file](#retrieve-file)
4040
- [Retrieve file content](#retrieve-file-content)
4141
- [Moderations](#moderations)
42-
- [Create moderation](#create-moderation)-
42+
- [Create moderation](#create-moderation)
43+
- [Hosts](#hosts)
44+
- [Azure](#azure)
45+
- [Other hosts](#other-hosts)
4346

4447
#### Beta
4548

@@ -391,6 +394,44 @@ val moderation = openAI.moderations(
391394
)
392395
````
393396

397+
## Hosts
398+
399+
This library has support for custom ChatGPT URLs. The host used by default is `https://api.openai.com/v1/`, as you would
400+
expect, and support for Azure hosted ChatGPT is built in as well.
401+
402+
### Azure
403+
404+
To connect to an Azure hosted instance, use the `OpenAIHost.azure` function like so:
405+
406+
````kotlin
407+
val host = OpenAIHost.azure(
408+
resourceName = "The name of your Azure OpenAI Resource.",
409+
deploymentId = "The name of your model deployment.",
410+
apiVersion = "The API version to use for this operation. This parameter should follow the YYYY-MM-DD format.",
411+
)
412+
val config = OpenAIConfig(
413+
host = host,
414+
token = "Your API token",
415+
)
416+
val openAI = OpenAI(config)
417+
````
418+
419+
### Other hosts
420+
421+
You can connect to whatever host you like by constructing your own `OpenAIHost` instance. Otherwise, it's exactly the
422+
same as the above Azure example.
423+
424+
````kotlin
425+
val host = OpenAIHost(
426+
baseUrl = "http://localhost:8080",
427+
)
428+
val config = OpenAIConfig(
429+
host = host,
430+
token = "Your API token",
431+
)
432+
val openAI = OpenAI(config)
433+
````
434+
394435
---
395436

396437
## Completions

0 commit comments

Comments
 (0)