Skip to content

Commit

Permalink
fix chatCompletion token metrics + complete grok model integration
Browse files Browse the repository at this point in the history
  • Loading branch information
fegloff committed Oct 27, 2024
1 parent a6bdd3d commit 36955f5
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 13 deletions.
8 changes: 6 additions & 2 deletions src/modules/llms/api/athropic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ export const anthropicCompletion = async (
model
},
usage: totalOutputTokens + totalInputTokens,
price: 0
price: 0,
inputTokens: parseInt(totalInputTokens, 10),
outputTokens: parseInt(totalOutputTokens, 10)
}
}
return {
Expand Down Expand Up @@ -93,7 +95,9 @@ export const xaiCompletion = async (
model
},
usage: totalOutputTokens + totalInputTokens,
price: 0
price: 0,
inputTokens: parseInt(totalInputTokens, 10),
outputTokens: parseInt(totalOutputTokens, 10)
}
}
return {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/llms/api/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export async function chatCompletion (
content: response.choices[0].message?.content ?? 'Error - no completion available',
role: 'assistant'
},
usage: 2010, // response.usage?.total_tokens,
usage: response.usage?.total_tokens, // 2010
price: price * config.openAi.chatGpt.priceAdjustment,
inputTokens,
outputTokens
Expand Down
1 change: 0 additions & 1 deletion src/modules/llms/llmsBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,6 @@ export abstract class LlmsBase implements PayableBot {
const response = await this.chatCompletion(conversation, model, usesTools, parameters)
if (response.completion) {
if (model === this.modelsEnum.O1) {
console.log(response.completion)
const msgs = splitTelegramMessage(response.completion.content as string)
await ctx.api.editMessageText(
ctx.chat.id,
Expand Down
8 changes: 4 additions & 4 deletions src/modules/llms/utils/llmsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@ export const llmData: LLMData = {
fullName: 'Grok',
botName: 'xAIBot',
version: 'grok-beta',
commands: ['gk', 'grok'],
prefix: ['gk. '],
commands: ['gk', 'grok', 'x'],
prefix: ['gk. ', 'x. '],
apiSpec: 'https://docs.x.ai/api#introduction',
inputPrice: 0.00500,
outputPrice: 0.01500,
inputPrice: 0.005,
outputPrice: 0.015,
maxContextTokens: 131072,
chargeType: 'TOKEN',
stream: false
Expand Down
4 changes: 0 additions & 4 deletions src/modules/llms/xaiBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
type OnCallBackQueryData,
type ChatConversation
} from '../types'
import { SupportedCommands } from './utils/helpers'
import { type LlmCompletion } from './api/llmApi'
import { xaiCompletion } from './api/athropic'
import { LlmsBase } from './llmsBase'
Expand All @@ -27,9 +26,6 @@ export class XaiBot extends LlmsBase {
): boolean {
const hasCommand = ctx.hasCommand(this.supportedCommands)

if (ctx.hasCommand(SupportedCommands.new) && this.checkModel(ctx)) {
return true
}
const chatPrefix = this.hasPrefix(ctx.message?.text ?? '')
if (chatPrefix !== '') {
return true
Expand Down
1 change: 0 additions & 1 deletion src/modules/payment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,6 @@ export class BotPayments {
from.username
}] credits total: ${totalCreditsAmount.toFixed()}, to withdraw: ${totalPayAmount.toFixed()}, total balance after: ${totalBalanceDelta.toFixed()}`
)

if (totalBalanceDelta.gte(0)) {
const { userPayment, userCredits: userCreditsAfter } = await chatService.withdrawCredits(accountId, totalPayAmount)
this.logger.info(`[${from.id} @${
Expand Down

0 comments on commit 36955f5

Please sign in to comment.