增加星火大模型的model按钮;修改配置文件的字段;更改部分逻辑过程。现在大模型的类型也可以选择了。

This commit is contained in:
2024-09-19 19:56:55 +08:00
parent 8438091990
commit a217b7c06b
6 changed files with 195 additions and 33 deletions

View File

@@ -1,6 +1,8 @@
package com.example.flomo_ai
import android.annotation.SuppressLint
import android.os.Bundle
import android.graphics.Color
import android.widget.Button
import android.widget.EditText
import android.widget.LinearLayout
@@ -8,13 +10,13 @@ import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import java.util.UUID
class SecondActivity : AppCompatActivity() {
private lateinit var etApiName: EditText
private lateinit var etApiUrl: EditText
private lateinit var etApiKey: EditText
private lateinit var etApiSecretKey: EditText
private lateinit var etApiModel: EditText
private lateinit var btnSave: Button
private lateinit var llConfigList: LinearLayout
@@ -49,6 +51,7 @@ class SecondActivity : AppCompatActivity() {
etApiUrl = findViewById(R.id.etApiUrl)
etApiKey = findViewById(R.id.etApiKey)
etApiSecretKey = findViewById(R.id.etApiSecretKey)
etApiModel = findViewById(R.id.etApiModel)
btnSave = findViewById(R.id.btnSave)
llConfigList = findViewById(R.id.llConfigList)
}
@@ -73,11 +76,12 @@ class SecondActivity : AppCompatActivity() {
val url = etApiUrl.text.toString()
val key = etApiKey.text.toString()
val secretKey = etApiSecretKey.text.toString()
val model = etApiModel.text.toString()
// 生成唯一的 id
val id = System.currentTimeMillis()
// 创建新的配置项
val newConfig = APIConfig(id, name, url, key, secretKey)
val newConfig = APIConfig(id, name, url, key, secretKey, model)
// 添加配置项
configs.add(newConfig)
// 保存配置
@@ -93,11 +97,12 @@ class SecondActivity : AppCompatActivity() {
val url = etApiUrl.text.toString()
val key = etApiKey.text.toString()
val secretKey = etApiSecretKey.text.toString()
val model = etApiModel.text.toString()
// 获取编辑的配置项 id
val id = editingId ?: return
// 更新配置项
val updatedConfig = APIConfig(id, name, url, key, secretKey)
val updatedConfig = APIConfig(id, name, url, key, secretKey, model)
val existingConfigIndex = configs.indexOfFirst { it.id == id }
if (existingConfigIndex != -1) {
configs[existingConfigIndex] = updatedConfig
@@ -113,6 +118,7 @@ class SecondActivity : AppCompatActivity() {
}
@SuppressLint("MissingInflatedId")
private fun displayConfigs() {
llConfigList.removeAllViews()
for (config in configs) {
@@ -121,24 +127,30 @@ class SecondActivity : AppCompatActivity() {
// 设置各项文本信息
// 获取并设置 Name 的 TextView 前景色和背景色
val tvName = configView.findViewById<TextView>(R.id.tvName)
tvName.setTextColor(resources.getColor(R.color.background_color))
tvName.text = "Name: ${config.name}"
tvName.setTextColor(Color.BLACK)
// 获取并设置 URL 的 TextView 前景色和背景色
val tvUrl = configView.findViewById<TextView>(R.id.tvUrl)
tvUrl.setTextColor(resources.getColor(R.color.background_color))
tvUrl.text = "URL: ${config.url}"
tvUrl.setTextColor(Color.BLACK)
// 获取并设置 Key 的 TextView 前景色和背景色
val tvKey = configView.findViewById<TextView>(R.id.tvKey).also {
it.setTextColor(resources.getColor(R.color.background_color))
}
val tvKey = configView.findViewById<TextView>(R.id.tvKey)
tvKey.text = "Key: ${config.key.take(4)}..."
tvKey.setTextColor(Color.BLACK)
// 获取并设置 SecretKey 的 TextView 前景色和背景色
val tvSecretKey = configView.findViewById<TextView>(R.id.tvSecretKey)
tvSecretKey.setTextColor(resources.getColor(R.color.background_color))
tvSecretKey.text = "Secret Key: ${config.secretKey.take(4)}..."
tvSecretKey.setTextColor(Color.BLACK)
// 获取并设置 model 的 TextView 前景色和背景色
val tvApiModel = configView.findViewById<TextView>(R.id.tvApiModel)
tvApiModel.text = "Model: ${config.model}"
tvApiModel.setTextColor(Color.BLACK)
// 设置编辑按钮点击事件
configView.findViewById<Button>(R.id.btnEdit).setOnClickListener {
@@ -176,6 +188,7 @@ class SecondActivity : AppCompatActivity() {
etApiUrl.text.clear()
etApiKey.text.clear()
etApiSecretKey.text.clear()
etApiModel.text.clear()
btnSave.text = "保存配置"
}
}
@@ -185,5 +198,6 @@ data class APIConfig(
val name: String,
val url: String,
val key: String,
val secretKey: String
val secretKey: String,
val model: String
)