Skip to content

Commit 81aedd6

Browse files
committed
feat: Add Assistants API, Threads, Messages, Runs, Fine-tuning, and File management, and enhance Chat and Image completion requests.
1 parent db82e16 commit 81aedd6

31 files changed

Lines changed: 457 additions & 23 deletions

README.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# OpenAI Client for Android
2-
A light weight OpenAI's API client for Android. This tool is specifically designed for Android developers to interact with OpenAI's API in a lightweight and efficient manner. With this client, Android developers will be able to access OpenAI's services seamlessly, without having to worry about heavy resource consumption or slow performance. This tool promises to be an invaluable asset for Android developers and users who require quick and easy access to OpenAI's API.
2+
A lightweight OpenAI API client for Android. This tool is specifically designed for Android developers to interact with OpenAI's API in a lightweight and efficient manner. With this client, Android developers will be able to access OpenAI's services seamlessly, without having to worry about heavy resource consumption or slow performance. This tool promises to be an invaluable asset for Android developers and users who require quick and easy access to OpenAI's API.
33

44
[![Jitpack](https://jitpack.io/v/mardillu/OpenAI-Client-Android.svg)](https://jitpack.io/#mardillu/OpenAI-Client-Android)
55
[![Build & Unit Test](https://github.com/mardillu/OpenAI-Client-Android/actions/workflows/build.yml/badge.svg)](https://github.com/mardillu/OpenAI-Client-Android/actions/workflows/build.yml)
@@ -47,10 +47,10 @@ client.getTextCompletion("Hello chat gpt! what is the meaning of life?") { resul
4747
}
4848
```
4949
## Supported APIs
50-
- [x] Completions
51-
- [x] Chat
52-
- [x] Edits
53-
- [x] Images
50+
- [x] Chat Completions (GPT-4, GPT-3.5)
51+
- [x] Function Calling / Tools
52+
- [x] JSON Mode
53+
- [x] Images (DALL-E 3, DALL-E 2)
5454
- Create
5555
- Edit
5656
- Variations
@@ -60,10 +60,17 @@ client.getTextCompletion("Hello chat gpt! what is the meaning of life?") { resul
6060
- [x] Audio
6161
- Transcribe
6262
- Translate
63+
- [x] Assistants (Beta)
64+
- [x] Threads (Beta)
65+
- [x] Runs (Beta)
66+
- [x] Messages (Beta)
67+
- [x] Files
68+
- [x] Fine-tuning
69+
- [x] Completions (Legacy)
70+
- [x] Edits (Legacy)
6371

6472
## Upcoming APIs
65-
- [ ] Fine-tunes
66-
- [ ] Files
73+
- [x] Streaming for Assistants
6774

6875
## License
6976
MIT License

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ android {
4242
}
4343

4444
dependencies {
45-
implementation 'androidx.core:core-ktx:1.9.0'
45+
implementation 'androidx.core:core-ktx:1.12.0'
4646
implementation 'androidx.appcompat:appcompat:1.6.1'
47-
implementation 'com.google.android.material:material:1.8.0'
47+
implementation 'com.google.android.material:material:1.11.0'
4848
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
4949
testImplementation 'junit:junit:4.13.2'
5050
androidTestImplementation 'androidx.test.ext:junit:1.1.5'

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
plugins {
3-
id 'com.android.application' version '8.1.2' apply false
4-
id 'com.android.library' version '8.1.2' apply false
5-
id 'org.jetbrains.kotlin.android' version '1.9.10' apply false
3+
id 'com.android.application' version '8.3.1' apply false
4+
id 'com.android.library' version '8.3.1' apply false
5+
id 'org.jetbrains.kotlin.android' version '1.9.23' apply false
66
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
44
networkTimeout=10000
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

openai/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ android {
3131
}
3232

3333
dependencies {
34-
implementation 'androidx.core:core-ktx:1.9.0'
34+
implementation 'androidx.core:core-ktx:1.12.0'
3535
implementation 'androidx.appcompat:appcompat:1.6.1'
36-
implementation 'com.google.android.material:material:1.8.0'
36+
implementation 'com.google.android.material:material:1.11.0'
3737
testImplementation 'junit:junit:4.13.2'
3838
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
3939
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
4040
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
4141
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
42-
implementation 'com.squareup.okhttp3:logging-interceptor:4.9.3'
42+
implementation 'com.squareup.okhttp3:logging-interceptor:4.12.0'
4343
api "com.github.AppDevNext.Logcat:LogcatCoreLib:3.2"
4444
}

openai/src/main/java/com/mardillu/openai/model/Message.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,19 @@ package com.mardillu.openai.model
22

33
data class Message(
44
val role: String,
5-
val content: String
5+
val content: String? = null,
6+
val name: String? = null,
7+
val tool_calls: List<ToolCall>? = null,
8+
val tool_call_id: String? = null
9+
)
10+
11+
data class ToolCall(
12+
val id: String,
13+
val type: String,
14+
val function: FunctionCall
15+
)
16+
17+
data class FunctionCall(
18+
val name: String,
19+
val arguments: String
620
)

openai/src/main/java/com/mardillu/openai/model/requests/ChatCompletionRequest.kt

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,36 @@ import com.mardillu.openai.model.Message
44

55
data class ChatCompletionRequest(
66
val model: String,
7-
val messages: List<Message>
7+
val messages: List<Message>,
8+
val frequency_penalty: Double = 0.0,
9+
val logit_bias: Map<String, Int>? = null,
10+
val logprobs: Boolean = false,
11+
val top_logprobs: Int? = null,
12+
val max_tokens: Int? = null,
13+
val n: Int = 1,
14+
val presence_penalty: Double = 0.0,
15+
val response_format: ResponseFormat? = null,
16+
val seed: Int? = null,
17+
val stop: Any? = null, // String or Array of Strings
18+
val stream: Boolean = false,
19+
val temperature: Double = 1.0,
20+
val top_p: Double = 1.0,
21+
val tools: List<Tool>? = null,
22+
val tool_choice: Any? = null, // String or ToolChoice object
23+
val user: String? = null
24+
)
25+
26+
data class ResponseFormat(
27+
val type: String
28+
)
29+
30+
data class Tool(
31+
val type: String,
32+
val function: FunctionDefinition
33+
)
34+
35+
data class FunctionDefinition(
36+
val name: String,
37+
val description: String? = null,
38+
val parameters: Any? = null // JSON Schema object
839
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.mardillu.openai.model.requests
2+
3+
import com.mardillu.openai.model.requests.Tool
4+
5+
data class CreateAssistantRequest(
6+
val model: String,
7+
val name: String? = null,
8+
val description: String? = null,
9+
val instructions: String? = null,
10+
val tools: List<Tool>? = null,
11+
val file_ids: List<String>? = null,
12+
val metadata: Map<String, String>? = null
13+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.mardillu.openai.model.requests
2+
3+
data class CreateFineTuningJobRequest(
4+
val model: String,
5+
val training_file: String,
6+
val validation_file: String? = null,
7+
val hyperparameters: Hyperparameters? = null,
8+
val suffix: String? = null
9+
)
10+
11+
data class Hyperparameters(
12+
val n_epochs: Any? = "auto" // "auto" or Int
13+
)

openai/src/main/java/com/mardillu/openai/model/requests/CreateImageRequest.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ package com.mardillu.openai.model.requests
22

33
data class CreateImageRequest(
44
val prompt: String,
5-
val n: Int,
6-
val size: String
5+
val n: Int = 1,
6+
val size: String = "1024x1024",
7+
val model: String? = "dall-e-2",
8+
val quality: String? = "standard",
9+
val style: String? = "vivid",
10+
val response_format: String? = "url",
11+
val user: String? = null
712
)

0 commit comments

Comments
 (0)