[ai]
[添加title]
This commit is contained in:
yangyakun
2025-08-05 19:58:46 +08:00
parent 03d8a1c4cb
commit 16a625e5b8
5 changed files with 122 additions and 57 deletions

View File

@@ -7,6 +7,7 @@ import com.mogo.eagle.core.data.BaseData
import com.mogo.eagle.core.data.ai.V2XRepository
import com.mogo.eagle.core.data.map.MogoLocation
import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisLocationGCJ02Listener
import com.mogo.eagle.core.utilcode.util.UiThreadHandler
import com.mogo.och.unmanned.passenger.ui.aiview.bean.AIMessage
import com.mogo.mgintelligent.speech.AsrResult
import com.mogo.mgintelligent.speech.AsrState
@@ -23,9 +24,12 @@ import com.mogo.och.data.taxi.BaseOrderBean
import com.mogo.och.data.taxi.TaxiOrderStatusEnum
import com.mogo.och.unmanned.passenger.bean.ai.LatLonBody
import com.mogo.och.unmanned.passenger.network.ai.AiServiceManager
import com.mogo.och.unmanned.passenger.ui.aiview.bean.MGCommonTitleBean
import com.mogo.och.unmanned.taxi.utils.order.OrderListener
import com.mogo.och.unmanned.taxi.utils.order.OrderModel
import com.mogo.service.v2n.bean.MGEventExtInfoBean
import com.mogo.service.v2n.bean.MGLlmQueryBean
import com.mogo.service.v2n.utils.JsonUtil
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
@@ -119,6 +123,8 @@ class AIViewModel : ViewModel(), AIMessageManager.AIMessageListener, IWakeUpList
llmResultJob = viewModelScope.launch(Dispatchers.IO) {
V2XRepository.llmResultFlow.collect { result ->
Log.d(TAG, "llm result: $result")
val title = result.aiMsg?.title ?: ""
val suggestion = result.aiMsg?.suggestion ?: result.answer ?: ""
val msg = msgList.findLast { it.id == result.queryId }
@@ -127,18 +133,33 @@ class AIViewModel : ViewModel(), AIMessageManager.AIMessageListener, IWakeUpList
return@collect
}
AIMessageManager.post(
AIMessage.QA(
id = result.queryId,
title = result.answer,
tts = result.answer,
answer = result.answer,
question = msg.question,
state = AIMessage.QA.QuestionState.FINISH,
pictureUrl = result.imgUrls.getOrNull(0) ?: "",
pictureUrlList = result.imgUrls
)
)
if (result.aiMsg?.data != null) {
val data: MGCommonTitleBean? = result.aiMsg?.parseData()
val content = data?.title ?: ""
AIMessage.QA(
id = result.queryId,
title = title,
tts = content,
answer = content,
question = "",
pictureUrl = result.imgUrls.getOrNull(0) ?: "",
pictureUrlList = result.imgUrls,
)
}else{
AIMessageManager.post(
AIMessage.QA(
id = result.queryId,
title = result.answer,
tts = result.answer,
answer = suggestion,
question = msg.question,
state = AIMessage.QA.QuestionState.FINISH,
pictureUrl = result.imgUrls.getOrNull(0) ?: "",
pictureUrlList = result.imgUrls
)
)
}
}
}
}
@@ -381,5 +402,17 @@ sealed class AsrUIState {
data class Recognized(val finalText: String) : AsrUIState()
}
inline fun <reified T> MGEventExtInfoBean.parseData(): T? {
val TAG = "MGEventExtInfoBean"
return try {
JsonUtil.fromJson(this.data, T::class.java)
} catch (e: Exception) {
Log.e(TAG, "Failed parse data: ${e.message}")
null
}
}

View File

