-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
138 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
app/src/main/java/com/mo/sh/studyassistant/data/network/GeminiApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.mo.sh.studyassistant.data.network | ||
|
||
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.HarmCategory | ||
import com.google.ai.client.generativeai.type.SafetySetting | ||
import com.google.ai.client.generativeai.type.generationConfig | ||
|
||
|
||
class GeminiApi { | ||
|
||
private val safetySettings = listOf( | ||
SafetySetting(HarmCategory.HARASSMENT, BlockThreshold.ONLY_HIGH), | ||
SafetySetting(HarmCategory.HATE_SPEECH, BlockThreshold.ONLY_HIGH), | ||
SafetySetting(HarmCategory.DANGEROUS_CONTENT, BlockThreshold.ONLY_HIGH), | ||
SafetySetting(HarmCategory.SEXUALLY_EXPLICIT, BlockThreshold.ONLY_HIGH), | ||
) | ||
private val temp = 0.4f | ||
private val candidates = 1 | ||
|
||
|
||
suspend fun generateMessage( | ||
history: List<Content>, | ||
message: String, | ||
key: String | ||
): String? { | ||
val generativeModel = GenerativeModel( | ||
modelName = "gemini-1.0-pro-latest", | ||
apiKey = key, | ||
generationConfig = generationConfig { | ||
temperature = temp | ||
maxOutputTokens = 1024 | ||
candidateCount = candidates | ||
}, | ||
safetySettings = safetySettings | ||
) | ||
return generativeModel.startChat( | ||
history | ||
).sendMessage(message).text | ||
} | ||
|
||
suspend fun generateText( | ||
prompt: String, | ||
key: String, | ||
): String? { | ||
val generativeModel = GenerativeModel( | ||
modelName = "gemini-1.0-pro-latest", | ||
apiKey = key, | ||
generationConfig = generationConfig { | ||
temperature = temp | ||
maxOutputTokens = 2048 | ||
candidateCount = candidates | ||
}, | ||
safetySettings = safetySettings | ||
) | ||
return generativeModel.generateContent(prompt).text | ||
} | ||
|
||
} |
9 changes: 0 additions & 9 deletions
9
app/src/main/java/com/mo/sh/studyassistant/data/network/NetworkConstants.kt
This file was deleted.
Oops, something went wrong.
50 changes: 0 additions & 50 deletions
50
app/src/main/java/com/mo/sh/studyassistant/data/network/PalmApi.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.