File tree 1 file changed +18
-10
lines changed
1 file changed +18
-10
lines changed Original file line number Diff line number Diff line change @@ -107,9 +107,14 @@ func toChatCompletion(id string, r api.ChatResponse) ChatCompletion {
107
107
Model : r .Model ,
108
108
SystemFingerprint : "fp_ollama" ,
109
109
Choices : []Choice {{
110
- Index : 0 ,
111
- Message : Message {Role : r .Message .Role , Content : r .Message .Content },
112
- FinishReason : & r .DoneReason ,
110
+ Index : 0 ,
111
+ Message : Message {Role : r .Message .Role , Content : r .Message .Content },
112
+ FinishReason : func (reason string ) * string {
113
+ if len (reason ) > 0 {
114
+ return & reason
115
+ }
116
+ return nil
117
+ }(r .DoneReason ),
113
118
}},
114
119
Usage : Usage {
115
120
// TODO: ollama returns 0 for prompt eval if the prompt was cached, but openai returns the actual count
@@ -127,13 +132,16 @@ func toChunk(id string, r api.ChatResponse) ChatCompletionChunk {
127
132
Created : time .Now ().Unix (),
128
133
Model : r .Model ,
129
134
SystemFingerprint : "fp_ollama" ,
130
- Choices : []ChunkChoice {
131
- {
132
- Index : 0 ,
133
- Delta : Message {Role : "assistant" , Content : r .Message .Content },
134
- FinishReason : & r .DoneReason ,
135
- },
136
- },
135
+ Choices : []ChunkChoice {{
136
+ Index : 0 ,
137
+ Delta : Message {Role : "assistant" , Content : r .Message .Content },
138
+ FinishReason : func (reason string ) * string {
139
+ if len (reason ) > 0 {
140
+ return & reason
141
+ }
142
+ return nil
143
+ }(r .DoneReason ),
144
+ }},
137
145
}
138
146
}
139
147
You can’t perform that action at this time.
0 commit comments