mirror of
https://github.com/cpacker/MemGPT.git
synced 2025-06-03 04:30:22 +00:00
feat: added token counter command to CLI (#2047)
This commit is contained in:
parent
82058d2077
commit
e5a7fc406d
@ -1582,6 +1582,10 @@ class Agent(BaseAgent):
|
|||||||
functions_definitions=available_functions_definitions,
|
functions_definitions=available_functions_definitions,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def count_tokens(self) -> int:
|
||||||
|
"""Count the tokens in the current context window"""
|
||||||
|
return self.get_context_window().context_window_size_current
|
||||||
|
|
||||||
|
|
||||||
def save_agent(agent: Agent, ms: MetadataStore):
|
def save_agent(agent: Agent, ms: MetadataStore):
|
||||||
"""Save agent to metadata store"""
|
"""Save agent to metadata store"""
|
||||||
|
@ -254,6 +254,15 @@ def run_agent_loop(
|
|||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
elif user_input.lower() == "/tokens":
|
||||||
|
tokens = letta_agent.count_tokens()
|
||||||
|
typer.secho(
|
||||||
|
f"{tokens}/{letta_agent.agent_state.llm_config.context_window}",
|
||||||
|
fg=typer.colors.GREEN,
|
||||||
|
bold=True,
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
|
||||||
elif user_input.lower().startswith("/add_function"):
|
elif user_input.lower().startswith("/add_function"):
|
||||||
try:
|
try:
|
||||||
if len(user_input) < len("/add_function "):
|
if len(user_input) < len("/add_function "):
|
||||||
|
Loading…
Reference in New Issue
Block a user