Skip to content

Commit

Permalink
Merge pull request #18 from st1vms/issue-17
Browse files Browse the repository at this point in the history
`model_name` defaults to None (latest model)
  • Loading branch information
st1vms authored Mar 7, 2024
2 parents f6f6742 + d525b77 commit af2c1ba
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,16 @@ __________

### Changing Claude model

In case you have accounts that are unable to migrate to newer models, you can override the `model_name` string parameter of `ClaudeAPIClient` constructor.
In case you have accounts that are unable to migrate to latest model, you can override the `model_name` string parameter of `ClaudeAPIClient` constructor.

```py
from claude2_api.client import ClaudeAPIClient
from claude2_api.session import SessionData

session = SessionData(...)

# Defaults to claude-2.1
# Defaults to None (latest Claude model)
# Can be either claude-2.0 or claude-2.1
client = ClaudeAPIClient(session, model_name="claude-2.0")
```

Expand Down
23 changes: 13 additions & 10 deletions claude2_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ class ClaudeAPIClient:
def __init__(
self,
session: SessionData,
model_name: str = None,
proxy: ClaudeProxyT = None,
model_name: str = "claude-2.1",
timeout: float = 240,
) -> None:
"""
Expand All @@ -134,9 +134,9 @@ def __init__(
Raises `ValueError` in case of failure
"""
if model_name not in {"claude-2.0", "claude-2.1"}:
if model_name is not None and model_name not in {"claude-2.0", "claude-2.1"}:
raise ValueError(
"model_name must be either one of 'claude-2.0' or 'claude-2.1' strings"
"model_name must be either None or one of 'claude-2.0' or 'claude-2.1' strings"
)

self.model_name: str = model_name
Expand Down Expand Up @@ -567,14 +567,17 @@ def send_message(
+ f"{chat_id}/completion"
)

payload = {
"attachments": attachments,
"files": [],
"prompt": prompt,
"timezone": self.timezone,
}
if self.model_name is not None:
payload["model"] = self.model_name

payload = dumps(
{
"attachments": attachments,
"files": [],
"model": self.model_name,
"prompt": prompt,
"timezone": self.timezone,
},
payload,
indent=None,
separators=(",", ":"),
)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

setup(
name="unofficial-claude2-api",
version="0.2.9",
version="0.3.0",
author="st1vms",
author_email="[email protected]",
description=__DESCRIPTION,
Expand Down

0 comments on commit af2c1ba

Please sign in to comment.