-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into file_search
- Loading branch information
Showing
22 changed files
with
1,082 additions
and
241 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
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,36 @@ | ||
name: Release | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
|
||
release-build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.x" | ||
- run: python -m pip install --upgrade pip build | ||
- run: python -m build --sdist --wheel | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: release-dists | ||
path: dist/ | ||
|
||
pypi-publish: | ||
runs-on: ubuntu-latest | ||
needs: | ||
- release-build | ||
permissions: | ||
id-token: write | ||
|
||
steps: | ||
- uses: actions/download-artifact@v4 | ||
with: | ||
name: release-dists | ||
path: dist/ | ||
- uses: pypa/gh-action-pypi-publish@release/v1 |
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
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,44 +1,98 @@ | ||
import asyncio | ||
import logging | ||
import os | ||
import sys | ||
|
||
import click | ||
import openai | ||
import sentry_sdk | ||
from sentry_sdk.integrations.asyncio import AsyncioIntegration | ||
|
||
from . import config | ||
|
||
sentry_sdk.init(config.SENTRY_DSN) | ||
sentry_sdk.init( | ||
dsn=config.SENTRY_DSN, | ||
enable_tracing=True, | ||
integrations=[ | ||
AsyncioIntegration(), | ||
], | ||
) | ||
|
||
|
||
@click.group() | ||
@click.option("-v", "--verbose", is_flag=True, help="Enables verbose mode.") | ||
def cli(verbose): | ||
def cli(): | ||
"""Sam – cuz your company is nothing with Sam.""" | ||
handler = logging.StreamHandler(sys.stdout) | ||
handler.setFormatter(logging.Formatter("%(asctime)s %(levelname)s %(message)s")) | ||
logger = logging.getLogger("sam") | ||
logger.addHandler(handler) | ||
logger.setLevel(logging.DEBUG if verbose else logging.INFO) | ||
|
||
|
||
@cli.group(chain=True) | ||
def run(): | ||
"""Run an assistent bot, currently only Slack is supported.""" | ||
@click.option("-v", "--verbose", is_flag=True, help="Enables verbose mode.") | ||
def run(verbose): | ||
"""Run an assistent bot.""" | ||
handler = logging.StreamHandler(sys.stdout) | ||
handler.setFormatter( | ||
logging.Formatter("%(asctime)s %(levelname)7s %(name)s - %(message)s") | ||
) | ||
logging.basicConfig( | ||
handlers=[handler], level=logging.DEBUG if verbose else logging.INFO | ||
) | ||
|
||
|
||
@run.command() | ||
def slack(): | ||
"""Run the Slack bot demon.""" | ||
from slack_bolt.adapter.socket_mode.async_handler import AsyncSocketModeHandler | ||
|
||
from .slack import app | ||
from .slack import get_app | ||
|
||
loop = asyncio.get_event_loop() | ||
|
||
loop.run_until_complete( | ||
AsyncSocketModeHandler(app, config.SLACK_APP_TOKEN).start_async() | ||
AsyncSocketModeHandler(get_app(), config.SLACK_APP_TOKEN).start_async() | ||
) | ||
|
||
|
||
@cli.group(chain=True) | ||
@click.option("-v", "--verbose", is_flag=True, help="Enables verbose mode.") | ||
def assistants(verbose): | ||
"""Manage OpenAI assistants.""" | ||
handler = logging.StreamHandler(sys.stdout) | ||
handler.setFormatter(logging.Formatter("%(message)s")) | ||
logging.basicConfig( | ||
handlers=[handler], level=logging.DEBUG if verbose else logging.INFO | ||
) | ||
|
||
|
||
@assistants.command(name="list") | ||
def _list(): | ||
"""List all assistants configured in your project.""" | ||
assistant_list = list(config.load_assistants()) | ||
for assistant_config in assistant_list: | ||
click.echo( | ||
f"{assistant_config.name} ({assistant_config.project}): {assistant_config.assistant_id}" | ||
) | ||
if not assistant_list: | ||
click.echo("No assistants configured.") | ||
|
||
|
||
@assistants.command() | ||
def upload(): | ||
"""Compile and upload all assistants system prompts to OpenAI.""" | ||
assistant_list = list(config.load_assistants()) | ||
for assistant_config in assistant_list: | ||
click.echo(f"Uploading {assistant_config.name}...", nl=False) | ||
project_api_key_name = ( | ||
f"OPENAI_{assistant_config.project.replace('-', '_').upper()}_API_KEY" | ||
) | ||
project_api_key = os.getenv(project_api_key_name) | ||
with openai.OpenAI(api_key=project_api_key) as client: | ||
client.beta.assistants.update( | ||
assistant_id=assistant_config.assistant_id, | ||
instructions=assistant_config.system_prompt, | ||
) | ||
click.echo(" Done!") | ||
if not assistant_list: | ||
click.echo("No assistants configured.") | ||
|
||
|
||
if __name__ == "__main__": | ||
cli() |
Oops, something went wrong.