Skip to content

Commit ff09ce7

Browse files
authored
genai: add SystemInstruction (#84)
1 parent 359cfe8 commit ff09ce7

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

genai/client.go

+11-7
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ type GenerativeModel struct {
105105
GenerationConfig
106106
SafetySettings []*SafetySetting
107107
Tools []*Tool
108-
ToolConfig *ToolConfig
108+
ToolConfig *ToolConfig // configuration for tools
109+
// SystemInstruction (also known as "system prompt") is a more forceful prompt to the model.
110+
// The model will adhere the instructions more strongly than if they appeared in a normal prompt.
111+
SystemInstruction *Content
109112
}
110113

111114
// GenerativeModel creates a new instance of the named generative model.
@@ -165,12 +168,13 @@ func (m *GenerativeModel) generateContent(ctx context.Context, req *pb.GenerateC
165168

166169
func (m *GenerativeModel) newGenerateContentRequest(contents ...*Content) *pb.GenerateContentRequest {
167170
return &pb.GenerateContentRequest{
168-
Model: m.fullName,
169-
Contents: support.TransformSlice(contents, (*Content).toProto),
170-
SafetySettings: support.TransformSlice(m.SafetySettings, (*SafetySetting).toProto),
171-
Tools: support.TransformSlice(m.Tools, (*Tool).toProto),
172-
ToolConfig: m.ToolConfig.toProto(),
173-
GenerationConfig: m.GenerationConfig.toProto(),
171+
Model: m.fullName,
172+
Contents: support.TransformSlice(contents, (*Content).toProto),
173+
SafetySettings: support.TransformSlice(m.SafetySettings, (*SafetySetting).toProto),
174+
Tools: support.TransformSlice(m.Tools, (*Tool).toProto),
175+
ToolConfig: m.ToolConfig.toProto(),
176+
GenerationConfig: m.GenerationConfig.toProto(),
177+
SystemInstruction: m.SystemInstruction.toProto(),
174178
}
175179
}
176180

genai/example_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ func ExampleGenerativeModel_GenerateContent_config() {
5959
model.SetTopP(0.5)
6060
model.SetTopK(20)
6161
model.SetMaxOutputTokens(100)
62+
model.SystemInstruction = &genai.Content{
63+
Parts: []genai.Part{genai.Text("You are Yoda from Star Wars.")},
64+
}
6265
resp, err := model.GenerateContent(ctx, genai.Text("What is the average size of a swallow?"))
6366
if err != nil {
6467
log.Fatal(err)

0 commit comments

Comments
 (0)