I am working onbuilding an own chatbot introducing my own data. I already did but my surprise was the amount of tokens are counted. Here there is a real example:
Prompt: “y qué es una estructura de precio?”
Completion: “Una estructura de precio se refiere a una horquilla de ofertas de compra y ofertas de venta que hay en un activo financiero, que condiciona la formación de precios de los mercados financieros. Los precios se determinan por la oferta y demanda de un activo, y por los conflictos entre compradores y vendedores.”
Here you can see how openai counted those tokens:
19:10
Local time: 15 may 2023, 21:10
text-davinci, 2 requests
1,673 prompt + 112 completion = 1,785 tokens
19:10
Local time: 15 may 2023, 21:10
text-embedding-ada-002-v2, 1 request
9 prompt + 0 completion = 9 tokens
During those minutes ONLY that query explained at the beginning was made.
I am using chat history in order to follow the conversation having. Here is the code:
@bot.message_handler(func=lambda msg: True)
def echo_all(message):
global qa, chat_history
try:
result = qa({"question": message.text, "chat_history": chat_history})
chat_history = [(message, result["answer"])]
bot.reply_to(message, result["answer"])
except:
bot.reply_to(message, "Actívame pulsando /start.")
Actually I am only interacting with openai in order to fill the variable “result”. This means 2 requests for davinci and 1 request to embedding ada. Can someone explain how this countability works?
Thanks!
Ramon.