From bd654e7aac566989fa8d9f431f4e6e87ac881cce Mon Sep 17 00:00:00 2001 From: Parshva Daftari <89991302+parshvadaftari@users.noreply.github.com> Date: Fri, 5 Jul 2024 21:24:04 +0530 Subject: [PATCH] Fixed Docs for the Token Usage (#1461) Co-authored-by: parshvadaftari --- docs/components/llms.mdx | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/docs/components/llms.mdx b/docs/components/llms.mdx index e3e695c4..c2cae52c 100644 --- a/docs/components/llms.mdx +++ b/docs/components/llms.mdx @@ -842,7 +842,7 @@ answer = app.query("What is the net worth of Elon Musk today?") ## Token Usage -You can get the cost of the query by setting `token_usage` to `True` in the config file. This will return the token details: `input_tokens`, `output_tokens`, `total_cost`. +You can get the cost of the query by setting `token_usage` to `True` in the config file. This will return the token details: `prompt_tokens`, `completion_tokens`, `total_tokens`, `total_cost`, `cost_currency`. The list of paid LLMs that support token usage are: - OpenAI - Vertex AI @@ -863,14 +863,24 @@ app = App.from_config(config_path="config.yaml") app.add("https://www.forbes.com/profile/elon-musk") -response, token_usage = app.query("what is the net worth of Elon Musk?") -# Elon Musk's net worth is $209.9 billion as of 6/9/24. -# {'input_tokens': 1228, 'output_tokens': 21, 'total_cost (USD)': 0.001884} +response = app.query("what is the net worth of Elon Musk?") +# {'answer': 'Elon Musk's net worth is $209.9 billion as of 6/9/24.', +# 'usage': {'prompt_tokens': 1228, +# 'completion_tokens': 21, +# 'total_tokens': 1249, +# 'total_cost': 0.001884, +# 'cost_currency': 'USD'} +# } -response, token_usage = app.chat("Which companies did Elon Musk found?") -# Elon Musk founded six companies, including Tesla, which is an electric car maker, SpaceX, a rocket producer, and the Boring Company, a tunneling startup. -# {'input_tokens': 1616, 'output_tokens': 34, 'total_cost (USD)': 0.002492} +response = app.chat("Which companies did Elon Musk found?") +# {'answer': 'Elon Musk founded six companies, including Tesla, which is an electric car maker, SpaceX, a rocket producer, and the Boring Company, a tunneling startup.', +# 'usage': {'prompt_tokens': 1616, +# 'completion_tokens': 34, +# 'total_tokens': 1650, +# 'total_cost': 0.002492, +# 'cost_currency': 'USD'} +# } ``` ```yaml config.yaml