Skip to content

Commit

Permalink
add SystemInstruction as a param to GenerativeModel and wire it throu… (
Browse files Browse the repository at this point in the history
#112)

…gh common

Co-authored-by: David Motsonashvili <davidmotson@google.com>
Co-authored-by: Rodrigo Lazo <rlazo@users.noreply.github.com>
  • Loading branch information
3 people committed Apr 9, 2024
1 parent 1fddbab commit 69b5610
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ data class GenerateContentRequest(
@SerialName("generation_config") val generationConfig: GenerationConfig? = null,
val tools: List<Tool>? = null,
@SerialName("tool_config") var toolConfig: ToolConfig? = null,
@SerialName("system_instruction") val systemInstruction: Content? = null,
) : Request

@Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import org.json.JSONObject
* @property generationConfig configuration parameters to use for content generation
* @property safetySettings the safety bounds to use during alongside prompts during content
* generation
* @property systemInstruction contains a [Content] that directs the model to behave a certain way
* @property requestOptions configuration options to utilize during backend communication
*/
@OptIn(ExperimentalSerializationApi::class)
Expand All @@ -69,6 +70,7 @@ internal constructor(
val safetySettings: List<SafetySetting>? = null,
val tools: List<Tool>? = null,
val toolConfig: ToolConfig? = null,
val systemInstruction: Content? = null,
val requestOptions: RequestOptions = RequestOptions(),
private val controller: APIController,
) {
Expand All @@ -81,6 +83,7 @@ internal constructor(
safetySettings: List<SafetySetting>? = null,
tools: List<Tool>? = null,
toolConfig: ToolConfig? = null,
systemInstruction: Content? = null,
requestOptions: RequestOptions = RequestOptions(),
) : this(
modelName,
Expand All @@ -89,12 +92,13 @@ internal constructor(
safetySettings,
tools,
toolConfig,
systemInstruction?.let { Content("system", it.parts) },
requestOptions,
APIController(
apiKey,
modelName,
requestOptions.toInternal(),
"genai-android/${BuildConfig.VERSION_NAME}"
"genai-android/${BuildConfig.VERSION_NAME}",
),
)

Expand Down Expand Up @@ -235,6 +239,7 @@ internal constructor(
generationConfig?.toInternal(),
tools?.map { it.toInternal() },
toolConfig?.toInternal(),
systemInstruction?.toInternal(),
)

private fun constructCountTokensRequest(vararg prompt: Content) =
Expand Down

0 comments on commit 69b5610

Please sign in to comment.