Skip to content

Commit a186dd3

Browse files
committed
fix あくまでembeddingなのでsafety外す
1 parent 4778f7f commit a186dd3

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

backend/infrastructure/llm/gemini.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ const (
1616
ModelEmbedding = "gemini-embedding-001"
1717
)
1818

19+
// noSafetySettings は全カテゴリの安全フィルターを無効にする設定
20+
// 日記アプリでは個人の記録を正確に処理するためブロックなしとする
21+
var noSafetySettings = []*genai.SafetySetting{
22+
{Category: genai.HarmCategoryHateSpeech, Threshold: genai.HarmBlockThresholdBlockNone},
23+
{Category: genai.HarmCategoryDangerousContent, Threshold: genai.HarmBlockThresholdBlockNone},
24+
{Category: genai.HarmCategorySexuallyExplicit, Threshold: genai.HarmBlockThresholdBlockNone},
25+
{Category: genai.HarmCategoryHarassment, Threshold: genai.HarmBlockThresholdBlockNone},
26+
}
27+
1928
// DiaryChunkData はLLMが生成したチャンクの内容と概要を保持する
2029
type DiaryChunkData struct {
2130
// Content チャンクの元テキスト(ベクトル化対象)
@@ -71,7 +80,8 @@ n日:箇条書き3
7180

7281
zero := float32(0)
7382
config := &genai.GenerateContentConfig{
74-
Temperature: &zero,
83+
Temperature: &zero,
84+
SafetySettings: noSafetySettings,
7585
}
7686

7787
resp, err := g.client.Models.GenerateContent(ctx, ModelGenerateContent, contents, config)
@@ -117,7 +127,8 @@ func (g *GeminiClient) GenerateDailySummary(ctx context.Context, diaryContent st
117127

118128
zero := float32(0)
119129
config := &genai.GenerateContentConfig{
120-
Temperature: &zero,
130+
Temperature: &zero,
131+
SafetySettings: noSafetySettings,
121132
}
122133

123134
resp, err := g.client.Models.GenerateContent(ctx, ModelGenerateContent, contents, config)
@@ -260,6 +271,7 @@ activities(活動・行動):
260271
config := &genai.GenerateContentConfig{
261272
ResponseMIMEType: "application/json",
262273
ResponseSchema: schema,
274+
SafetySettings: noSafetySettings,
263275
}
264276

265277
resp, err := g.client.Models.GenerateContent(ctx, ModelGenerateContent, contents, config)
@@ -353,6 +365,7 @@ func (g *GeminiClient) SplitDiaryIntoChunks(ctx context.Context, content string)
353365
Temperature: &zero,
354366
ResponseMIMEType: "application/json",
355367
ResponseSchema: schema,
368+
SafetySettings: noSafetySettings,
356369
}
357370

358371
resp, err := g.client.Models.GenerateContent(ctx, ModelGenerateContent, contents, config)
@@ -458,6 +471,7 @@ func (g *GeminiClient) GenerateHighlights(ctx context.Context, diaryContent stri
458471
Temperature: &zero,
459472
ResponseMIMEType: "application/json",
460473
ResponseSchema: schema,
474+
SafetySettings: noSafetySettings,
461475
}
462476

463477
resp, err := g.client.Models.GenerateContent(ctx, ModelGenerateContent, contents, config)

0 commit comments

Comments
 (0)