You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+10-13Lines changed: 10 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,21 +28,20 @@ dependencies {
28
28
~~~
29
29
30
30
## Getting started
31
-
1. Initialize the client by calling the following function. You only need to do this once, ideally, in your Application class using environment variables for the API_KEY.
32
-
~~~kotlin
33
-
OpenAiInitializer.initialize("API_KEY")
34
-
~~~
35
-
2. Create an instance of `OpenAiClient`
31
+
1. Create an instance of `OpenAiConfig` and `OpenApiClient`:
36
32
```kotlin
37
-
val client =OpenApiClient()
33
+
val config =OpenAiConfig(apiKey ="YOUR_API_KEY")
34
+
val client =OpenApiClient(config)
38
35
```
39
-
3. Make a request
36
+
2. Make a request using Coroutines:
40
37
```kotlin
41
-
client.getTextCompletion("Hello chat gpt! what is the meaning of life?") { result, error ->
42
-
if (error !=null) {
43
-
// Handle error
44
-
} elseif (result !=null) {
38
+
lifecycleScope.launch {
39
+
try {
40
+
val result = client.getTextCompletion("Hello chat gpt! what is the meaning of life?")
45
41
Log.d("TAG", result.choices[0].text)
42
+
} catch (e:Exception) {
43
+
// Handle error
44
+
e.printStackTrace()
46
45
}
47
46
}
48
47
```
@@ -68,8 +67,6 @@ client.getTextCompletion("Hello chat gpt! what is the meaning of life?") { resul
0 commit comments