Skip to content

Commit 422581d

Browse files
authored
Merge pull request #22 from st1vms/dev-0.3.2
dev-0.3.2 merge to main
2 parents de88d8e + d5a6702 commit 422581d

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
- [Retrieving Chat History](#retrieving-chat-history)
1111
- [Faster Loading](#faster-loading-avoiding-selenium)
1212
- [Proxies](#proxies)
13-
- [Switching model version](#changing-claude-model)
13+
- [Changing model version](#changing-claude-model)
1414
- [Troubleshooting](#troubleshooting)
1515
- [Donating](#donating)
1616

@@ -23,7 +23,7 @@ While not officially supported by Anthropic, this library can enable interesting
2323
It allows for:
2424

2525
- Creating chat sessions with Claude and getting chat IDs.
26-
- Sending messages to Claude containing up to 5 attachment files (txt, pdf, csv, etc...) 10 MB each.
26+
- Sending messages to Claude containing up to 5 attachment files (txt, pdf, csv, png, jpeg, etc...) 10 MB each, images are also supported!
2727
- Retrieving chat message history, accessing specific chat conversations.
2828
- Deleting old chats when they are no longer needed.
2929
- Sending requests through proxies.
@@ -39,6 +39,8 @@ and more.
3939

4040
- Receive thoughtful responses to open-ended prompts and ideas. Claude can brainstorm ideas, expand on concepts, and have philosophical discussions.
4141

42+
- Send images and let Claude analyze them for you.
43+
4244
## How to install
4345

4446
```shell
@@ -256,7 +258,7 @@ __________
256258

257259
### Changing Claude model
258260

259-
In case you have accounts that are unable to migrate to latest model, you can override the `model_name` string parameter of `ClaudeAPIClient` constructor.
261+
In case you'd like to change the model used, or you do have accounts that are unable to migrate to latest model, you can override the `model_name` string parameter of `ClaudeAPIClient` constructor like so:
260262

261263
```py
262264
from claude_api.client import ClaudeAPIClient
@@ -265,10 +267,11 @@ from claude_api.session import SessionData
265267
session = SessionData(...)
266268

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

273+
You can retrieve the `model_name` strings from the [official API docs](https://docs.anthropic.com/claude/docs/models-overview#model-comparison)
274+
272275
## TROUBLESHOOTING
273276

274277
Some common errors that may arise during the usage of this API:

claude_api/client.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,6 @@ def __init__(
134134
Raises `ValueError` in case of failure
135135
136136
"""
137-
if model_name is not None and model_name not in {"claude-2.0", "claude-2.1"}:
138-
raise ValueError(
139-
"model_name must be either None or one of 'claude-2.0' or 'claude-2.1' strings"
140-
)
141137

142138
self.model_name: str = model_name
143139
self.timeout: float = timeout
@@ -235,7 +231,7 @@ def __prepare_file_attachment(self, fpath: str, chat_id: str) -> dict | None:
235231
if content_type == "text/plain":
236232
return self.__prepare_text_file_attachment(fpath)
237233

238-
url = f"{self.__BASE_URL}/api/convert_document"
234+
url = f"{self.__BASE_URL}/api/{self.__session.organization_id}/upload"
239235

240236
headers = {
241237
"Host": "claude.ai",
@@ -268,7 +264,9 @@ def __prepare_file_attachment(self, fpath: str, chat_id: str) -> dict | None:
268264
proxies=self.__get_proxy(),
269265
)
270266
if response.status_code == 200:
271-
return response.json()
267+
res = response.json()
268+
if "file_uuid" in res:
269+
return res["file_uuid"]
272270
print(
273271
f"\n[{response.status_code}] Unable to prepare file attachment -> {fpath}\n"
274272
f"\nReason: {response.text}\n\n"
@@ -552,14 +550,8 @@ def send_message(
552550

553551
attachments = []
554552
if attachment_paths:
555-
attachments = [
556-
a
557-
for a in [
558-
self.__prepare_file_attachment(path, chat_id)
559-
for path in attachment_paths
560-
]
561-
if a
562-
]
553+
for path in attachment_paths:
554+
attachments.append(self.__prepare_file_attachment(path, chat_id))
563555

564556
url = (
565557
f"{self.__BASE_URL}/api/organizations/"
@@ -568,11 +560,20 @@ def send_message(
568560
)
569561

570562
payload = {
571-
"attachments": attachments,
563+
"attachments": [],
572564
"files": [],
573565
"prompt": prompt,
574566
"timezone": self.timezone,
575567
}
568+
569+
for a in attachments:
570+
if isinstance(a, dict):
571+
# Text file attachment
572+
payload["attachments"].append(a)
573+
elif isinstance(a, str):
574+
# Other files uploaded
575+
payload["files"].append(a)
576+
576577
if self.model_name is not None:
577578
payload["model"] = self.model_name
578579

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
setup(
1818
name="unofficial-claude-api",
19-
version="0.3.1",
19+
version="0.3.2",
2020
author="st1vms",
2121
author_email="stefano.maria.salvatore@gmail.com",
2222
description=__DESCRIPTION,

0 commit comments

Comments
 (0)