Add IRC disconnect try/except
This commit is contained in:
parent
781271aa59
commit
1343557f3d
@ -109,7 +109,7 @@ web_server = None
|
||||
# Cmd line overrides
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser(description="AI is Really Cool")
|
||||
parser.add_argument("--irc-server", type=str, default=IRC_SERVER, help=f"IRC server address. default={IRC_SERVER}")
|
||||
parser.add_argument("--irc-server", type=str, default=IRC_SERVER, help=f"IRC server address. Example: irc.libera.chat default={IRC_SERVER}")
|
||||
parser.add_argument("--irc-port", type=int, default=IRC_PORT, help=f"IRC server port. default={IRC_PORT}")
|
||||
parser.add_argument("--irc-nickname", type=str, default=NICK, help=f"Bot nickname. default={NICK}")
|
||||
parser.add_argument("--irc-channel", type=str, default=CHANNEL, help=f"Channel to join. default={CHANNEL}")
|
||||
@ -481,7 +481,15 @@ class DynamicIRCBot(pydle.Client):
|
||||
await super().on_part(channel, user)
|
||||
logging.info(f"PART: {channel} => {user}")
|
||||
|
||||
async def on_message(self, target, source, message, session, local_user=None):
|
||||
async def on_disconnect(self, expected):
|
||||
self.logger.error("Disconnected. Reconnecting in 5 seconds...")
|
||||
await asyncio.sleep(5)
|
||||
try:
|
||||
await self.connect(self.host, self.port, tls=self.tls)
|
||||
except Exception as e:
|
||||
self.logger.error(f"Reconnection failed: {e}")
|
||||
|
||||
async def on_message(self, target, source, message, session=None, local_user=None):
|
||||
global system_log, tool_log, system_log, command_log, web_server
|
||||
|
||||
if not local_user:
|
||||
@ -492,6 +500,9 @@ class DynamicIRCBot(pydle.Client):
|
||||
if source == self.nickname and not local_user:
|
||||
return
|
||||
|
||||
if session == None:
|
||||
session = target
|
||||
|
||||
if self.processing:
|
||||
await self.message(target, f"I'm already processing a query.")
|
||||
return
|
||||
@ -981,7 +992,10 @@ async def main():
|
||||
logging.info(f"Starting web server at http://{args.web_host}:{args.web_port}")
|
||||
threading.Thread(target=lambda: web_server.run(host=args.web_host, port=args.web_port, debug=True, use_reloader=False)).start()
|
||||
|
||||
await irc_bot.handle_forever()
|
||||
try:
|
||||
await irc_bot.handle_forever()
|
||||
except Exception as e:
|
||||
logging.exception({ "error": "irc_bot.handle_forever() failed"})
|
||||
|
||||
# Run the main function using anyio
|
||||
asyncio.run(main())
|
||||
|
1640
src/ketr-chat/package-lock.json
generated
1640
src/ketr-chat/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -13,8 +13,12 @@
|
||||
"@types/react-dom": "^19.0.4",
|
||||
"react": "^19.0.0",
|
||||
"react-dom": "^19.0.0",
|
||||
"react-markdown": "^10.1.0",
|
||||
"react-scripts": "5.0.1",
|
||||
"react-spinners": "^0.15.0",
|
||||
"rehype-katex": "^7.0.1",
|
||||
"remark-gfm": "^4.0.1",
|
||||
"remark-math": "^6.0.0",
|
||||
"typescript": "^4.9.5",
|
||||
"web-vitals": "^2.1.4"
|
||||
},
|
||||
|
@ -84,7 +84,7 @@ div {
|
||||
border-radius: 0.25rem;
|
||||
justify-self: left;
|
||||
display: flex;
|
||||
white-space: pre-wrap;
|
||||
/* white-space: pre-wrap; */
|
||||
overflow-wrap: break-word;
|
||||
word-break: break-word;
|
||||
flex-direction: column;
|
||||
@ -103,3 +103,43 @@ div {
|
||||
font-size: 0.75rem;
|
||||
padding: 0.125rem;
|
||||
}
|
||||
/* Reduce general whitespace in markdown content */
|
||||
.markdown-content p {
|
||||
margin-top: 0.5rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
/* Reduce space between headings and content */
|
||||
.markdown-content h1,
|
||||
.markdown-content h2,
|
||||
.markdown-content h3,
|
||||
.markdown-content h4,
|
||||
.markdown-content h5,
|
||||
.markdown-content h6 {
|
||||
margin-top: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
/* Reduce space in lists */
|
||||
.markdown-content ul,
|
||||
.markdown-content ol {
|
||||
margin-top: 0.5rem;
|
||||
margin-bottom: 0.5rem;
|
||||
padding-left: 1.5rem;
|
||||
}
|
||||
|
||||
.markdown-content li {
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
|
||||
/* Reduce space between list items */
|
||||
.markdown-content li p {
|
||||
margin-top: 0;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
/* Reduce space around code blocks */
|
||||
.markdown-content pre {
|
||||
margin-top: 0.5rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
@ -1,8 +1,11 @@
|
||||
import React, { useState, useEffect, useRef, useCallback } from 'react';
|
||||
import PropagateLoader from "react-spinners/PropagateLoader";
|
||||
//import Markdown from 'react-native-markdown-display';
|
||||
import Markdown from 'react-markdown';
|
||||
import './App.css';
|
||||
import { createSemanticDiagnosticsBuilderProgram } from 'typescript';
|
||||
import remarkGfm from 'remark-gfm'
|
||||
import rehypeKatex from 'rehype-katex'
|
||||
import remarkMath from 'remark-math'
|
||||
import 'katex/dist/katex.min.css' // `rehype-katex` does not import the CSS for you
|
||||
|
||||
const welcome_message = "Welcome to Ketr-Chat. I have real-time access to a lot of information. Ask things like 'What are the headlines from cnn.com?' or 'What is the weather in Portland, OR?'";
|
||||
|
||||
@ -318,14 +321,26 @@ const App = () => {
|
||||
{message.user && (
|
||||
<div>{message.user}</div>
|
||||
)}
|
||||
<div>{formattedContent}</div>
|
||||
{message.role === 'assistant' ? (
|
||||
<div className="markdown-content">
|
||||
<Markdown remarkPlugins={[remarkMath]} rehypePlugins={[rehypeKatex]} children={formattedContent} />
|
||||
</div>
|
||||
) : (
|
||||
<div>{formattedContent}</div>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
{message.user && (
|
||||
<div>{message.user}</div>
|
||||
)}
|
||||
<div>{formattedContent}</div>
|
||||
{message.role === 'assistant' ? (
|
||||
<div className="markdown-content">
|
||||
<Markdown remarkPlugins={[remarkMath]} rehypePlugins={[rehypeKatex]} children={formattedContent} />
|
||||
</div>
|
||||
) : (
|
||||
<div>{formattedContent}</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user