I am trying to calculate exactly the cost incurred in use cases like this and wondering if someone from the forum can help me with reference or documentation or method to calculate the cost.
Here is the sample code I am using:
from langchain import OpenAI, SQLDatabase, SQLDatabaseChain
import os
os.environ["OPENAI_API_KEY"] = "YOUR_KEY"
db = SQLDatabase.from_uri("sqlite:///../../../../content/sqlite2.db")
llm = OpenAI(temperature=0, verbose=True)
db_chain = SQLDatabaseChain.from_llm(llm, db, verbose=True)
db_chain.run("Describe the playlisttrack table")
The output I got is:
Entering new SQLDatabaseChain chain...
Describe the playlisttrack table
SQLQuery:SELECT * FROM "PlaylistTrack" LIMIT 5;
SQLResult: [(1, 3402), (1, 3389), (1, 3390), (1, 3391), (1, 3392)]
Answer:The PlaylistTrack table contains two columns, PlaylistId and TrackId, which are both integers. It is used to store the relationship between playlists and tracks.
Finished chain.
'The PlaylistTrack table contains two columns, PlaylistId and TrackId, which are both integers. It is used to store the relationship between playlists and tracks.'
I want to know how to calculate the total tokens used in this call?
The db size is 1.87 MB but I am not sure if it is relevant.
When I check it on the usage dashboard after above query I got charged $0.13, which seems way high when I compare with the pricing mentioned on open API pricing page.
If I consider the max cost of gpt 3.5 turbo model which is 0.004 / 1k token $0.13 charge implies I have used approx 32k tokens. I want to know how the total tokens are calculated in this case?