Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Styles Implemented + Removed backward import + Updated Docs #30

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- [Requirements](#requirements)
- [Example Usage](#example-usage)
- [Tips](#tips)
- [Response Styles](#response-styles)
- [Retrieving Chat History](#retrieving-chat-history)
- [Faster Loading](#faster-loading-avoiding-selenium)
- [Proxies](#proxies)
Expand Down Expand Up @@ -137,6 +138,19 @@ sys_exit(0)

## Tips

### Response styles

After version 0.3.4 there is the ability to customize the response style using one of these four attributes: `normal`, `concise`, `explanatory`, `formal`.

You can specify one of these attributes in the `send_message` method, which by default uses normal style:

```py
# Omitt style argument to use the default normal response style
client.send_message(
chat_id, "Hello!", style='formal'
)
```

### Retrieving chat history

```python
Expand Down
20 changes: 0 additions & 20 deletions claude2_api/__init__.py

This file was deleted.

20 changes: 20 additions & 0 deletions claude_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from curl_cffi.requests import post as http_post
from curl_cffi.requests import delete as http_delete
from .session import SessionData
from .styles import NORMAL_STYLE, CONCISE_STYLE, EXPLANATORY_STYLE, FORMAL_STYLE
from .errors import ClaudeAPIError, MessageRateLimitError, OverloadError


Expand Down Expand Up @@ -541,12 +542,16 @@ def send_message(
chat_id: str,
prompt: str,
attachment_paths: list[str] = None,
style: str = "normal",
) -> SendMessageResponse:
"""
Send message to `chat_id` using specified `prompt` string.

You can omitt or provide an attachments path list using `attachment_paths`

List of available response styles (default normal):
- `normal`, `concise`, `explanatory`, `formal`

Returns a `SendMessageResponse` instance, having:
- `answer` string field,
- `status_code` integer field,
Expand All @@ -569,6 +574,7 @@ def send_message(
payload = {
"attachments": [],
"files": [],
"personalized_styles": [],
"prompt": prompt,
"timezone": self.timezone,
}
Expand All @@ -581,6 +587,20 @@ def send_message(
# Other files uploaded
payload["files"].append(a)

# Apply style
if style == "normal":
payload["personalized_styles"].append(NORMAL_STYLE)
elif style == "concise":
payload["personalized_styles"].append(CONCISE_STYLE)
elif style == "explanatory":
payload["personalized_styles"].append(EXPLANATORY_STYLE)
elif style == "formal":
payload["personalized_styles"].append(FORMAL_STYLE)
else:
# Unknown style
payload["personalized_styles"].append(NORMAL_STYLE)

# NOTE Model parameter may be removed in the future
if self.model_name is not None:
payload["model"] = self.model_name

Expand Down
38 changes: 38 additions & 0 deletions claude_api/styles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""Claude styles definitions"""

NORMAL_STYLE = {
"isDefault": True,
"key": "Normal",
"name": "Normal",
"prompt": "Normal",
"summary": "Default responses from Claude",
"type": "default",
}

CONCISE_STYLE = {
"isDefault": False,
"key": "Concise",
"name": "Concise",
"prompt": "Claude is operating in Concise Mode. In this mode, Claude aims to reduce its output tokens while maintaining its helpfulness, quality, completeness, and accuracy.Claude provides answers to questions without much unneeded preamble or postamble. It focuses on addressing the specific query or task at hand, avoiding tangential information unless helpful for understanding or completing the request. If it decides to create a list, Claude focuses on key information instead of comprehensive enumeration.Claude maintains a helpful tone while avoiding excessive pleasantries or redundant offers of assistance.Claude provides relevant evidence and supporting details when substantiation is helpful for factuality and understanding of its response. For numerical data, Claude includes specific figures when important to the answer's accuracy.For code, artifacts, written content, or other generated outputs, Claude maintains the exact same level of quality, completeness, and functionality as when NOT in Concise Mode. There should be no impact to these output types.Claude does not compromise on completeness, correctness, appropriateness, or helpfulness for the sake of brevity.If the human requests a long or detailed response, Claude will set aside Concise Mode constraints and provide a more comprehensive answer.If the human appears frustrated with Claude's conciseness, repeatedly requests longer or more detailed responses, or directly asks about changes in Claude's response style, Claude informs them that it's currently in Concise Mode and explains that Concise Mode can be turned off via Claude's UI if desired. Besides these scenarios, Claude does not mention Concise Mode.",
"summary": "Shorter responses & more messages",
"type": "default",
}

EXPLANATORY_STYLE = {
"isDefault": False,
"key": "Explanatory",
"name": "Explanatory",
"prompt": "Claude aims to give clear, thorough explanations that help the human deeply understand complex topics.Claude approaches questions like a teacher would, breaking down ideas into easier parts and building up to harder concepts. It uses comparisons, examples, and step-by-step explanations to improve understanding.Claude keeps a patient and encouraging tone, trying to spot and address possible points of confusion before they arise. Claude may ask thinking questions or suggest mental exercises to get the human more involved in learning.Claude gives background info when it helps create a fuller picture of the topic. It might sometimes branch into related topics if they help build a complete understanding of the subject.When writing code or other technical content, Claude adds helpful comments to explain the thinking behind important steps.Claude always writes prose and in full sentences, especially for reports, documents, explanations, and question answering. Claude can use bullets only if the user asks specifically for a list.",
"summary": "Educational responses for learning",
"type": "default",
}


FORMAL_STYLE = {
"isDefault": False,
"key": "Formal",
"name": "Formal",
"prompt": "Claude aims to write in a clear, polished way that works well for business settings.Claude structures its answers carefully, with clear sections and logical flow. It gets to the point quickly while giving enough detail to fully answer the question.Claude uses a formal but clear tone, avoiding casual language and slang. It writes in a way that would be appropriate for sharing with colleagues and stakeholders.Claude balances being thorough with being efficient. It includes important context and details while leaving out unnecessary information that might distract from the main points.Claude writes prose and in full sentences, especially for reports, documents, explanations, and question answering. Claude can use bullet points or lists only if the human asks specifically for a list, or if it makes sense for the specific task that the human is asking about.",
"summary": "Clear and well-structured responses",
"type": "default",
}
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-claude-api",
version="0.3.3",
version="0.3.4",
author="st1vms",
author_email="[email protected]",
description=__DESCRIPTION,
Expand Down