Comments (5)
Yes, this library will support it in v1.2.0,During this time I'm developing and testing
from gpt-tokens.
@Cainier while you develop it can you give me a clue how can I do it by myself?
from gpt-tokens.
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.
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.
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)
- Don't surpport gpt-4-0613 HOT 1
- Requesting your help with gpt-tokens project
- messages token count algorithm is different from the one in openAI official cookbook HOT 1
- Error while importing in React HOT 2
- Counts are slightly off on completion for chat models HOT 3
- js-tiktoken 性能太差了
- Is there really a discount on gpt-3.5-turbo for Plus users? HOT 4
- Tiktoken encodings not re-used between GPTTokens instances (slow performance) HOT 2
- Add openai finetune model support HOT 1
- How to disable warnings? HOT 2
- [Idea] self-discipline plugin
- Add gpt-4-0125-preview HOT 4
- Import is broken HOT 1
- Throw an error when content contains <|endoftext|>
- Is it possible to support gpt-4-vision-preview
- How to count tokens for cl100k_base embedding?
- new GPTTokens() sometime fails with RuntimeError: unreachable HOT 2
- there exists memeory leak in this package HOT 5
- Support for the latest gpt-3.5-turbo-16k model HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gpt-tokens.