Skip to content

Commit

Permalink
Merge pull request #50 from ihatenumbers/main
Browse files Browse the repository at this point in the history
fix togetherai (openai-compatible)
  • Loading branch information
lmg-anon authored Apr 20, 2024
2 parents b13c5bd + b5be7a1 commit 4a67aae
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions mikupad.html
Original file line number Diff line number Diff line change
Expand Up @@ -917,9 +917,9 @@
return await koboldCppTokenCount({ endpoint, signal, ...options });
case 3: // openai
// OpenAI itself doesn't have a token count endpoint...
if (new URL(endpoint).host === 'api.openai.com')
if (new URL(endpoint).host === 'api.openai.com' || new URL(endpoint).host === 'api.together.xyz')
return 0;
if (options.realEndpoint && new URL(options.realEndpoint).host === 'api.openai.com')
if (options.realEndpoint && new URL(options.realEndpoint).host === 'api.openai.com' || new URL(options.realEndpoint).host === 'api.together.xyz')
return 0;

// Each backend that exposes an OpenAI-compatible API may have a different token count endpoint.
Expand Down Expand Up @@ -1247,7 +1247,9 @@
return data.map(item => item.id);
}

function openaiConvertOptions(options, isOpenAI) {
function openaiConvertOptions(options, realEndpoint){
const isOpenAI = realEndpoint.toLowerCase().includes("openai.com");
const isTogetherAI = realEndpoint.toLowerCase().includes("together.xyz");
const swapOption = (lhs, rhs) => {
if (lhs in options) {
options[rhs] = options[lhs];
Expand Down Expand Up @@ -1278,6 +1280,12 @@
swapOption("tfs_z", "tfs");
swapOption("mirostat", "mirostat_mode");
swapOption("ignore_eos", "ban_eos_token")

if (isTogetherAI) {
// errors 400 without this.
delete options.logprobs;
}

return options;
}

Expand All @@ -1292,7 +1300,7 @@
...(realEndpoint ? { 'X-Real-URL': realEndpoint } : {})
},
body: JSON.stringify({
...openaiConvertOptions(options, endpoint.toLowerCase().includes("openai.com")),
...openaiConvertOptions(options, realEndpoint),
stream: true,
}),
signal,
Expand Down

0 comments on commit 4a67aae

Please sign in to comment.