@@ -39,9 +39,18 @@ public final class GeminiService: LLMStreamService {
39
39
result. isStreamFinished = false
40
40
41
41
let queryType = queryType ( text: text, from: from, to: to)
42
- let translationPrompt = promptContent ( queryType: queryType, text: text, from: from, to: to)
43
- let systemInstruction = queryType == . dictionary ? LLMStreamService . dictSystemPrompt : LLMStreamService
42
+ let chatHistory = promptContent ( queryType: queryType, text: text, from: from, to: to)
43
+ let systemPrompt = queryType == . dictionary ? LLMStreamService
44
+ . dictSystemPrompt : LLMStreamService
44
45
. translationSystemPrompt
46
+
47
+ var systemInstruction : ModelContent ? = try ModelContent ( role: " system " , systemPrompt)
48
+
49
+ // !!!: gemini-1.0-pro model does not support system instruction https://github.com/google-gemini/generative-ai-python/issues/328
50
+ if model == GeminiModel . gemini1_0_pro. rawValue {
51
+ systemInstruction = nil
52
+ }
53
+
45
54
let model = GenerativeModel (
46
55
name: model,
47
56
apiKey: apiKey,
@@ -58,7 +67,7 @@ public final class GeminiService: LLMStreamService {
58
67
59
68
// Gemini Docs: https://github.com/google/generative-ai-swift
60
69
61
- let outputContentStream = model. generateContentStream ( translationPrompt )
70
+ let outputContentStream = model. generateContentStream ( chatHistory )
62
71
for try await outputContent in outputContentStream {
63
72
guard let line = outputContent. text else {
64
73
return
@@ -196,9 +205,7 @@ extension GeminiService {
196
205
chats. append ( chat)
197
206
}
198
207
}
199
- guard !chats. isEmpty else {
200
- return chats
201
- }
208
+
202
209
return chats
203
210
}
204
211
}
0 commit comments