Skip to content

Commit

Permalink
fix: support legacy finish_reason (yetone#706)
Browse files Browse the repository at this point in the history
Many OpenAI compatible alternative servers are still returning a
`finish_reason` of `eos_token` instead of `stop`. This commit adds
support for that to support more of these servers/options.
  • Loading branch information
abatilo authored Oct 11, 2024
1 parent faaa7f2 commit f92c3a6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lua/avante/providers/openai.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ local P = require("avante.providers")
---
---@class OpenAIResponseChoiceComplete
---@field message OpenAIMessage
---@field finish_reason "stop" | "length"
---@field finish_reason "stop" | "length" | "eos_token"
---@field index integer
---@field logprobs integer
---
Expand Down Expand Up @@ -84,7 +84,7 @@ M.parse_response = function(data_stream, _, opts)
local json = vim.json.decode(data_stream)
if json.choices and json.choices[1] then
local choice = json.choices[1]
if choice.finish_reason == "stop" then
if choice.finish_reason == "stop" or choice.finish_reason == "eos_token" then
opts.on_complete(nil)
elseif choice.delta.content then
if choice.delta.content ~= vim.NIL then opts.on_chunk(choice.delta.content) end
Expand Down

0 comments on commit f92c3a6

Please sign in to comment.