File tree Expand file tree Collapse file tree 1 file changed +14
-6
lines changed
openai-core/src/main/scala/io/cequence/openaiscala/service/adapter Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -53,18 +53,26 @@ object MessageConversions {
53
53
54
54
def filterOutToThinkEndFlow : Flow [Seq [ChunkMessageSpec ], Seq [ChunkMessageSpec ], NotUsed ] = {
55
55
Flow [Seq [ChunkMessageSpec ]].statefulMapConcat { () =>
56
- var foundEnd = false
56
+ var startOutput : Option [ Boolean ] = None
57
57
58
58
(messages : Seq [ChunkMessageSpec ]) => {
59
- if (foundEnd) {
60
- List (messages)
59
+ if (startOutput.isDefined) {
60
+ val nonEmptyLineFound = messages.exists(_.content.exists(_.trim.nonEmpty))
61
+
62
+ if (nonEmptyLineFound)
63
+ startOutput = Some (true )
64
+
65
+ if (startOutput.get)
66
+ List (messages)
67
+ else
68
+ List (messages.map(_.copy(content = None )))
61
69
} else {
62
70
val endFoundInThisChunk =
63
71
messages.exists(_.content.exists(_.trim.matches(thinkEndTagRegex)))
64
72
65
- if (endFoundInThisChunk) {
66
- foundEnd = true
67
- }
73
+ if (endFoundInThisChunk)
74
+ startOutput = Some ( false )
75
+
68
76
List (messages.map(_.copy(content = None )))
69
77
}
70
78
}
You can’t perform that action at this time.
0 commit comments