Skip to content

Commit

Permalink
fix: Unable to choose other Chat models
Browse files Browse the repository at this point in the history
Signed-off-by: Dheshan Mohandass <dheshan@mohandass.com>
  • Loading branch information
dheshanm committed Nov 18, 2023
1 parent 3025ea3 commit a08591a
Show file tree
Hide file tree
Showing 14 changed files with 254 additions and 90 deletions.
123 changes: 123 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 16 additions & 18 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ plugins {

android {
namespace = "com.mohandass.botforge"
compileSdk = 33
compileSdk = 34

defaultConfig {
applicationId = "com.mohandass.botforge"
minSdk = 28
targetSdk = 33
versionCode = 32
versionName = "1.3.2"
targetSdk = 34
versionCode = 33
versionName = "1.3.3"

vectorDrawables.useSupportLibrary = true

Expand All @@ -50,7 +50,6 @@ android {
isMinifyEnabled = true
isShrinkResources = true

@Suppress("UnstableApiUsage")
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
Expand All @@ -67,13 +66,12 @@ android {
jvmTarget = "1.8"
}

@Suppress("UnstableApiUsage")
buildFeatures {
compose = true
}

composeOptions {
kotlinCompilerExtensionVersion = "1.2.0"
kotlinCompilerExtensionVersion = "1.5.4"
}

packaging {
Expand All @@ -89,18 +87,18 @@ configurations {

dependencies {
val composeBomVersion = "2023.04.00"
val activityVersion = "1.7.0"
val coreVersion = "1.10.0"
val lifecycleVersion = "2.6.1"
val navVersion = "2.5.3"
val composeRuntimeVersion = "1.4.1"
val activityVersion = "1.8.1"
val coreVersion = "1.12.0"
val lifecycleVersion = "2.6.2"
val navVersion = "2.7.5"
val composeRuntimeVersion = "1.5.4"
val datastorePreferencesVersion = "1.0.0"
val roomVersion = "2.5.1"
val daggerHiltVersion = "2.45"
val hiltNavVersion = "1.0.0"
val roomVersion = "2.6.0"
val daggerHiltVersion = "2.48"
val hiltNavVersion = "1.1.0"
val firebaseBomVersion = "31.5.0"
val gsonVersion = "2.10.1"
val openaiKotlinVersion = "3.2.1"
val openaiKotlinVersion = "3.5.1"
val percentageUnitsVersion = "1.0.0"
val prettytimeVersion = "5.0.6.Final"
val aboutLibsRelease = "10.6.2"
Expand All @@ -109,9 +107,9 @@ dependencies {
val coilVersion = "2.3.0"
val markwonVersion = "4.6.2"
val leakCanaryVersion = "2.10"
val okioVersion = "3.3.0"
val okioVersion = "3.4.0"

val playServicesAuthVersion = "20.5.0"
val playServicesAuthVersion = "20.7.0"

// Compose BOM
implementation(platform("androidx.compose:compose-bom:$composeBomVersion"))
Expand Down
2 changes: 2 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@

-dontwarn org.jetbrains.annotations.NotNull
-dontwarn org.jetbrains.annotations.Nullable

-dontwarn org.intellij.lang.annotations.Language
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@ data class Message(
companion object {
@OptIn(BetaOpenAI::class)
fun from(message: ChatMessage): Message {
val text = message.content
var nonNullText = ""

if (text != null) {
nonNullText = text
}
return Message(
text = message.content,
text = nonNullText,
role = Role.from(message.role),
uuid = UUID.randomUUID().toString(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ import java.util.*

@OptIn(BetaOpenAI::class)
fun ChatMessage.toMessage(): Message {
val text = this.content
var nonNullText = ""

if (text != null) {
nonNullText = text
}
return Message(
text = this.content,
text = nonNullText,
role = Role.from(this.role),
uuid = UUID.randomUUID().toString(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class OpenAiServiceImpl private constructor(
}
}

@OptIn(BetaOpenAI::class)
override suspend fun getChatCompletion(
messages: List<Message>,
): Message {
Expand All @@ -89,7 +88,7 @@ class OpenAiServiceImpl private constructor(

val metadata = MessageMetadata(
openAiId = completion.id,
finishReason = completion.choices[0].finishReason,
finishReason = completion.choices[0].finishReason.toString(),
promptTokens = completion.usage?.promptTokens,
completionTokens = completion.usage?.completionTokens,
totalTokens = completion.usage?.totalTokens,
Expand All @@ -99,7 +98,7 @@ class OpenAiServiceImpl private constructor(
sharedPreferencesService.incrementUsageTokens(completion.usage?.totalTokens ?: 0)

return Message(
text = completion.choices[0].message?.content?.trim() ?: "",
text = completion.choices[0].message.content?.trim() ?: "",
role = Role.BOT,
metadata = metadata,
)
Expand All @@ -109,7 +108,6 @@ class OpenAiServiceImpl private constructor(
}
}

@OptIn(BetaOpenAI::class)
override suspend fun generateImage(
prompt: String,
n: Int,
Expand Down

0 comments on commit a08591a

Please sign in to comment.