-
Notifications
You must be signed in to change notification settings - Fork 1
Sourcery refactored main branch #1
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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'] | ||
|
|
||
| def get_content_type(self, file_path): | ||
| # Function to determine content type based on file extension | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ): |
||
| attachments = [attachment_response] | ||
| else: | ||
| return {"Error: Invalid file format. Please try again."} | ||
|
|
@@ -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): | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| # Returns all the messages in conversation | ||
| def chat_conversation_history(self, conversation_id): | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def create_new_chat(self): | ||
| url = f"https://claude.ai/api/organizations/{self.organization_id}/chat_conversations" | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
|
|
||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def main(): | ||
| cookie = get_cookie() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
Client.get_organization_idrefactored with the following changes:inline-immediately-returned-variable)