├── .idea ├── .name ├── .gitignore ├── compiler.xml ├── kotlinc.xml ├── vcs.xml ├── misc.xml └── gradle.xml ├── demo ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── dimens.xml │ │ │ │ ├── themes.xml │ │ │ │ ├── colors.xml │ │ │ │ └── strings.xml │ │ │ ├── values-land │ │ │ │ └── dimens.xml │ │ │ ├── values-w1240dp │ │ │ │ └── dimens.xml │ │ │ ├── values-w600dp │ │ │ │ └── dimens.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── values-night │ │ │ │ └── themes.xml │ │ │ ├── values-v29 │ │ │ │ └── themes.xml │ │ │ ├── xml │ │ │ │ ├── backup_rules.xml │ │ │ │ └── data_extraction_rules.xml │ │ │ ├── layout │ │ │ │ ├── content_main.xml │ │ │ │ ├── fragment_second.xml │ │ │ │ ├── fragment_first.xml │ │ │ │ └── activity_main.xml │ │ │ ├── navigation │ │ │ │ └── nav_graph.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ └── drawable │ │ │ │ └── ic_launcher_background.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── yat3s │ │ │ │ └── openai │ │ │ │ └── demo │ │ │ │ ├── ui │ │ │ │ └── theme │ │ │ │ │ ├── Color.kt │ │ │ │ │ ├── Type.kt │ │ │ │ │ └── Theme.kt │ │ │ │ └── MainActivity.kt │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── yat3s │ │ │ └── openai │ │ │ └── api │ │ │ └── ExampleUnitTest.kt │ └── androidTest │ │ └── java │ │ └── com │ │ └── yat3s │ │ └── openai │ │ └── api │ │ └── ExampleInstrumentedTest.kt ├── proguard-rules.pro └── build.gradle ├── openai ├── .gitignore ├── src │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── yat3s │ │ │ │ └── openai │ │ │ │ └── api │ │ │ │ ├── model │ │ │ │ ├── OpenAIRequestBody.kt │ │ │ │ ├── TextCompletionError.kt │ │ │ │ ├── TextCompletionResponse.kt │ │ │ │ ├── ImageGenerationResponse.kt │ │ │ │ ├── ImageGenerationApiResponse.kt │ │ │ │ ├── TextCompletionApiRequestBody.kt │ │ │ │ ├── ImageGenerationApiRequestBody.kt │ │ │ │ └── TextCompletionApiResponse.kt │ │ │ │ ├── Config.kt │ │ │ │ ├── service │ │ │ │ └── OpenAIService.kt │ │ │ │ ├── OpenAIClient.kt │ │ │ │ ├── OpenAIClientBuilder.kt │ │ │ │ └── repository │ │ │ │ └── OpenAIRepository.kt │ │ └── AndroidManifest.xml │ └── test │ │ └── java │ │ └── com │ │ └── yat3s │ │ └── openai │ │ └── openai │ │ └── ExampleUnitTest.kt ├── build.gradle ├── gradle.properties └── proguard-rules.pro ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── settings.gradle ├── gradle.properties ├── README.md ├── gradlew.bat └── gradlew /.idea/.name: -------------------------------------------------------------------------------- 1 | openai-api -------------------------------------------------------------------------------- /demo/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /openai/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /demo/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 16dp 3 | -------------------------------------------------------------------------------- /demo/src/main/res/values-land/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 48dp 3 | -------------------------------------------------------------------------------- /demo/src/main/res/values-w1240dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 200dp 3 | -------------------------------------------------------------------------------- /demo/src/main/res/values-w600dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 48dp 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yat3s/openai-android/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /openai/src/main/java/com/yat3s/openai/api/model/OpenAIRequestBody.kt: -------------------------------------------------------------------------------- 1 | package com.yat3s.openai.api.model 2 | 3 | interface OpenAIRequestBody -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-hdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yat3s/openai-android/HEAD/demo/src/main/res/mipmap-hdpi/ic_launcher.webp -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-mdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yat3s/openai-android/HEAD/demo/src/main/res/mipmap-mdpi/ic_launcher.webp -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-xhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yat3s/openai-android/HEAD/demo/src/main/res/mipmap-xhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-xxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yat3s/openai-android/HEAD/demo/src/main/res/mipmap-xxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-xxxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yat3s/openai-android/HEAD/demo/src/main/res/mipmap-xxxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-hdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yat3s/openai-android/HEAD/demo/src/main/res/mipmap-hdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-mdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yat3s/openai-android/HEAD/demo/src/main/res/mipmap-mdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-xhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yat3s/openai-android/HEAD/demo/src/main/res/mipmap-xhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /openai/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yat3s/openai-android/HEAD/demo/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yat3s/openai-android/HEAD/demo/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /demo/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | -------------------------------------------------------------------------------- /openai/src/main/java/com/yat3s/openai/api/model/TextCompletionApiRequestBody.kt: -------------------------------------------------------------------------------- 1 | package com.yat3s.openai.api.model 2 | 3 | import com.google.gson.annotations.SerializedName 4 | 5 | internal data class TextCompletionApiRequestBody internal constructor( 6 | val prompt: String, 7 | val model: String, 8 | val temperature: Float, 9 | @SerializedName("max_tokens") val maxTokens: Int, 10 | ) : OpenAIRequestBody -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | google() 4 | mavenCentral() 5 | gradlePluginPortal() 6 | } 7 | } 8 | dependencyResolutionManagement { 9 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) 10 | repositories { 11 | google() 12 | mavenCentral() 13 | } 14 | } 15 | rootProject.name = "openai-api" 16 | include ':demo' 17 | include ':openai' 18 | -------------------------------------------------------------------------------- /demo/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFBB86FC 4 | #FF6200EE 5 | #FF3700B3 6 | #FF03DAC5 7 | #FF018786 8 | #FF000000 9 | #FFFFFFFF 10 | -------------------------------------------------------------------------------- /openai/src/main/java/com/yat3s/openai/api/model/ImageGenerationApiRequestBody.kt: -------------------------------------------------------------------------------- 1 | package com.yat3s.openai.api.model 2 | 3 | import com.google.gson.annotations.SerializedName 4 | 5 | internal data class ImageGenerationApiRequestBody internal constructor( 6 | val prompt: String, 7 | val size: String, 8 | @SerializedName("n") val generateCount: Int, 9 | @SerializedName("response_format") val responseFormat: String, 10 | ) : OpenAIRequestBody -------------------------------------------------------------------------------- /demo/src/test/java/com/yat3s/openai/api/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.yat3s.openai.api 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } -------------------------------------------------------------------------------- /openai/src/main/java/com/yat3s/openai/api/model/TextCompletionApiResponse.kt: -------------------------------------------------------------------------------- 1 | package com.yat3s.openai.api.model 2 | 3 | data class TextCompletionApiResponse( 4 | var id: String? = null, 5 | var created: String? = null, 6 | var choices: List? = null, 7 | var error: TextCompletionError? = null, 8 | ) 9 | 10 | data class TextCompletionChoice( 11 | val text: String?, 12 | val index: Int?, 13 | val finish_reason: String?, 14 | ) -------------------------------------------------------------------------------- /openai/src/test/java/com/yat3s/openai/openai/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.yat3s.openai.openai 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 10 | -------------------------------------------------------------------------------- /demo/src/main/res/values-v29/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | -------------------------------------------------------------------------------- /demo/src/main/res/xml/backup_rules.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 13 | -------------------------------------------------------------------------------- /demo/src/main/res/xml/data_extraction_rules.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 12 | 13 | 19 | -------------------------------------------------------------------------------- /openai/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.library' 3 | id 'org.jetbrains.kotlin.android' 4 | id 'com.vanniktech.maven.publish' version "0.24.0" 5 | } 6 | 7 | android { 8 | namespace 'com.yat3s.openai.api' 9 | compileSdk 33 10 | 11 | defaultConfig { 12 | minSdk 23 13 | targetSdk 33 14 | } 15 | 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | } 23 | 24 | dependencies { 25 | implementation 'com.squareup.okhttp3:okhttp:4.10.0' 26 | implementation 'com.squareup.retrofit2:retrofit:2.9.0' 27 | implementation 'com.squareup.retrofit2:converter-gson:2.9.0' 28 | } 29 | -------------------------------------------------------------------------------- /openai/gradle.properties: -------------------------------------------------------------------------------- 1 | SONATYPE_HOST=DEFAULT 2 | RELEASE_SIGNING_ENABLED=true 3 | 4 | GROUP=com.yat3s.openai 5 | POM_ARTIFACT_ID=openai-android 6 | VERSION_NAME=0.0.4 7 | 8 | POM_NAME=OpenAI API 9 | POM_DESCRIPTION=An Android SDK for OpenAI API. 10 | POM_INCEPTION_YEAR=2023 11 | POM_URL=https://github.com/Yat3s/openai-android 12 | 13 | POM_LICENSE_NAME=The Apache Software License, Version 2.0 14 | POM_LICENSE_URL=https://www.apache.org/licenses/LICENSE-2.0.txt 15 | POM_LICENSE_DIST=repo 16 | 17 | POM_SCM_URL=https://github.com/Yat3s/openai-android/ 18 | POM_SCM_CONNECTION=scm:git:git://github.com/Yat3s/openai-android.git 19 | POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/Yat3s/openai-android.git 20 | 21 | POM_DEVELOPER_ID=yat3s 22 | POM_DEVELOPER_NAME=Chris Ye 23 | POM_DEVELOPER_URL=https://github.com/yat3s/ -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 19 | 20 | -------------------------------------------------------------------------------- /demo/src/androidTest/java/com/yat3s/openai/api/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.yat3s.openai.api 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.yat3s.openai.api", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /demo/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /openai/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /demo/src/main/res/layout/content_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 19 | -------------------------------------------------------------------------------- /demo/src/main/java/com/yat3s/openai/demo/ui/theme/Type.kt: -------------------------------------------------------------------------------- 1 | package com.yat3s.openai.demo.ui.theme 2 | 3 | import androidx.compose.material3.Typography 4 | import androidx.compose.ui.text.TextStyle 5 | import androidx.compose.ui.text.font.FontFamily 6 | import androidx.compose.ui.text.font.FontWeight 7 | import androidx.compose.ui.unit.sp 8 | 9 | // Set of Material typography styles to start with 10 | val Typography = Typography( 11 | bodyLarge = TextStyle( 12 | fontFamily = FontFamily.Default, 13 | fontWeight = FontWeight.Normal, 14 | fontSize = 16.sp, 15 | lineHeight = 24.sp, 16 | letterSpacing = 0.5.sp 17 | ) 18 | /* Other default text styles to override 19 | titleLarge = TextStyle( 20 | fontFamily = FontFamily.Default, 21 | fontWeight = FontWeight.Normal, 22 | fontSize = 22.sp, 23 | lineHeight = 28.sp, 24 | letterSpacing = 0.sp 25 | ), 26 | labelSmall = TextStyle( 27 | fontFamily = FontFamily.Default, 28 | fontWeight = FontWeight.Medium, 29 | fontSize = 11.sp, 30 | lineHeight = 16.sp, 31 | letterSpacing = 0.5.sp 32 | ) 33 | */ 34 | ) -------------------------------------------------------------------------------- /demo/src/main/res/navigation/nav_graph.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 17 | 18 | 23 | 24 | 27 | 28 | -------------------------------------------------------------------------------- /openai/src/main/java/com/yat3s/openai/api/service/OpenAIService.kt: -------------------------------------------------------------------------------- 1 | package com.yat3s.openai.api.service 2 | 3 | import com.yat3s.openai.api.Config 4 | import com.yat3s.openai.api.model.ImageGenerationApiRequestBody 5 | import com.yat3s.openai.api.model.ImageGenerationApiResponse 6 | import com.yat3s.openai.api.model.TextCompletionApiRequestBody 7 | import com.yat3s.openai.api.model.TextCompletionApiResponse 8 | import retrofit2.Response 9 | import retrofit2.http.Body 10 | import retrofit2.http.Header 11 | import retrofit2.http.Headers 12 | import retrofit2.http.POST 13 | 14 | internal interface OpenAIService { 15 | @Headers( 16 | "content-type: application/json", 17 | ) 18 | @POST(Config.URL_TEXT_COMPLETION) 19 | suspend fun textCompletion( 20 | @Header("Authorization") authorization: String, 21 | @Body requestBody: TextCompletionApiRequestBody 22 | ): Response 23 | 24 | @Headers( 25 | "content-type: application/json", 26 | ) 27 | @POST(Config.URL_IMAGE_GENERATION) 28 | suspend fun imageGeneration( 29 | @Header("Authorization") authorization: String, 30 | @Body requestBody: ImageGenerationApiRequestBody 31 | ): Response 32 | } -------------------------------------------------------------------------------- /demo/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 17 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Kotlin code style for this project: "official" or "obsolete": 19 | kotlin.code.style=official 20 | # Enables namespacing of each library's R class so that its R class includes only the 21 | # resources declared in the library itself and none from the library's dependencies, 22 | # thereby reducing the size of the R class for that library 23 | android.nonTransitiveRClass=true -------------------------------------------------------------------------------- /demo/src/main/res/layout/fragment_second.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 |