-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP * yt sumission is working * bot provides yt issue link now * fix prompt and function call escription
- Loading branch information
1 parent
df2af53
commit 2c24502
Showing
12 changed files
with
346 additions
and
110 deletions.
There are no files selected for viewing
This file contains 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,33 @@ | ||
from __future__ import annotations | ||
|
||
import contextlib | ||
from pathlib import Path | ||
from typing import Any | ||
|
||
|
||
# This class represents a simple database that stores its data as files in a directory. | ||
class DB: | ||
def __init__(self, path: Path) -> None: | ||
"""Initialize a DB instance.""" | ||
self.path = path | ||
|
||
def get(self, key: str) -> str | None: | ||
"""Get a value from the DB.""" | ||
try: | ||
with (self.path / key).open(mode="rb") as f: | ||
return f.read().decode("utf-8") | ||
except FileNotFoundError: | ||
return None | ||
|
||
def __getitem__(self, key: str) -> str | None: | ||
return self.get(key) | ||
|
||
def write(self, key: str, value: Any) -> None: | ||
"""Set a value in the DB.""" | ||
with (self.path / key).open(mode="wb") as f: | ||
f.write(value) | ||
|
||
def delete(self, key: str) -> None: | ||
"""Delete a value from the DB.""" | ||
with contextlib.suppress(FileNotFoundError): | ||
Path.unlink(self.path / key) |
This file contains 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,18 @@ | ||
{ | ||
"name": "create_issue", | ||
"description": "Create a YouTrack issue", | ||
"parameters": { | ||
"type": "object", | ||
"properties": { | ||
"summary": { | ||
"type": "string", | ||
"description": "Issue summary (come up with an issue title here)" | ||
}, | ||
"description": { | ||
"type": "string", | ||
"description": "Issue description (pass filled ${template} here)" | ||
} | ||
}, | ||
"required": ["summary", "description"] | ||
} | ||
} |
This file contains 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,13 @@ | ||
{ | ||
"name": "run_query", | ||
"description": "Runs SQL query against a db and returns result", | ||
"parameters": { | ||
"type": "object", | ||
"properties": { | ||
"sql_query": { | ||
"type": "string", | ||
"description": "SQL query to run" | ||
} | ||
} | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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,24 @@ | ||
Act as a ClarifAI🧙🏾♂️, an expert at technical specifications clarification. | ||
You are going to assist user with ${technical specification}, which will be assigned to Analytics team. | ||
The ${user} is not an analyst, so you are helping ${user} with adjustment of ${technical specification} to map their ${goal}. | ||
|
||
Your initialization: ${emoji}: My name is ${name}. | ||
My task ends when technical specification will be adjusted. | ||
${first step, question}." | ||
|
||
Follow these steps: | ||
1. ${Initialization}; Ask ${user} to describe the ${goal} in a few words. | ||
2. Learn ${Product knowledge}. | ||
3. Fill ${template}, based on the user's answers: | ||
{template} | ||
4. 🧙🏾♂️ make sure that ${user} is agreed with the final technical specification. | ||
5. When the ${final technical specification} is confirmed, end the task with function call: `create_issue`, fill `description` with the final technical specification. | ||
|
||
Rules: | ||
-End every output with a multiple choice question with several options (not more than 4) to chose from | ||
-Don't ask a colleague about data structure, data sources or any information about the tables and fields available in database | ||
-Don't work with SQL, work only with ${technical specification} as an YouTrack issue | ||
|
||
Product knowledge: | ||
At our product users can make submissions. Submission is a user answer to a step. | ||
Step is a educational unit that contains a question or some task to do. |
This file contains 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,12 @@ | ||
Act as a QueryMaster🧙🏾♂️, an expert SQL developer, who is using "ClickHouse" dialect. | ||
Your job is to map technical specification to SQL query. | ||
Develop a SQL query. | ||
|
||
Rules: | ||
-There are several available tables for you to work with: | ||
`hyperskill.content` – events mart, contains information about user actions | ||
`hyperskill_private.users` – users mart, contains user properties | ||
-Use CTEs (common table expressions) to break down complex queries into smaller steps | ||
-Don't run queries against `hyperskill.content` without `date` column filter or it will take consume all server resources | ||
-Don't use `CASE`, use if() or multiIf() instead | ||
-Don't use `COUNT(DISTINCT {column})` use `uniqExact({column})` instead |
This file contains 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,14 @@ | ||
Act as a QueryReviewer🧙🏾♂️, an expert SQL developer, who is reviewing quires in "ClickHouse" dialect. | ||
Your job is to review a SQL query: | ||
{sql_query} | ||
|
||
Follow the next steps: | ||
1. Check if {query} makes sense in context of the technical specification: | ||
{tech_spec} | ||
2. Check if {query} is valid according to docs: | ||
{docs} | ||
3. Check some other aspects of the {query} | ||
4. Provide a step by step review of the {query} as a list of comments | ||
|
||
Useful reminders: | ||
-Don't run queries against `hyperskill.content` without `date` column filter or it will take consume all server resources |
This file contains 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,5 @@ | ||
Act as a QueryTester🧙🏾♂️, an expert SQL developer, who is testing queries in ClickHouse dialect. | ||
Your job is to test this SQL query: | ||
{sql_query} | ||
|
||
Run {query} against a db, if errors occur, you will be informed, so you can fix them. |
This file contains 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 |
---|---|---|
@@ -1,7 +1,5 @@ | ||
#!/bin/bash | ||
|
||
cd slack_bot || exit | ||
|
||
echo "Formatting code..." | ||
black . | ||
|
||
|
This file contains 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,10 @@ | ||
### Motivation (Why?) | ||
[comment]: <> (Please, describe the motivation for this task. Why do you need it? What is the problem you are trying to solve?) | ||
|
||
### TODO: | ||
[comment]: <> (What do you expect to see as a result of this task? What should the results of this task contain?) | ||
|
||
### Priority & Urgency | ||
[comment]: <> (Please, fill the following checklist:) | ||
- is important [comment]: <> (Ask user about issue priority: Critical, Major, Normal, Minor.) | ||
- is urgent [comment]: <> (Ask user about issue urgency: yes, no, may be there is a due date.) |
This file contains 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 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,48 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Any | ||
|
||
import requests | ||
|
||
|
||
class IssueCreationError(Exception): | ||
"""Exception raised for errors in the issue creation process.""" | ||
|
||
def __init__(self, status_code: int, error_message: str) -> None: | ||
self.status_code = status_code | ||
self.error_message = error_message | ||
super().__init__( | ||
f"Failed to create issue. Status code: {status_code}.\n" | ||
f"Error: {error_message}" | ||
) | ||
|
||
|
||
class YouTrack: | ||
def __init__(self, base_url: str | None, token: str | None) -> None: | ||
if base_url or token: | ||
self.base_url = base_url | ||
self.token = token | ||
else: | ||
raise ValueError("YouTrack base URL and API token are required.") | ||
|
||
def create_issue( | ||
self, summary: str, description: str, project: str = "43-46" | ||
) -> dict[str, Any] | IssueCreationError: | ||
"""Create an issue in YouTrack.""" | ||
url = f"{self.base_url}/api/issues" | ||
headers = { | ||
"Content-Type": "application/json", | ||
"Authorization": f"Bearer {self.token}", | ||
} | ||
payload = { | ||
"project": {"id": project}, | ||
"summary": summary + " [created by AI Data Assistant]", | ||
"description": description, | ||
} | ||
|
||
response = requests.post(url, headers=headers, json=payload, timeout=30) | ||
|
||
if response.status_code != 200: # noqa: PLR2004 | ||
return IssueCreationError(response.status_code, response.text) | ||
|
||
return response.json() |