-
Notifications
You must be signed in to change notification settings - Fork 62
CG-10610: System Prompt Generation #221
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
31ca3df
added logic to generate and update system prompt in codegen team gith…
80a3b32
added command to read the system prompt
c586e2d
modified gist client and refactored system prompt command to support …
fd61748
Merge branch 'develop' into system-prompt-generation
d81b5b6
update system prompt link in docs
e0546b8
commiting system prompt to repo
668f4e0
updated system prompt link
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| from typing import Any, Optional | ||
| from urllib.parse import urljoin | ||
|
|
||
| import requests | ||
| from requests.exceptions import RequestException | ||
|
|
||
|
|
||
| class GistClientError(Exception): | ||
| """Base exception for GistClient errors.""" | ||
|
|
||
| pass | ||
|
|
||
|
|
||
| class GistAuthenticationError(GistClientError): | ||
| """Raised when authentication fails.""" | ||
|
|
||
| pass | ||
|
|
||
|
|
||
| class GistClient: | ||
| """A client for interacting with GitHub Gists API. | ||
|
|
||
| This client provides methods to read and update GitHub Gists using the GitHub API v3. | ||
| It supports both authenticated and unauthenticated requests, though some operations | ||
| require authentication. | ||
| """ | ||
|
|
||
| def __init__(self, token: Optional[str] = None) -> None: | ||
| """Initialize the GistClient with your GitHub personal access token. | ||
|
|
||
| Args: | ||
| token (Optional[str]): GitHub personal access token with gist scope | ||
|
|
||
| Raises: | ||
| GistAuthenticationError: If the provided token is invalid | ||
| """ | ||
| self.base_url = "https://api.github.com" | ||
| self.headers = {"Accept": "application/vnd.github.v3+json", "User-Agent": "GistClient"} | ||
|
|
||
| if token: | ||
| self.headers["Authorization"] = f"token {token}" | ||
|
|
||
| self.session = requests.Session() | ||
| self.session.headers.update(self.headers) | ||
|
|
||
| def _make_request(self, method: str, endpoint: str, **kwargs) -> dict[str, Any]: | ||
| """Make an HTTP request to the GitHub API. | ||
|
|
||
| Args: | ||
| method (str): HTTP method to use | ||
| endpoint (str): API endpoint to call | ||
| **kwargs: Additional arguments to pass to requests | ||
|
|
||
| Returns: | ||
| Dict[str, Any]: JSON response from the API | ||
|
|
||
| Raises: | ||
| GistClientError: If the request fails | ||
| GistAuthenticationError: If authentication fails | ||
| """ | ||
| try: | ||
| url = urljoin(self.base_url, endpoint) | ||
| response = self.session.request(method, url, **kwargs) | ||
| response.raise_for_status() | ||
| return response.json() | ||
| except requests.exceptions.HTTPError as e: | ||
| if e.response.status_code == 401: | ||
| msg = "Invalid authentication token" | ||
| raise GistAuthenticationError(msg) from e | ||
| msg = f"GitHub API request failed: {e!s}" | ||
| raise GistClientError(msg) from e | ||
| except RequestException as e: | ||
| msg = f"Request failed: {e!s}" | ||
| raise GistClientError(msg) from e | ||
|
|
||
| def get_gist(self, gist_id: str) -> dict[str, Any]: | ||
| """Fetch a specific gist. | ||
|
|
||
| Args: | ||
| gist_id (str): The ID of the gist to fetch | ||
|
|
||
| Returns: | ||
| Dict[str, Any]: The gist data | ||
| """ | ||
| return self._make_request("GET", f"/gists/{gist_id}") | ||
|
|
||
| def update_gist(self, gist_id: str, filename: str, content: str, description: Optional[str] = None) -> dict[str, Any]: | ||
| """Update a specific file in a gist. | ||
|
|
||
| Args: | ||
| gist_id (str): The ID of the gist to update | ||
| filename (str): The name of the file to update | ||
| content (str): The new content for the file | ||
| description (Optional[str]): New description for the gist | ||
|
|
||
| Returns: | ||
| Dict[str, Any]: The updated gist data | ||
|
|
||
| Raises: | ||
| GistAuthenticationError: If no authentication token was provided | ||
| """ | ||
| if not self.headers.get("Authorization"): | ||
| msg = "Authentication token required to update a gist" | ||
| raise GistAuthenticationError(msg) | ||
|
|
||
| payload = {"files": {filename: {"content": content}}} | ||
| if description: | ||
| payload["description"] = description | ||
|
|
||
| return self._make_request("PATCH", f"/gists/{gist_id}", json=payload) | ||
|
|
||
| def __enter__(self): | ||
| return self | ||
|
|
||
| def __exit__(self, exc_type, exc_val, exc_tb): | ||
| self.session.close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| SYSTEM_PROMPT_GIST_ID = "708a870eec379d1f8086bd722f668978" | ||
| SYSTEM_PROMPT_FILENAME = "system-prompt.txt" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
would be cool if this could also be used to auto gen
links.tsx?