mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-04-25 00:36:55 +02:00
update cluade token count
This commit is contained in:
parent
79390a2824
commit
ed54cc6e28
2 changed files with 12 additions and 8 deletions
|
|
@ -406,13 +406,17 @@ SPARK_TOKENS = {
|
|||
def count_message_tokens(messages, model="gpt-3.5-turbo-0125"):
|
||||
"""Return the number of tokens used by a list of messages."""
|
||||
if "claude" in model:
|
||||
# rough estimation for models newer than claude-2.1
|
||||
vo = anthropic.Client()
|
||||
num_tokens = 0
|
||||
for message in messages:
|
||||
for key, value in message.items():
|
||||
num_tokens += vo.count_tokens(str(value))
|
||||
return num_tokens
|
||||
# rough estimation for models newer than claude-2.1, needs api_key or auth_token
|
||||
ac = anthropic.Client()
|
||||
system_prompt = ""
|
||||
new_messages = []
|
||||
for msg in messages:
|
||||
if msg.get("role") == "system":
|
||||
system_prompt = msg.get("content")
|
||||
else:
|
||||
new_messages.append(msg)
|
||||
num_tokens = ac.beta.messages.count_tokens(messages=new_messages, model=model, system=system_prompt)
|
||||
return num_tokens.get("input_tokens", 0)
|
||||
try:
|
||||
encoding = tiktoken.encoding_for_model(model)
|
||||
except KeyError:
|
||||
|
|
|
|||
2
setup.py
2
setup.py
|
|
@ -98,7 +98,7 @@ extras_require["android_assistant"] = [
|
|||
|
||||
setup(
|
||||
name="metagpt",
|
||||
version="0.8.1",
|
||||
version="1.0.0",
|
||||
description="The Multi-Agent Framework",
|
||||
long_description=long_description,
|
||||
long_description_content_type="text/markdown",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue