Skip to content

Commit

Permalink
Resolved the HTTP 400 Bad Request error at API endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
dundermain committed Nov 12, 2024
1 parent 07d4aeb commit 0f1cd3c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
5 changes: 0 additions & 5 deletions cookbook/tools/linear_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,8 @@

user_id = "69069"
issue_id = "6969"
team_id = "69"
new_title = "Design not updated yet"

agent.print_response("Get all the details of current user")
agent.print_response(f"Show the issue with the issue id: {issue_id}")
agent.print_response(f"Can you create an issue with the title: {new_title} under the team id: {team_id}")
agent.print_response(f"Show all the issues assigned to user id: {user_id}")
agent.print_response("Show all the high priority issues")


43 changes: 23 additions & 20 deletions phi/tools/linear_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def _execute_query(self, query, variables=None):
response.raise_for_status()

data = response.json()

if "errors" in data:
logger.error(f"GraphQL Error: {data['errors']}")
raise Exception(f"GraphQL Error: {data['errors']}")
Expand All @@ -66,13 +66,13 @@ def _execute_query(self, query, variables=None):
logger.error(f"Unexpected error: {e}")
raise

def get_user_details(self) -> dict:
def get_user_details(self) -> Optional[str]:
"""
Fetch authenticated user details.
It will return the user's unique ID, name, and email address from the viewer object in the GraphQL response.
Returns:
dict: A dictionary containing user details with keys `id`, `name`, and `email`.
str or None: A string containing user details like user id, name, and email.
Raises:
Exception: If an error occurs during the query execution or data retrieval.
Expand All @@ -93,25 +93,27 @@ def get_user_details(self) -> dict:

if response.get("viewer"):
user = response["viewer"]
logger.info(f"Retrieved authenticated user details with name: {user['name']}, ID: {user['id']}, Email: {user['email']}")
logger.info(
f"Retrieved authenticated user details with name: {user['name']}, ID: {user['id']}, Email: {user['email']}"
)
return str(user)
else:
logger.error(f"Failed to retrieve issue with ID {issue_id}.")
logger.error("Failed to retrieve the current user details")
return None

except Exception as e:
logger.error(f"Error fetching authenticated user details: {e}")
raise

def get_issue_details(self, issue_id: str) -> Optional[dict]:
def get_issue_details(self, issue_id: str) -> Optional[str]:
"""
Retrieve details of a specific issue by issue ID.
Args:
issue_id (str): The unique identifier of the issue to retrieve.
Returns:
dict: A dictionary containing issue details with keys `id`, `title`, and `description`.
str or None: A string containing issue details like issue id, issue title, and issue description.
Returns `None` if the issue is not found.
Raises:
Expand Down Expand Up @@ -143,7 +145,7 @@ def get_issue_details(self, issue_id: str) -> Optional[dict]:
logger.error(f"Error retrieving issue with ID {issue_id}: {e}")
raise

def create_issue(self, title: str, description: str, team_id: str) -> Optional[dict]:
def create_issue(self, title: str, description: str, team_id: str) -> Optional[str]:
"""
Create a new issue within a specific project and team.
Expand All @@ -153,7 +155,7 @@ def create_issue(self, title: str, description: str, team_id: str) -> Optional[d
team_id (str): The unique identifier of the team in which to create the issue.
Returns:
dict: A dictionary containing the created issue's details with keys `id` and `title`.
str or None: A string containing the created issue's details like issue id and issue title.
Returns `None` if the issue creation fails.
Raises:
Expand Down Expand Up @@ -190,7 +192,7 @@ def create_issue(self, title: str, description: str, team_id: str) -> Optional[d
logger.error(f"Error creating issue '{title}' for team ID {team_id}: {e}")
raise

def update_issue(self, issue_id: str, title: Optional[str], state_id: Optional[str]) -> Optional[dict]:
def update_issue(self, issue_id: str, title: Optional[str], state_id: Optional[str]) -> Optional[str]:
"""
Update the title or state of a specific issue by issue ID.
Expand All @@ -200,7 +202,7 @@ def update_issue(self, issue_id: str, title: Optional[str], state_id: Optional[s
state_id (str, optional): The new state identifier for the issue. If None, the state remains unchanged.
Returns:
dict: A dictionary containing the updated issue's details with keys `id`, `title`, and `state` (which includes `id` and `name`).
str or None: A string containing the updated issue's details with issue id, issue title, and issue state (which includes `id` and `name`).
Returns `None` if the update is unsuccessful.
Raises:
Expand Down Expand Up @@ -242,16 +244,16 @@ def update_issue(self, issue_id: str, title: Optional[str], state_id: Optional[s
logger.error(f"Error updating issue ID {issue_id}: {e}")
raise

def get_user_assigned_issues(self, user_id: str) -> Optional[list[dict]]:
def get_user_assigned_issues(self, user_id: str) -> Optional[str]:
"""
Retrieve issues assigned to a specific user by user ID.
Args:
user_id (str): The unique identifier of the user for whom to retrieve assigned issues.
Returns:
list[dict] or None: A list of dictionaries representing the assigned issues,
where each dictionary contains issue details (e.g., `id`, `title`).
str or None: A string representing the assigned issues to user id,
where each issue contains issue details (e.g., `id`, `title`).
Returns None if the user or issues cannot be retrieved.
Raises:
Expand Down Expand Up @@ -290,16 +292,16 @@ def get_user_assigned_issues(self, user_id: str) -> Optional[list[dict]]:
logger.error(f"Error retrieving issues for user ID {user_id}: {e}")
raise

def get_workflow_issues(self, workflow_id: str) -> Optional[list[dict]]:
def get_workflow_issues(self, workflow_id: str) -> Optional[str]:
"""
Retrieve issues within a specific workflow state by workflow ID.
Args:
workflow_id (str): The unique identifier of the workflow state to retrieve issues from.
Returns:
list[dict] or None: A list of dictionaries representing the issues within the specified workflow state,
where each dictionary contains details of an issue (e.g., `title`).
str or None: A string representing the issues within the specified workflow state,
where each issue contains details of an issue (e.g., `title`).
Returns None if no issues are found or if the workflow state cannot be retrieved.
Raises:
Expand Down Expand Up @@ -333,13 +335,14 @@ def get_workflow_issues(self, workflow_id: str) -> Optional[list[dict]]:
logger.error(f"Error retrieving issues for workflow state ID {workflow_id}: {e}")
raise

def get_high_priority_issues(self) -> Optional[list[dict]]:
def get_high_priority_issues(self) -> Optional[str]:
"""
Retrieve issues with a high priority (priority <= 2).
Returns:
list[dict] or None: A list of dictionaries representing high-priority issues, where each dictionary
contains details of an issue (e.g., `id`, `title`, `priority`). Returns None if no issues are retrieved.
str or None: A str representing high-priority issues, where it
contains details of an issue (e.g., `id`, `title`, `priority`).
Returns None if no issues are retrieved.
Raises:
Exception: If an error occurs during the query process.
Expand Down

0 comments on commit 0f1cd3c

Please sign in to comment.