Skip to content

Commit

Permalink
feat(vertex): support token counting
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertCraigie committed Dec 17, 2024
1 parent 5db8538 commit 6c3eded
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/anthropic/lib/vertex/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,15 @@ def _prepare_options(input_options: FinalRequestOptions, *, project_id: str | No

options.url = f"/projects/{project_id}/locations/{region}/publishers/anthropic/models/{model}:{specifier}"

if options.url in {"/v1/messages/count_tokens", "/v1/messages/count_tokens?beta=true"} and options.method == "post":
if project_id is None:
raise RuntimeError(
"No project_id was given and it could not be resolved from credentials. The client should be instantiated with the `project_id` argument or the `ANTHROPIC_VERTEX_PROJECT_ID` environment variable should be set."
)

if is_dict(options.json_data):
options.json_data.pop("model", None)
options.json_data.pop("anthropic_version", None)

options.url = f"/projects/{project_id}/locations/{region}/publishers/anthropic/models/count-tokens:rawPredict"

return options

0 comments on commit 6c3eded

Please sign in to comment.