MCPcopy Create free account
hub / github.com/Xyntopia/taskyon / enrichWithDelayedUsageInfos

Function enrichWithDelayedUsageInfos

src/modules/chat.ts:629–677  ·  view source on GitHub ↗
(
  generationId: string,
  chatState: ChatStateType,
  task: LLMTask
)

Source from the content-addressed store, hash-verified

627}
628
629export function enrichWithDelayedUsageInfos(
630 generationId: string,
631 chatState: ChatStateType,
632 task: LLMTask
633) {
634 void sleep(5000).then(() => {
635 const headers: Record<string, string> = generateHeaders(chatState);
636 void axios
637 .get<OpenRouterGenerationInfo>(
638 `https://openrouter.ai/api/v1/generation?id=${generationId}`,
639 { headers }
640 )
641 .then((generation) => {
642 console.log('received costs for task');
643 if (generation) {
644 const generationInfo = generation.data.data;
645
646 if (
647 generationInfo.native_tokens_completion &&
648 generationInfo.native_tokens_prompt
649 ) {
650 // we get the useage data very often in an asynchronous form.
651 // thats why we need to
652 // openai sends back the exact number of prompt tokens :)
653 task.debugging.promptTokens = generationInfo.native_tokens_prompt;
654 task.debugging.resultTokens =
655 generationInfo.native_tokens_completion;
656 task.debugging.taskCosts = generationInfo.usage;
657 task.debugging.taskTokens =
658 generationInfo.native_tokens_prompt +
659 generationInfo.native_tokens_completion;
660 for (const childID of task.childrenIDs) {
661 const child = chatState.Tasks[childID];
662 if (!child.debugging.promptTokens) {
663 child.debugging.promptTokens = task.debugging.resultTokens;
664 }
665 }
666 }
667 }
668 })
669 .catch((err) => {
670 console.log(
671 'failed to get cost information for Openrouter.ai: ',
672 generationId,
673 err
674 );
675 });
676 });
677}
678
679async function uploadFileToOpenAI(
680 file: File,

Callers 1

processChatTaskFunction · 0.90

Calls 2

sleepFunction · 0.90
generateHeadersFunction · 0.85

Tested by

no test coverage detected