Merge branch 'LAION-AI:main' into main

This commit is contained in:
Alexander Goryunov
2023-01-01 18:27:10 +02:00
committed by GitHub
7 changed files with 120 additions and 23 deletions
+3 -2
View File
@@ -57,7 +57,8 @@ repos:
- id: next-lint-website
name: Lint website
files: ^website/
exclude: ^website/node_modules/
types_or: [javascript, jsx, ts, tsx]
language: system
language: node
pass_filenames: false
entry: bash -c "cd website && npm install && npm run lint"
entry: website/next-lint.js
+6
View File
@@ -136,3 +136,9 @@ In case you haven't done this, have already committed, and CI is failing, you ca
### Deployment
Upon making a release on GitHub, all docker images are automatically built and pushed to ghcr.io. The docker images are tagged with the release version, and the `latest` tag. Further, the ansible playbook in `ansible/dev.yaml` is run to automatically deploy the built release to the dev machine.
### Problems and Solutions
- **I am on Ubuntu and getting `ERROR: The Compose file is invalid because:Service backend has neither an image nor a build context specified. At least one must be provided.`**
Make sure you have an up-to-date version of docker installed, and also install `docker-compose-plugin`. See [here](https://github.com/LAION-AI/Open-Assistant/issues/208) for more details.
+77
View File
@@ -1,11 +1,14 @@
# -*- coding: utf-8 -*-
"""Bot logic."""
from datetime import datetime
import aiosqlite
import hikari
import lightbulb
import miru
from bot.api_client import OasstApiClient
from bot.settings import Settings
from bot.utils import EMPTY, mention
settings = Settings()
@@ -38,3 +41,77 @@ async def on_stopping(event: hikari.StoppingEvent):
"""Cleanup."""
await bot.d.db.close()
await bot.d.oasst_api.close()
async def _send_error_embed(
content: str, exception: lightbulb.errors.LightbulbError | BaseException, ctx: lightbulb.Context
) -> None:
ctx.command
embed = hikari.Embed(
title=f"`{exception.__class__.__name__}` Error{f' in `{ctx.command.name}`' if ctx.command else '' }",
description=content,
color=0xFF0000,
timestamp=datetime.now().astimezone(),
).set_author(name=ctx.author.username, url=str(ctx.author.avatar_url))
await ctx.respond(EMPTY, embed=embed)
@bot.listen(lightbulb.CommandErrorEvent)
async def on_error(event: lightbulb.CommandErrorEvent) -> None:
"""Error handler for the bot."""
# Unwrap the exception to get the original cause
exc = event.exception.__cause__ or event.exception
ctx = event.context
if isinstance(event.exception, lightbulb.CommandInvocationError):
if not event.context.command:
await _send_error_embed("Something went wrong", exc, ctx)
else:
await _send_error_embed(
f"Something went wrong during invocation of command `{event.context.command.name}`.", exc, ctx
)
raise event.exception
# Not an owner
if isinstance(exc, lightbulb.NotOwner):
await _send_error_embed("You are not the owner of this bot.", exc, ctx)
# Command is on cooldown
elif isinstance(exc, lightbulb.CommandIsOnCooldown):
await _send_error_embed(f"This command is on cooldown. Retry in `{exc.retry_after:.2f}` seconds.", exc, ctx)
# Missing permissions
elif isinstance(exc, lightbulb.errors.MissingRequiredPermission):
await _send_error_embed(
f"You do not have permission to use this command. Missing permissions: {exc.missing_perms}", exc, ctx
)
# Missing roles
elif isinstance(exc, lightbulb.errors.MissingRequiredRole):
assert event.context.guild_id is not None # Roles only exist in guilds
await _send_error_embed(
f"You do not have the correct role to use this command. Missing role(s): {[mention(r, 'role') for r in exc.missing_roles]}",
exc,
ctx,
)
# Only a guild command
elif isinstance(exc, lightbulb.errors.OnlyInGuild):
await _send_error_embed("This command can only be run in servers.", exc, ctx)
# Only a DM command
elif isinstance(exc, lightbulb.errors.OnlyInDM):
await _send_error_embed("This command can only be run in DMs.", exc, ctx)
# Not enough arguments
elif isinstance(exc, lightbulb.errors.NotEnoughArguments):
await _send_error_embed(
f"Not enough arguments were supplied to the command. {[opt.name for opt in exc.missing_options]}", exc, ctx
)
# Bot missing permission
elif isinstance(exc, lightbulb.errors.BotMissingRequiredPermission):
await _send_error_embed(
f"The bot does not have the correct permission(s) to execute this command. Missing permissions: {exc.missing_perms}",
exc,
ctx,
)
elif isinstance(exc, lightbulb.errors.MissingRequiredAttachment):
await _send_error_embed("Not enough attachemnts were supplied to this command.", exc, ctx)
else:
raise exc
+24
View File
@@ -0,0 +1,24 @@
#!/usr/bin/env node
const { spawnSync } = require("child_process");
async function npmLint() {
const spawnOption = {
shell: true,
env: process.env,
stdio: "inherit",
cwd: "./website",
};
let npmInstall;
let npmRunLint;
try {
npmInstall = await spawnSync("npm", ["install"], spawnOption);
if (npmInstall.status !== 0) {
process.exit(npmInstall.status);
}
npmRunLint = await spawnSync("npm", ["run lint"], spawnOption);
process.exit(npmRunLint.status);
} catch (error) {
console.error(error);
process.exit(1);
}
}
npmLint();
+10 -13
View File
@@ -20,24 +20,21 @@ export function Footer() {
</div>
</div>
<nav className="flex justify-center gap-20">
<div className="flex flex-col text-sm leading-7">
<b>Information</b>
<div className="flex flex-col leading-5">
<Link href="#" aria-label="Our Team" className="hover:underline underline-offset-2">
Our Team
</Link>
<Link href="/#join-us" aria-label="Join Us" className="hover:underline underline-offset-2">
Join Us
</Link>
</div>
</div>
<div className="flex flex-col text-sm leading-7">
<b>Legal</b>
<div className="flex flex-col leading-5">
<Link href="#" aria-label="Privacy Policy" className="hover:underline underline-offset-2">
<Link
href="/privacy-policy"
aria-label="Privacy Policy"
className="hover:underline underline-offset-2"
>
Privacy Policy
</Link>
<Link href="#" aria-label="Terms of Service" className="hover:underline underline-offset-2">
<Link
href="/terms-of-service"
aria-label="Terms of Service"
className="hover:underline underline-offset-2"
>
Terms of Service
</Link>
</div>
-7
View File
@@ -65,9 +65,6 @@ export function Header(props) {
<Image src="/images/logos/logo.svg" className="mx-auto object-fill" width="50" height="50" alt="logo" />
<span className="text-2xl font-bold ml-3">Open Assistant</span>
</Link>
<div className="hidden lg:flex lg:gap-10">
<NavLinks />
</div>
</div>
<div className="flex items-center gap-4">
<Popover className="lg:hidden">
@@ -102,10 +99,6 @@ export function Header(props) {
}}
className="absolute inset-x-0 top-0 z-0 origin-top rounded-b-2xl bg-white px-6 pb-6 pt-32 shadow-2xl shadow-gray-900/20"
>
<div className="space-y-4">
<MobileNavLink href="/#join-us">Join Us</MobileNavLink>
<MobileNavLink href="/#faqs">FAQs</MobileNavLink>
</div>
<div className="mt-8 flex flex-col gap-4"></div>
</Popover.Panel>
</>
-1
View File
@@ -27,7 +27,6 @@ const Home = () => {
<main>
<Hero />
<CallToAction />
<Faq />
</main>
)}