Skip to content

Commit

Permalink
Upgrade Anthropic package to 0.3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
kharvd committed Jul 12, 2023
1 parent 0e2a78d commit eb1a416
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions gptcli/anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def get_client():
if not api_key:
raise ValueError("ANTHROPIC_API_KEY environment variable not set")

return anthropic.Client(api_key)
return anthropic.Anthropic(api_key=api_key)


def role_to_name(role: str) -> str:
Expand All @@ -38,7 +38,7 @@ def complete(
kwargs = {
"prompt": make_prompt(messages),
"stop_sequences": [anthropic.HUMAN_PROMPT],
"max_tokens_to_sample": 2048,
"max_tokens_to_sample": 4096,
"model": args["model"],
}
if "temperature" in args:
Expand All @@ -48,21 +48,21 @@ def complete(

client = get_client()
if stream:
response = client.completion_stream(**kwargs)
response = client.completions.create(**kwargs, stream=True)
else:
response = [client.completion(**kwargs)]
response = [client.completions.create(**kwargs, stream=False)]

prev_completion = ""
for data in response:
next_completion = data["completion"]
yield next_completion[len(prev_completion) :]
prev_completion = next_completion
next_completion = data.completion
yield next_completion


def num_tokens_from_messages_anthropic(messages: List[Message], model: str) -> int:
prompt = make_prompt(messages)
return anthropic.count_tokens(prompt)
client = get_client()
return client.count_tokens(prompt)


def num_tokens_from_completion_anthropic(message: Message, model: str) -> int:
return anthropic.count_tokens(message["content"])
client = get_client()
return client.count_tokens(message["content"])
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ classifiers = [
"Topic :: Scientific/Engineering :: Artificial Intelligence",
]
dependencies = [
"anthropic==0.2.8",
"anthropic==0.3.4",
"black==23.1.0",
"google-generativeai==0.1.0",
"openai==0.27.8",
Expand Down

0 comments on commit eb1a416

Please sign in to comment.