feat: support deepseek (#69)

The DeepSeek API reduces costs through disk caching, and DeepSeek-Coder-V2-0724 achieves GPT-4-Turbo-0409 level code capabilities with excellent math and reasoning skills.
This commit is contained in:
Chao Li
2024-08-18 21:33:45 +08:00
committed by GitHub
parent b979b3d8ce
commit 6bef72e287
3 changed files with 35 additions and 5 deletions

View File

@@ -17,6 +17,7 @@ local E = {
openai = "OPENAI_API_KEY",
claude = "ANTHROPIC_API_KEY",
azure = "AZURE_OPENAI_API_KEY",
deepseek = "DEEPSEEK_API_KEY",
},
_once = false,
}
@@ -298,6 +299,23 @@ local function call_openai_api_stream(question, code_lang, code_content, selecte
max_tokens = Config.azure.max_tokens,
stream = true,
}
elseif Config.provider == "deepseek" then
api_key = os.getenv(E.key("deepseek"))
url = Utils.trim_suffix(Config.deepseek.endpoint, "/") .. "/chat/completions"
headers = {
["Content-Type"] = "application/json",
["Authorization"] = "Bearer " .. api_key,
}
body = {
model = Config.deepseek.model,
messages = {
{ role = "system", content = system_prompt },
{ role = "user", content = user_prompt },
},
temperature = Config.deepseek.temperature,
max_tokens = Config.deepseek.max_tokens,
stream = true,
}
else
url = Utils.trim_suffix(Config.openai.endpoint, "/") .. "/v1/chat/completions"
headers = {
@@ -364,7 +382,7 @@ end
---@param on_chunk fun(chunk: string): any
---@param on_complete fun(err: string|nil): any
function M.call_ai_api_stream(question, code_lang, code_content, selected_content_content, on_chunk, on_complete)
if Config.provider == "openai" or Config.provider == "azure" then
if Config.provider == "openai" or Config.provider == "azure" or Config.provider == "deepseek" then
call_openai_api_stream(question, code_lang, code_content, selected_content_content, on_chunk, on_complete)
elseif Config.provider == "claude" then
call_claude_api_stream(question, code_lang, code_content, selected_content_content, on_chunk, on_complete)