@@ -14,6 +14,7 @@ import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.widget.AppCompatImageView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat
import androidx.core.graphics.toColorInt
import androidx.recyclerview.widget.LinearLayoutManager
@@ -111,14 +112,14 @@ abstract class MessageViewHolder(view: View) : RecyclerView.ViewHolder(view) {
class QAViewHolder(val binding: View) : MessageViewHolder(binding) {
private var tvQuestion: TextView = binding.findViewById(R.id.tvQuestion)
private var tvAnswer: TextView = binding.findViewById(R.id.tvAnswer)
private var tvTitle: TextView = binding.findViewById(R.id.tvTitle)
private var tvTitleImage: TextView = binding.findViewById(R.id.tvTitleImage)
private var clContain: ConstraintLayout = binding.findViewById(R.id.clContain)
private var tvTimestamp: TextView = binding.findViewById(R.id.tvTimestamp)
private var tvStateContent: TextView = binding.findViewById(R.id.tvStateContent)
private var tvPncActionDesc: TextView = binding.findViewById(R.id.tvPncActionDesc)
// private var ivPicture: OchRoundImageView = binding.findViewById(R.id.ivPicture)
private var llState: LinearLayout = binding.findViewById(R.id.llState)
private var tvStateUnderstand: TextView = binding.findViewById(R.id.tvStateUnderstand)
private var tvStateAnalyze: TextView = binding.findViewById(R.id.tvStateAnalyze)
private var tvStateAnswer: TextView = binding.findViewById(R.id.tvStateAnswer)
private var picBanner = binding.findViewById<Banner<String,BannerImageAdapter>>(R.id.picBanner)
@@ -128,9 +129,19 @@ class QAViewHolder(val binding: View) : MessageViewHolder(binding) {
handleState(item.state)
tvQuestion.text = item.question
Log.d(TAG, "bind: ${item}")
tvAnswer.setTextAndVisibility(item.answer)
// ivPicture.showOrHideWithUrl(item.pictureUrl)
if(item.title==item.answer){
tvTitle.text = item.title
tvPncActionDesc.text = item.answer
tvTitle.visibility = View.VISIBLE
tvPncActionDesc.visibility = View.GONE
tvTitleImage.visibility = View.VISIBLE
}else{
tvTitle.text = item.title
tvPncActionDesc.text = item.answer
tvTitle.visibility = View.VISIBLE
tvPncActionDesc.visibility = View.VISIBLE
tvTitleImage.visibility = View.VISIBLE
}
handleTimestamp(item, tvTimestamp)
@@ -140,7 +151,6 @@ class QAViewHolder(val binding: View) : MessageViewHolder(binding) {
} else {
picBanner.visibility = View.VISIBLE
picBanner.setAdapter(BannerImageAdapter(pictureUrlList))
// .addBannerLifecycleObserver(picBanner.context) //添加生命周期观察者
.setIndicator(CircleIndicator(picBanner.context))
.setIndicatorSelectedColor("#40B4FF".toColorInt())
.setIndicatorNormalColor("#FFFFFF".toColorInt())
@@ -154,43 +164,32 @@ class QAViewHolder(val binding: View) : MessageViewHolder(binding) {
when (state) {
AIMessage.QA.QuestionState.UNDERSTAND -> {
llState.visibility = View.VISIBLE
clContain.visibility = View.GONE
tvStateContent.text = "正在理解问题…"
tvStateUnderstand.visibility = View.GONE
tvStateAnalyze.visibility = View.GONE
tvStateAnswer.visibility = View.GONE
}
AIMessage.QA.QuestionState.ANALYZE -> {
tvStateUnderstand.visibility = View.VISIBLE
llState.visibility = View.VISIBLE
clContain.visibility = View.GONE
tvStateContent.text = "正在分析处理…"
tvStateAnalyze.visibility = View.GONE
tvStateAnswer.visibility = View.GONE
}
AIMessage.QA.QuestionState.ANSWER -> {
tvStateUnderstand.visibility = View.VISIBLE
tvStateAnalyze.visibility = View.VISIBLE
llState.visibility = View.VISIBLE
clContain.visibility = View.GONE
tvStateContent.text = "正在总结回答…"
tvStateAnswer.visibility = View.GONE
}
AIMessage.QA.QuestionState.FINISH -> {
tvStateUnderstand.visibility = View.VISIBLE
tvStateAnalyze.visibility = View.VISIBLE
tvStateAnswer.visibility = View.VISIBLE
llState.visibility = View.GONE
clContain.visibility = View.VISIBLE
tvStateContent.text = ""
}
AIMessage.QA.QuestionState.ERROR -> {
tvStateUnderstand.visibility = View.VISIBLE
tvStateAnalyze.visibility = View.VISIBLE
tvStateAnswer.visibility = View.VISIBLE
clContain.visibility = View.VISIBLE
llState.visibility = View.GONE
tvStateContent.text = ""
}

View File

@@ -0,0 +1,4 @@
package com.mogo.och.unmanned.passenger.ui.aiview.bean
data class MGCommonTitleBean(
val title: String = "",
)

View File

@@ -42,21 +42,6 @@
android:orientation="vertical"
android:padding="31dp">
<TextView
android:id="@+id/tvStateUnderstand"
style="@style/AIMsgTextState"
android:text="理解问题" />
<TextView
android:id="@+id/tvStateAnalyze"
style="@style/AIMsgTextState"
android:text="分析处理" />
<TextView
android:id="@+id/tvStateAnswer"
style="@style/AIMsgTextState"
android:text="总结回答" />
<LinearLayout
android:id="@+id/llState"
android:layout_width="match_parent"
@@ -87,11 +72,55 @@
</LinearLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/clContain"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tvTitleImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#394047"
android:textSize="@dimen/sp_32"
android:visibility="gone"
tools:visibility="visible"
android:drawablePadding="@dimen/dp_7"
android:drawableStart="@drawable/icon_pnc_action"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:textStyle="bold"
/>
<TextView
app:layout_constraintTop_toTopOf="@+id/tvTitleImage"
app:layout_constraintBottom_toBottomOf="@+id/tvTitleImage"
app:layout_constraintStart_toEndOf="@+id/tvTitleImage"
android:layout_marginTop="0dp"
android:id="@+id/tvTitle"
android:visibility="gone"
tools:visibility="visible"
android:textStyle="bold"
style="@style/AIMsgTextTitle"
tools:text="前方道路施工" />
<TextView
android:id="@+id/tvPncActionDesc"
android:layout_width="@dimen/dp_0"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/tvTitleImage"
app:layout_constraintLeft_toLeftOf="@id/tvTitle"
app:layout_constraintBottom_toBottomOf="parent"
android:visibility="gone"
tools:visibility="visible"
android:textSize="@dimen/sp_32"
android:textColor="#394047"
android:layout_marginTop="@dimen/dp_10"
android:layout_marginBottom="@dimen/dp_26"
android:text="古城村滇池卫城我吃完传达传达出我擦撒擦擦车是擦擦" />
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="@+id/tvAnswer"
style="@style/AIMsgTextTitle"
tools:text="前方道路施工" />
<com.youth.banner.Banner
android:id="@+id/picBanner"

View File

@@ -90,7 +90,7 @@ dependencies {
api rootProject.ext.dependencies.mogochainbase
api rootProject.ext.dependencies.mogoservicebiz
api ('com.mogo.service:mogo-v2x-enhanced:1.3.8'){
api ('com.mogo.service:mogo-v2x-enhanced:1.3.37'){
exclude group: 'com.google.protobuf', module: 'protoc'
exclude group: 'com.google.protobuf', module: 'protobuf-java'
exclude group: 'com.google.protobuf', module: 'protobuf-java-util'