Skip to content

Commit 36955f5

Browse files
committed
fix chatCompletion token metrics + complete grok model integration
1 parent a6bdd3d commit 36955f5

File tree

6 files changed

+11
-13
lines changed

6 files changed

+11
-13
lines changed

src/modules/llms/api/athropic.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ export const anthropicCompletion = async (
5252
model
5353
},
5454
usage: totalOutputTokens + totalInputTokens,
55-
price: 0
55+
price: 0,
56+
inputTokens: parseInt(totalInputTokens, 10),
57+
outputTokens: parseInt(totalOutputTokens, 10)
5658
}
5759
}
5860
return {
@@ -93,7 +95,9 @@ export const xaiCompletion = async (
9395
model
9496
},
9597
usage: totalOutputTokens + totalInputTokens,
96-
price: 0
98+
price: 0,
99+
inputTokens: parseInt(totalInputTokens, 10),
100+
outputTokens: parseInt(totalOutputTokens, 10)
97101
}
98102
}
99103
return {

src/modules/llms/api/openai.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export async function chatCompletion (
127127
content: response.choices[0].message?.content ?? 'Error - no completion available',
128128
role: 'assistant'
129129
},
130-
usage: 2010, // response.usage?.total_tokens,
130+
usage: response.usage?.total_tokens, // 2010
131131
price: price * config.openAi.chatGpt.priceAdjustment,
132132
inputTokens,
133133
outputTokens

src/modules/llms/llmsBase.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,6 @@ export abstract class LlmsBase implements PayableBot {
402402
const response = await this.chatCompletion(conversation, model, usesTools, parameters)
403403
if (response.completion) {
404404
if (model === this.modelsEnum.O1) {
405-
console.log(response.completion)
406405
const msgs = splitTelegramMessage(response.completion.content as string)
407406
await ctx.api.editMessageText(
408407
ctx.chat.id,

src/modules/llms/utils/llmsData.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,11 @@ export const llmData: LLMData = {
171171
fullName: 'Grok',
172172
botName: 'xAIBot',
173173
version: 'grok-beta',
174-
commands: ['gk', 'grok'],
175-
prefix: ['gk. '],
174+
commands: ['gk', 'grok', 'x'],
175+
prefix: ['gk. ', 'x. '],
176176
apiSpec: 'https://docs.x.ai/api#introduction',
177-
inputPrice: 0.00500,
178-
outputPrice: 0.01500,
177+
inputPrice: 0.005,
178+
outputPrice: 0.015,
179179
maxContextTokens: 131072,
180180
chargeType: 'TOKEN',
181181
stream: false

src/modules/llms/xaiBot.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
type OnCallBackQueryData,
55
type ChatConversation
66
} from '../types'
7-
import { SupportedCommands } from './utils/helpers'
87
import { type LlmCompletion } from './api/llmApi'
98
import { xaiCompletion } from './api/athropic'
109
import { LlmsBase } from './llmsBase'
@@ -27,9 +26,6 @@ export class XaiBot extends LlmsBase {
2726
): boolean {
2827
const hasCommand = ctx.hasCommand(this.supportedCommands)
2928

30-
if (ctx.hasCommand(SupportedCommands.new) && this.checkModel(ctx)) {
31-
return true
32-
}
3329
const chatPrefix = this.hasPrefix(ctx.message?.text ?? '')
3430
if (chatPrefix !== '') {
3531
return true

src/modules/payment/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,6 @@ export class BotPayments {
441441
from.username
442442
}] credits total: ${totalCreditsAmount.toFixed()}, to withdraw: ${totalPayAmount.toFixed()}, total balance after: ${totalBalanceDelta.toFixed()}`
443443
)
444-
445444
if (totalBalanceDelta.gte(0)) {
446445
const { userPayment, userCredits: userCreditsAfter } = await chatService.withdrawCredits(accountId, totalPayAmount)
447446
this.logger.info(`[${from.id} @${

0 commit comments

Comments
 (0)