Skip to content
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
30 changes: 7 additions & 23 deletions claude-api/claude_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ def get_organization_id(self):

response = requests.request("GET", url, headers=headers)
res = json.loads(response.text)
uuid = res[0]['uuid']

return uuid
return res[0]['uuid']
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Client.get_organization_id refactored with the following changes:


def get_content_type(self, file_path):
# Function to determine content type based on file extension
Expand Down Expand Up @@ -78,8 +76,7 @@ def send_message(self, prompt, conversation_id, attachment=None):
# Upload attachment if provided
attachments = []
if attachment:
attachment_response = self.upload_attachment(attachment)
if attachment_response:
if attachment_response := self.upload_attachment(attachment):
Comment on lines -81 to +79
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Client.send_message refactored with the following changes:

This removes the following comments ( why? ):

# Returns answer

attachments = [attachment_response]
else:
return {"Error: Invalid file format. Please try again."}
Expand Down Expand Up @@ -121,10 +118,7 @@ def send_message(self, prompt, conversation_id, attachment=None):
decoded_data = response.content.decode("utf-8")
data = decoded_data.strip().split('\n')[-1]

answer = {"answer": json.loads(data[6:])['completion']}['answer']

# Returns answer
return answer
return {"answer": json.loads(data[6:])['completion']}['answer']

# Deletes the conversation
def delete_conversation(self, conversation_id):
Expand All @@ -150,10 +144,7 @@ def delete_conversation(self, conversation_id):
response = requests.request("DELETE", url, headers=headers, data=payload)

# Returns True if deleted or False if any error in deleting
if response.status_code == 204:
return True
else:
return False
return response.status_code == 204
Comment on lines -153 to +147
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Client.delete_conversation refactored with the following changes:


# Returns all the messages in conversation
def chat_conversation_history(self, conversation_id):
Expand Down Expand Up @@ -181,8 +172,7 @@ def chat_conversation_history(self, conversation_id):
def generate_uuid(self):
random_uuid = uuid.uuid4()
random_uuid_str = str(random_uuid)
formatted_uuid = f"{random_uuid_str[0:8]}-{random_uuid_str[9:13]}-{random_uuid_str[14:18]}-{random_uuid_str[19:23]}-{random_uuid_str[24:]}"
return formatted_uuid
return f"{random_uuid_str[:8]}-{random_uuid_str[9:13]}-{random_uuid_str[14:18]}-{random_uuid_str[19:23]}-{random_uuid_str[24:]}"
Comment on lines -184 to +175
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Client.generate_uuid refactored with the following changes:


def create_new_chat(self):
url = f"https://claude.ai/api/organizations/{self.organization_id}/chat_conversations"
Expand Down Expand Up @@ -245,10 +235,7 @@ def upload_attachment(self, file_path):
}

response = requests.post(url, headers=headers, files=files)
if response.status_code == 200:
return response.json()
else:
return False
return response.json() if response.status_code == 200 else False
Comment on lines -248 to +238
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Client.upload_attachment refactored with the following changes:




Expand Down Expand Up @@ -278,8 +265,5 @@ def rename_chat(self, title, conversation_id):

response = requests.request("POST", url, headers=headers, data=payload)

if response.status_code == 200:
return True
else:
return False
return response.status_code == 200
Comment on lines -281 to +268
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Client.rename_chat refactored with the following changes:


6 changes: 3 additions & 3 deletions usecases/console_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from claude_api import Client

def get_cookie():
cookie = os.environ.get('cookie')
if not cookie:
if cookie := os.environ.get('cookie'):
return cookie
else:
raise ValueError("Please set the 'cookie' environment variable.")
return cookie
Comment on lines -5 to -8
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_cookie refactored with the following changes:


def main():
cookie = get_cookie()
Expand Down