Skip to content

Commit

Permalink
Merge pull request #10 from st1vms/dev-0.2.6
Browse files Browse the repository at this point in the history
v0.2.6 | Ability to change Claude's model version
  • Loading branch information
st1vms authored Jan 10, 2024
2 parents 1e40c1f + 76c7c08 commit b1f9b2d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ for chat in all_chat_ids:
client.delete_chat(chat)

# Or by using a shortcut utility
#
# client.delete_all_chats()
client.delete_all_chats()
```

## Tips
Expand Down Expand Up @@ -201,6 +200,7 @@ If you'd like to set a proxy for all requests, follow this example:

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

# Create HTTPProxy instance
http_proxy = HTTPProxy(
Expand All @@ -209,11 +209,26 @@ http_proxy = HTTPProxy(
use_ssl=False # Set to True if proxy uses HTTPS schema
)

# session = SessionData(...)
session = SessionData(...)

# Give the proxy instance to ClaudeAPIClient constructor, along with session data.
client = ClaudeAPIClient(session, proxy=http_proxy)
```

### 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.

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

session = SessionData(...)

# Defaults to claude-2.1
client = ClaudeAPIClient(session, model_name="claude-2.0")
```

______

## TROUBLESHOOTING
Expand Down
17 changes: 13 additions & 4 deletions claude2_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ class ClaudeAPIClient:
__BASE_URL = "https://claude.ai"

def __init__(
self, session: SessionData, proxy: HTTPProxy = None, timeout: float = 240
self,
session: SessionData,
proxy: HTTPProxy = None,
model_name: str = "claude-2.1",
timeout: float = 240,
) -> None:
"""
Constructs a `ClaudeAPIClient` instance using provided `SessionData`,
Expand All @@ -117,6 +121,12 @@ def __init__(
Raises `ValueError` in case of failure
"""
if 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"
)

self.model_name = model_name
self.timeout = timeout
self.proxy = proxy
self.__session = session
Expand Down Expand Up @@ -473,8 +483,7 @@ def send_message(
attachments = [
a
for a in [
self.__prepare_file_attachment(path)
for path in attachment_paths
self.__prepare_file_attachment(path) for path in attachment_paths
]
if a
]
Expand All @@ -486,7 +495,7 @@ def send_message(
"completion": {
"prompt": prompt,
"timezone": self.timezone,
"model": "claude-2.1",
"model": self.model_name,
},
"organization_uuid": self.__session.organization_id,
"conversation_uuid": chat_id,
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.5",
version="0.2.6",
author="st1vms",
author_email="[email protected]",
description=__DESCRIPTION,
Expand Down

0 comments on commit b1f9b2d

Please sign in to comment.