Merge pull request #1791 from anon998/add-logprobs-to-custom-openai

Add logprobs support for custom OpenAI APIs
This commit is contained in:
Cohee 2024-02-05 01:31:06 +02:00 committed by GitHub
commit d192c5ae7f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 2 deletions

View File

@ -1617,7 +1617,7 @@ async function sendOpenAIRequest(type, messages, signal) {
}
// Add logprobs request (currently OpenAI only, max 5 on their side)
if (useLogprobs && isOAI) {
if (useLogprobs && (isOAI || isCustom)) {
generate_data['logprobs'] = 5;
}
@ -1768,6 +1768,7 @@ function parseChatCompletionLogprobs(data) {
switch (oai_settings.chat_completion_source) {
case chat_completion_sources.OPENAI:
case chat_completion_sources.CUSTOM:
if (!data.choices?.length) {
return null;
}

View File

@ -751,7 +751,16 @@ router.post('/generate', jsonParser, function (request, response) {
apiUrl = request.body.custom_url;
apiKey = readSecret(SECRET_KEYS.CUSTOM);
headers = {};
bodyParams = {};
bodyParams = {
logprobs: request.body.logprobs,
};
// Adjust logprobs params for Chat Completions API, which expects { top_logprobs: number; logprobs: boolean; }
if (!isTextCompletion && bodyParams.logprobs > 0) {
bodyParams.top_logprobs = bodyParams.logprobs;
bodyParams.logprobs = true;
}
mergeObjectWithYaml(bodyParams, request.body.custom_include_body);
mergeObjectWithYaml(headers, request.body.custom_include_headers);
} else {