Skip to content

Commit

Permalink
Tweak chat (#25)
Browse files Browse the repository at this point in the history
* Improve state handling
* Imrpove error handling in chat
  • Loading branch information
Otacon authored Oct 4, 2024
1 parent 9b24bd9 commit 1796e49
Show file tree
Hide file tree
Showing 29 changed files with 1,343 additions and 395 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/create_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ name: Create release
run-name: Create release

on:
push:
branches:
- main

workflow_dispatch:
push:
tags:
- v*

permissions:
contents: read
Expand Down Expand Up @@ -51,7 +50,7 @@ jobs:
- name: Setup Ruby
uses: ruby/setup-ruby@8575951200e472d5f2d95c625da0c7bec8217c42 # v1.161.0
with:
ruby-version: '3.1' # Not needed with a .ruby-version file
ruby-version: '3.1'

- name: Create Blog
working-directory: ./blog
Expand Down
61 changes: 48 additions & 13 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

permissions:
checks: write
contents: write
pull-requests: write

jobs:
build-app:
runs-on: ubuntu-latest
Expand All @@ -25,6 +30,49 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Run unit tests
run: ./gradlew allTests

- name: Upload desktop test report
uses: dorny/test-reporter@v1
if: success() || failure()
with:
name: Desktop test report
only-summary: 'true'
path: 'composeApp/build/test-results/desktopTest/*.xml'
reporter: java-junit
list-tests: 'failed'

- name: Upload android debug test report
uses: dorny/test-reporter@v1
if: success() || failure()
with:
name: Android debug test report
only-summary: 'true'
path: 'composeApp/build/test-results/testDebugUnitTest/*.xml'
reporter: java-junit
list-tests: 'failed'

- name: Upload android release test report
uses: dorny/test-reporter@v1
if: success() || failure()
with:
name: Android release test report
only-summary: 'true'
path: 'composeApp/build/test-results/testReleaseUnitTest/*.xml'
reporter: java-junit
list-tests: 'failed'

- name: Upload web test report
uses: dorny/test-reporter@v1
if: success() || failure()
with:
name: Web test report
only-summary: 'true'
path: 'composeApp/build/test-results/wasmJsBrowserTest/*.xml'
reporter: java-junit
list-tests: 'failed'

- name: Build Web app
env:
FIREBASE_WEB_CONFIG_JSON: ${{ secrets.FIREBASE_WEB_CONFIG_JSON }}
Expand All @@ -33,21 +81,8 @@ jobs:
run: |
./gradlew :composeApp:wasmJsBrowserDistribution -Pbuildkonfig.flavor=release
- name: Build Desktop app
env:
ANALYTICS_API_SECRET: ${{ secrets.ANALYTICS_API_SECRET }}
ANALYTICS_MEASUREMENT_ID: ${{ secrets.ANALYTICS_MEASUREMENT_ID }}
run: |
./gradlew desktopJar --quiet -Pbuildkonfig.flavor=release
- name: Upload web artifacts
uses: actions/upload-artifact@v4
with:
name: OlpakaWeb
path: composeApp/build/dist/wasmJs/productionExecutable/*

- name: Upload desktop artifacts
uses: actions/upload-artifact@v4
with:
name: OlpakaDesktop
path: composeApp/build/libs/*
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ plugins {
alias(libs.plugins.compose.compiler) apply false
alias(libs.plugins.kotlinMultiplatform) apply false
alias(libs.plugins.buildKonfig) apply false
alias(libs.plugins.mokkery) apply false
}
42 changes: 41 additions & 1 deletion composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import com.codingfeline.buildkonfig.compiler.FieldSpec.Type.BOOLEAN
import com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
Expand All @@ -14,6 +16,7 @@ plugins {
alias(libs.plugins.compose.compiler)
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.buildKonfig)
alias(libs.plugins.mokkery)
}

buildkonfig {
Expand All @@ -24,7 +27,6 @@ buildkonfig {
val analyticsApiSecret = System.getenv("ANALYTICS_API_SECRET") ?: ""
val firebaseWebConfig = System.getenv("FIREBASE_WEB_CONFIG_JSON") ?: ""

println("FirebaseWebConfig exists? ${firebaseWebConfig.isNotBlank()}")
val decodedWebConfig = Base64.getDecoder().decode(firebaseWebConfig).decodeToString()

defaultConfigs {
Expand All @@ -43,7 +45,37 @@ buildkonfig {
}
}

tasks.withType<Test> {
testLogging {

events = setOf(
TestLogEvent.PASSED,
TestLogEvent.FAILED,
TestLogEvent.SKIPPED,
TestLogEvent.STANDARD_OUT,
TestLogEvent.STANDARD_ERROR,
)

exceptionFormat = TestExceptionFormat.FULL
ignoreFailures = true
showExceptions = true
showCauses = true
showStackTraces = true
showStandardStreams = true

reports.html.required = false
reports.junitXml.required = true
}

}

@OptIn(ExperimentalKotlinGradlePluginApi::class)
kotlin {

compilerOptions {
freeCompilerArgs.add("-Xexpect-actual-classes")
}

@OptIn(ExperimentalWasmDsl::class)
wasmJs {
moduleName = "composeApp"
Expand Down Expand Up @@ -93,6 +125,7 @@ kotlin {

implementation(libs.kotlinx.coroutines.android)
}

commonMain.dependencies {
implementation(compose.foundation)
implementation(compose.components.resources)
Expand Down Expand Up @@ -139,9 +172,16 @@ kotlin {
iosMain.dependencies {
implementation(libs.ktor.client.darwin)
}

wasmJsMain.dependencies {
implementation(devNpm("firebase", "10.13.2"))
}

commonTest.dependencies {
implementation(libs.kotlin.test)
implementation(libs.kotlinx.coroutines.test)
implementation(libs.turbine)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.cyanotic.olpaka.core

actual class FirebaseAnalytics {
actual fun init() {
actual class FirebaseAnalytics : Analytics {
actual override fun init() {
}

actual fun screenView(screenName: String) {
actual override fun screenView(screenName: String) {
}

actual fun event(eventName: String, properties: Map<String, Any?>) {
actual override fun event(eventName: String, properties: Map<String, Any?>) {
}

}
4 changes: 2 additions & 2 deletions composeApp/src/commonMain/composeResources/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<string name="chat_missing_model_error_message">To start a new conversation, make sure you've got at least one model installed.\n\nHead to the "Models" tab to download your first model.</string>
<string name="chat_empty_screen_title">...Howdy...</string>
<string name="chat_empty_screen_message">How can I help you today?</string>
<string name="chat_message_error">Whooops...something went wrong when generating the answer...</string>
<string name="chat_message_error">There has been an error while generating the message. Try again.</string>

<string name="home_tab_name_chat">Chat</string>
<string name="home_tab_name_models">Models</string>
Expand Down Expand Up @@ -46,7 +46,7 @@
<string name="onboarding_step_2_a">To get started, you'll need to download and install Ollama.</string>
<string name="onboarding_step_2_b">Click on "Next" once you're done.</string>
<string name="onboarding_step_3_a">To allow Olpaka to communicate with Ollama, you'll need to set up CORS.</string>
<string name="onboarding_step_3_b">Once you've configured CORS, you can check whether Olpaka is able to communicate with Olpaka by using the button below.</string>
<string name="onboarding_step_3_b">Once you've configured CORS, you can check whether Olpaka is able to communicate with Ollama by using the button below.</string>
<string name="onboarding_step_3_c">If it still doesn't work try to restart Ollama before continuing.</string>
<string name="onboarding_download_ollama">Download Ollama</string>
<string name="onboarding_setup_cors">Setup CORS</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package androidx.compose.desktop.ui.tooling.preview

// Little workaround to make the Compose preview work even in the commonMain package
@OptIn(ExperimentalMultiplatform::class)
@OptionalExpectation
expect annotation class Preview()
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package org.cyanotic.olpaka.core

expect class FirebaseAnalytics() {
interface Analytics {
fun init()

fun screenView(screenName: String)

fun event(eventName: String, properties: Map<String,Any?> = emptyMap())
}

expect class FirebaseAnalytics() : Analytics {
override fun init()

override fun screenView(screenName: String)

override fun event(eventName: String, properties: Map<String,Any?>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@ package org.cyanotic.olpaka.core

import kotlinx.coroutines.flow.MutableStateFlow

class ModelDownloadState {
val currentDownloadState = MutableStateFlow(DownloadState.INACTIVE)
interface ModelDownloadState {
val currentDownloadState: MutableStateFlow<DownloadState>
fun setDownloading()
fun setCompleted()
fun setInactive()
}

class ModelDownloadStateDefault : ModelDownloadState {
override val currentDownloadState = MutableStateFlow(DownloadState.INACTIVE)

fun setDownloading() {
override fun setDownloading() {
currentDownloadState.value = DownloadState.DOWNLOADING
}

fun setCompleted() {
override fun setCompleted() {
currentDownloadState.value = DownloadState.COMPLETED
}

fun setInactive() {
override fun setInactive() {
currentDownloadState.value = DownloadState.INACTIVE
}
}
Expand Down
Loading

0 comments on commit 1796e49

Please sign in to comment.