Skip to content

Commit

Permalink
Fix empty stop in the official OpenAI endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
lmg-anon committed Apr 16, 2024
1 parent 0691107 commit d0968c5
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions mikupad.html
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,15 @@
return await llamaCppTokenCount({ endpoint, endpointAPIKey, signal, ...options });
case 2: // koboldcpp
return await koboldCppTokenCount({ endpoint, signal, ...options });
case 3: // openai // TODO: Fix this for official OpenAI?
case 3: // openai
// OpenAI itself doesn't have a token count endpoint...
if (new URL(endpoint).host === 'api.openai.com')
return 0;
if (options.realEndpoint && new URL(options.realEndpoint).host === 'api.openai.com')
return 0;

// Each backend that exposes an OpenAI-compatible API may have a different token count endpoint.
// Instead of asking the user which backend they are using, let's try each one.
let tokenCount = 0;
tokenCount = await openaiAphroditeTokenCount({ endpoint, endpointAPIKey, signal, ...options });
if (tokenCount != -1)
Expand Down Expand Up @@ -2455,7 +2463,6 @@
repeat_last_n: repeatLastN,
penalize_nl: penalizeNl,
ignore_eos: ignoreEos,
stop: JSON.parse(stoppingStrings) || [],
} : {}),
presence_penalty: presencePenalty,
frequency_penalty: frequencyPenalty,
Expand All @@ -2474,6 +2481,7 @@
}),
n_predict: maxPredictTokens,
n_probs: 10,
...(JSON.parse(stoppingStrings).length ? { stop: JSON.parse(stoppingStrings) } : {}),
signal: ac.signal,
...(isMikupadEndpoint ? { endpoint: sessionStorage.proxyEndpoint, realEndpoint: endpoint } : {})
})) {
Expand Down

0 comments on commit d0968c5

Please sign in to comment.