Skip to content

Commit

Permalink
Merge pull request #2 from Taewan-P/dev
Browse files Browse the repository at this point in the history
Update safety settings for Gemini
  • Loading branch information
Taewan-P authored Jun 21, 2024
2 parents a95b2db + eb03b2c commit 095c9b6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import com.aallam.openai.api.chat.ChatRole
import com.aallam.openai.api.model.ModelId
import com.aallam.openai.client.OpenAI
import com.google.ai.client.generativeai.GenerativeModel
import com.google.ai.client.generativeai.type.BlockThreshold
import com.google.ai.client.generativeai.type.Content
import com.google.ai.client.generativeai.type.GenerateContentResponse
import com.google.ai.client.generativeai.type.HarmCategory
import com.google.ai.client.generativeai.type.SafetySetting
import com.google.ai.client.generativeai.type.content
import dev.chungjungsoo.gptmobile.data.database.dao.ChatRoomDao
import dev.chungjungsoo.gptmobile.data.database.dao.MessageDao
Expand Down Expand Up @@ -90,7 +93,11 @@ class ChatRepositoryImpl @Inject constructor(
google = GenerativeModel(
modelName = platform.model ?: "",
apiKey = platform.token ?: "",
systemInstruction = content { text(ModelConstants.GOOGLE_PROMPT) }
systemInstruction = content { text(ModelConstants.GOOGLE_PROMPT) },
safetySettings = listOf(
SafetySetting(HarmCategory.DANGEROUS_CONTENT, BlockThreshold.ONLY_HIGH),
SafetySetting(HarmCategory.SEXUALLY_EXPLICIT, BlockThreshold.NONE)
)
)

val inputContent = messageToGoogleMessage(history)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fun HomeScreen(
modifier = Modifier.padding(innerPadding),
state = listState
) {
item { ChatsTitle() }
item { ChatsTitle(scrollBehavior) }
items(chatList, key = { it.id }) { chatRoom ->
val usingPlatform = chatRoom.enabledPlatform.joinToString(", ") { platformTitles[it] ?: "" }
ListItem(
Expand Down Expand Up @@ -163,13 +163,15 @@ fun HomeTopAppBar(
)
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun ChatsTitle() {
private fun ChatsTitle(scrollBehavior: TopAppBarScrollBehavior) {
Text(
modifier = Modifier
.padding(top = 32.dp)
.padding(horizontal = 20.dp, vertical = 16.dp),
text = stringResource(R.string.chats),
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 1.0F - scrollBehavior.state.overlappedFraction),
style = MaterialTheme.typography.headlineLarge
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ fun PlatformSettingScreen(
val platform = platformState.firstOrNull { it.name == apiType }
val enabled = platform?.enabled ?: false
val model = platform?.model
val token = platform?.token

PreferenceSwitchWithContainer(
title = stringResource(R.string.enable_api),
Expand All @@ -109,6 +110,7 @@ fun PlatformSettingScreen(
SettingItem(
modifier = Modifier.height(64.dp),
title = stringResource(R.string.api_key),
description = token?.let { stringResource(R.string.token_set, it[0]) } ?: stringResource(R.string.token_not_set),
enabled = enabled,
onItemClick = { isApiTokenDialogOpen = true },
showTrailingIcon = false,
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-ko-rKR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,6 @@
<string name="ask_a_question">질문을 입력하세요…</string>
<string name="some_platforms_disabled">일부 API가 비활성화되었습니다</string>
<string name="claude_3_5_sonnet_description">Anthropic사의 가장 지능적인 모델입니다.</string>
<string name="token_not_set">토큰이 설정되지 않았습니다.</string>
<string name="token_set">토큰이 설정되었습니다: %s*****</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,6 @@
<string name="openai_brand_text" translatable="false">Powered by OpenAI</string>
<string name="anthropic_brand_text" translatable="false">Powered by Claude</string>
<string name="google_brand_text" translatable="false">Powered by Gemini</string>
<string name="token_not_set">Token not set</string>
<string name="token_set">Token is set as %s*****</string>
</resources>

0 comments on commit 095c9b6

Please sign in to comment.