mirror of
https://github.com/NovaOSS/nova-betterchat.git
synced 2024-11-25 20:13:59 +01:00
update token cost to prompt + completion
This commit is contained in:
parent
b7b3c0ec75
commit
bd0f91f1a2
|
@ -17,9 +17,10 @@ const tokenCostToCost = (
|
||||||
model: ModelOptions
|
model: ModelOptions
|
||||||
) => {
|
) => {
|
||||||
if (!tokenCost) return 0;
|
if (!tokenCost) return 0;
|
||||||
const { price, unit } = modelCost[model as keyof typeof modelCost];
|
const { prompt, completion } = modelCost[model as keyof typeof modelCost];
|
||||||
const completionCost = (price / unit) * tokenCost.completionTokens;
|
const completionCost =
|
||||||
const promptCost = (price / unit) * tokenCost.promptTokens;
|
(completion.price / completion.unit) * tokenCost.completionTokens;
|
||||||
|
const promptCost = (prompt.price / prompt.unit) * tokenCost.promptTokens;
|
||||||
return completionCost + promptCost;
|
return completionCost + promptCost;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,9 @@ const TokenCount = React.memo(() => {
|
||||||
);
|
);
|
||||||
|
|
||||||
const cost = useMemo(() => {
|
const cost = useMemo(() => {
|
||||||
const price = modelCost[model].price * (tokenCount / modelCost[model].unit);
|
const price =
|
||||||
|
modelCost[model].prompt.price *
|
||||||
|
(tokenCount / modelCost[model].prompt.unit);
|
||||||
return price.toPrecision(3);
|
return price.toPrecision(3);
|
||||||
}, [model, tokenCount]);
|
}, [model, tokenCount]);
|
||||||
|
|
||||||
|
|
|
@ -38,12 +38,30 @@ export const modelMaxToken = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const modelCost = {
|
export const modelCost = {
|
||||||
'gpt-3.5-turbo': { price: 0.002, unit: 1000 },
|
'gpt-3.5-turbo': {
|
||||||
'gpt-3.5-turbo-0301': { price: 0.002, unit: 1000 },
|
prompt: { price: 0.002, unit: 1000 },
|
||||||
'gpt-4': { price: 0.03, unit: 1000 },
|
completion: { price: 0.002, unit: 1000 },
|
||||||
'gpt-4-0314': { price: 0.03, unit: 1000 },
|
},
|
||||||
'gpt-4-32k': { price: 0.06, unit: 1000 },
|
'gpt-3.5-turbo-0301': {
|
||||||
'gpt-4-32k-0314': { price: 0.06, unit: 1000 },
|
prompt: { price: 0.002, unit: 1000 },
|
||||||
|
completion: { price: 0.002, unit: 1000 },
|
||||||
|
},
|
||||||
|
'gpt-4': {
|
||||||
|
prompt: { price: 0.03, unit: 1000 },
|
||||||
|
completion: { price: 0.06, unit: 1000 },
|
||||||
|
},
|
||||||
|
'gpt-4-0314': {
|
||||||
|
prompt: { price: 0.03, unit: 1000 },
|
||||||
|
completion: { price: 0.06, unit: 1000 },
|
||||||
|
},
|
||||||
|
'gpt-4-32k': {
|
||||||
|
prompt: { price: 0.06, unit: 1000 },
|
||||||
|
completion: { price: 0.12, unit: 1000 },
|
||||||
|
},
|
||||||
|
'gpt-4-32k-0314': {
|
||||||
|
prompt: { price: 0.06, unit: 1000 },
|
||||||
|
completion: { price: 0.12, unit: 1000 },
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const defaultUserMaxToken = 4000;
|
export const defaultUserMaxToken = 4000;
|
||||||
|
@ -57,7 +75,10 @@ export const _defaultChatConfig: ConfigInterface = {
|
||||||
frequency_penalty: 0,
|
frequency_penalty: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const generateDefaultChat = (title?: string, folder?: string): ChatInterface => ({
|
export const generateDefaultChat = (
|
||||||
|
title?: string,
|
||||||
|
folder?: string
|
||||||
|
): ChatInterface => ({
|
||||||
id: uuidv4(),
|
id: uuidv4(),
|
||||||
title: title ? title : 'New Chat',
|
title: title ? title : 'New Chat',
|
||||||
messages:
|
messages:
|
||||||
|
@ -66,7 +87,7 @@ export const generateDefaultChat = (title?: string, folder?: string): ChatInterf
|
||||||
: [],
|
: [],
|
||||||
config: { ...useStore.getState().defaultChatConfig },
|
config: { ...useStore.getState().defaultChatConfig },
|
||||||
titleSet: false,
|
titleSet: false,
|
||||||
folder
|
folder,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const codeLanguageSubset = [
|
export const codeLanguageSubset = [
|
||||||
|
|
Loading…
Reference in a new issue