add done_reason to the api (#4235)

This commit is contained in:
Bruce MacDonald 2024-05-09 13:30:14 -07:00 committed by GitHub
parent 1580ed4c06
commit cfa84b8470
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 44 additions and 40 deletions

View file

@ -107,15 +107,9 @@ func toChatCompletion(id string, r api.ChatResponse) ChatCompletion {
Model: r.Model,
SystemFingerprint: "fp_ollama",
Choices: []Choice{{
Index: 0,
Message: Message{Role: r.Message.Role, Content: r.Message.Content},
FinishReason: func(done bool) *string {
if done {
reason := "stop"
return &reason
}
return nil
}(r.Done),
Index: 0,
Message: Message{Role: r.Message.Role, Content: r.Message.Content},
FinishReason: &r.DoneReason,
}},
Usage: Usage{
// TODO: ollama returns 0 for prompt eval if the prompt was cached, but openai returns the actual count
@ -135,15 +129,9 @@ func toChunk(id string, r api.ChatResponse) ChatCompletionChunk {
SystemFingerprint: "fp_ollama",
Choices: []ChunkChoice{
{
Index: 0,
Delta: Message{Role: "assistant", Content: r.Message.Content},
FinishReason: func(done bool) *string {
if done {
reason := "stop"
return &reason
}
return nil
}(r.Done),
Index: 0,
Delta: Message{Role: "assistant", Content: r.Message.Content},
FinishReason: &r.DoneReason,
},
},
}