Giter VIP home page Giter VIP logo

Comments (5)

Cainier avatar Cainier commented on August 26, 2024 4

Yes, this library will support it in v1.2.0,During this time I'm developing and testing

from gpt-tokens.

finom avatar finom commented on August 26, 2024

@Cainier while you develop it can you give me a clue how can I do it by myself?

from gpt-tokens.

finom avatar finom commented on August 26, 2024

Who still wondering how to do that there is a snippet of code that you can run once when server is started to get real usage of tokens by functions.

void (async () => {
  const result = await createCompletion({
    model: MODEL,
    messages: [{ content: '', role: 'user' }],
    stream: false,
    functionCall: 'auto',
    temperature: 0,
  });

  console.log('result', result.fullResponse?.usage?.prompt_tokens);
})(); 

from gpt-tokens.

vlrevolution avatar vlrevolution commented on August 26, 2024

Yes, this library will support it in v1.2.0,During this time I'm developing and testing

How's it going?

from gpt-tokens.

Cainier avatar Cainier commented on August 26, 2024

I added it in 1.2.0, Using the npm package openai-chat-tokens

https://hmarr.com/blog/counting-openai-tokens/

But it has not been rigorously tested

you can use it in v1.2.0 like this

import { GPTTokens } from 'gpt-tokens'

const usageInfo = new GPTTokens({
    model   : 'gpt-3.5-turbo-1106',
    messages: [
        { role: 'user', content: 'What\'s the weather like in San Francisco and Paris?' },
    ],
    tools   : [
        {
            type    : 'function',
            function: {
                name       : 'get_current_weather',
                description: 'Get the current weather in a given location',
                parameters : {
                    type      : 'object',
                    properties: {
                        location: {
                            type       : 'string',
                            description: 'The city and state, e.g. San Francisco, CA',
                        },
                        unit    : {
                            type: 'string',
                            enum: ['celsius', 'fahrenheit'],
                        },
                    },
                    required  : ['location'],
                },
            },
        },
    ]
})

console.info('Used tokens: ', usageInfo.usedTokens)
console.info('Used USD: ',    usageInfo.usedUSD)

from gpt-tokens.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.