-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: restore intro message and costs calculation (#69)
* fix: restore intro message and costs calculation * debug command
- Loading branch information
1 parent
d5c5de5
commit f348057
Showing
11 changed files
with
112 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,27 @@ | ||
import { type Message } from '@callstack/byorg-core'; | ||
import { ModelUsage, type Message } from '@callstack/byorg-core'; | ||
|
||
export const messages: Message[] = []; | ||
|
||
export const totalUsage: ModelUsage = { | ||
inputTokens: 0, | ||
outputTokens: 0, | ||
requests: 0, | ||
responseTime: 0, | ||
model: '', | ||
usedTools: {}, | ||
}; | ||
|
||
export function resetUsage() { | ||
totalUsage.inputTokens = 0; | ||
totalUsage.outputTokens = 0; | ||
totalUsage.requests = 0; | ||
totalUsage.responseTime = 0; | ||
} | ||
|
||
export function updateUsage(usage: ModelUsage) { | ||
totalUsage.inputTokens += usage.inputTokens; | ||
totalUsage.outputTokens += usage.outputTokens; | ||
totalUsage.requests += usage.requests; | ||
totalUsage.responseTime += usage.responseTime; | ||
totalUsage.model = usage.model; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
export const texts = { | ||
userLabel: 'me:', | ||
assistantLabel: 'ai:', | ||
initialHelp: 'Type "/exit" or press Ctrl+C to exit. Type "/help" to see available commands.', | ||
responseLoading: 'Thinking ...', | ||
initialHelp: 'Type "/exit" or press Ctrl+C to exit. Type "/help" to see available commands.\n', | ||
} as const; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { ModelUsage } from '@callstack/byorg-core'; | ||
import { Provider } from '../../engine/providers/provider.js'; | ||
import { ProviderConfig } from '../../engine/providers/config.js'; | ||
|
||
export type CostContext = { | ||
provider: Provider; | ||
providerConfig: ProviderConfig; | ||
}; | ||
|
||
export function calculateUsageCost(usage: Partial<ModelUsage>, context: CostContext) { | ||
const pricing = getModelPricing(usage, context); | ||
if (pricing === undefined) { | ||
return undefined; | ||
} | ||
|
||
const inputCost = ((usage.inputTokens ?? 0) * (pricing.inputTokensCost ?? 0)) / 1_000_000; | ||
const outputCost = ((usage.outputTokens ?? 0) * (pricing.outputTokensCost ?? 0)) / 1_000_000; | ||
const requestsCost = ((usage.requests ?? 0) * (pricing.requestsCost ?? 0)) / 1_000_000; | ||
return inputCost + outputCost + requestsCost; | ||
} | ||
|
||
function getModelPricing(usage: Partial<ModelUsage>, { provider, providerConfig }: CostContext) { | ||
return ( | ||
provider.modelPricing[usage.model ?? providerConfig.model] ?? | ||
provider.modelPricing[providerConfig.model] | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters