mirror of
https://github.com/lfnovo/open-notebook.git
synced 2026-04-28 19:40:50 +00:00
Version 1 (#160)
New front-end Launch Chat API Manage Sources Enable re-embedding of all contents Sources can be added without a notebook now Improved settings Enable model selector on all chats Background processing for better experience Dark mode Improved Notes Improved Docs: - Remove all Streamlit references from documentation - Update deployment guides with React frontend setup - Fix Docker environment variables format (SURREAL_URL, SURREAL_PASSWORD) - Update docker image tag from :latest to :v1-latest - Change navigation references (Settings → Models to just Models) - Update development setup to include frontend npm commands - Add MIGRATION.md guide for users upgrading from Streamlit - Update quick-start guide with correct environment variables - Add port 5055 documentation for API access - Update project structure to reflect frontend/ directory - Remove outdated source-chat documentation files
This commit is contained in:
parent
124d7d110c
commit
b7e656a319
319 changed files with 46747 additions and 7408 deletions
38
open_notebook/utils/token_utils.py
Normal file
38
open_notebook/utils/token_utils.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
"""
|
||||
Token utilities for Open Notebook.
|
||||
Handles token counting and cost calculations for language models.
|
||||
"""
|
||||
|
||||
|
||||
def token_count(input_string: str) -> int:
|
||||
"""
|
||||
Count the number of tokens in the input string using the 'o200k_base' encoding.
|
||||
|
||||
Args:
|
||||
input_string (str): The input string to count tokens for.
|
||||
|
||||
Returns:
|
||||
int: The number of tokens in the input string.
|
||||
"""
|
||||
try:
|
||||
import tiktoken
|
||||
encoding = tiktoken.get_encoding("o200k_base")
|
||||
tokens = encoding.encode(input_string)
|
||||
return len(tokens)
|
||||
except ImportError:
|
||||
# Fallback: simple word count estimation
|
||||
return int(len(input_string.split()) * 1.3)
|
||||
|
||||
|
||||
def token_cost(token_count: int, cost_per_million: float = 0.150) -> float:
|
||||
"""
|
||||
Calculate the cost of tokens based on the token count and cost per million tokens.
|
||||
|
||||
Args:
|
||||
token_count (int): The number of tokens.
|
||||
cost_per_million (float): The cost per million tokens. Default is 0.150.
|
||||
|
||||
Returns:
|
||||
float: The calculated cost for the given token count.
|
||||
"""
|
||||
return cost_per_million * (token_count / 1_000_000)
|
||||
Loading…
Add table
Add a link
Reference in a new issue