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

Prettier markdown format (low priority) #234

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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: 12 additions & 2 deletions utils/first_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ def remove_html_comments(body: str) -> str:
return re.sub(r"<!--.*?-->", "", body, flags=re.DOTALL).strip()


def format_with_prettier(code: str, parser: str = "markdown") -> str:
"""Formats a string using Prettier with the specified parser."""
result = subprocess.run(
["npx", "prettier", "--stdin", "--parser", parser],
input=code.encode("utf-8"),
capture_output=True,
check=True,
)
return result.stdout.decode("utf-8")


def get_completion(messages: list) -> str:
"""Get completion from OpenAI or Azure OpenAI."""
if AZURE_API_KEY and AZURE_ENDPOINT:
Expand All @@ -43,7 +54,7 @@ def get_completion(messages: list) -> str:

r = requests.post(url, headers=headers, json=data)
r.raise_for_status()
return r.json()["choices"][0]["message"]["content"].strip()
return format_with_prettier(r.json()["choices"][0]["message"]["content"].strip())


def get_pr_diff(pr_number):
Expand Down Expand Up @@ -391,7 +402,6 @@ def get_first_interaction_response(issue_type: str, title: str, body: str, usern
- INCLUDE ALL LINKS AND INSTRUCTIONS IN THE EXAMPLE BELOW, customized as appropriate
- In your response mention to the user that this is an automated response and that an Ultralytics engineer will also assist soon
- Do not add a sign-off or valediction like "best regards" at the end of your response
- Do not add spaces between bullet points or numbered lists
- Only link to files or URLs in the example below, do not add external links
- Use a few emojis to enliven your response

Expand Down