|
|
@@ -6,6 +6,7 @@ import androidx.lifecycle.MutableLiveData
|
|
|
import com.nova.brain.glass.model.ChatItem
|
|
|
import com.nova.brain.glass.model.ChatModel
|
|
|
import com.nova.brain.glass.model.ChatModel1
|
|
|
+import com.nova.brain.glass.model.ChatModel2
|
|
|
import com.nova.brain.glass.model.data.ChatData
|
|
|
import com.nova.brain.glass.repository.Service
|
|
|
import com.xuqm.base.common.GsonImplHelp
|
|
|
@@ -50,6 +51,7 @@ class ChatVM : BaseListViewModel<ChatItem>() {
|
|
|
.subscribeOn(Schedulers.io())
|
|
|
.subscribe({ body ->
|
|
|
var content = ""
|
|
|
+ var currentType = "" // 追踪当前阶段:reason / string
|
|
|
body.charStream().buffered().use { reader ->
|
|
|
try {
|
|
|
var line: String?
|
|
|
@@ -80,9 +82,24 @@ class ChatVM : BaseListViewModel<ChatItem>() {
|
|
|
result.postValue(msg)
|
|
|
return@use
|
|
|
}
|
|
|
- if (model.role != "assistant" || model.type != "string") continue
|
|
|
- val model1 = GsonImplHelp.get().toObject(json, ChatModel1::class.java)
|
|
|
- content += model1.data
|
|
|
+ if (model.role != "assistant") continue
|
|
|
+ when (model.type) {
|
|
|
+ "reason" -> {
|
|
|
+ val m = GsonImplHelp.get().toObject(json, ChatModel2::class.java)
|
|
|
+ content += m.data.content
|
|
|
+ currentType = "reason"
|
|
|
+ }
|
|
|
+ "string" -> {
|
|
|
+ if (currentType != "string") {
|
|
|
+ // 第一条 string:清除 reason 阶段的内容,重新开始
|
|
|
+ content = ""
|
|
|
+ currentType = "string"
|
|
|
+ }
|
|
|
+ val m = GsonImplHelp.get().toObject(json, ChatModel1::class.java)
|
|
|
+ content += m.data
|
|
|
+ }
|
|
|
+ else -> continue
|
|
|
+ }
|
|
|
val lastIndex = chatItems.size - 1
|
|
|
if (lastIndex >= 0) {
|
|
|
chatItems[lastIndex].content = content
|