optional sources
All checks were successful
Build and Push Discord Bot Docker Image / build (push) Successful in 1m0s
All checks were successful
Build and Push Discord Bot Docker Image / build (push) Successful in 1m0s
This commit is contained in:
@@ -41,20 +41,26 @@ class AgentClient:
|
|||||||
logger.warning(f"Agent health check failed: {e}")
|
logger.warning(f"Agent health check failed: {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
async def query(self, message: str) -> str:
|
async def query(self, message: str, sources_only: bool | None = None) -> str:
|
||||||
"""
|
"""
|
||||||
Send a query to the agent and return the response.
|
Send a query to the agent and return the response.
|
||||||
|
|
||||||
The agent uses AG-UI protocol with SSE streaming. We collect
|
The agent uses AG-UI protocol with SSE streaming. We collect
|
||||||
the full response for Discord (which doesn't support streaming).
|
the full response for Discord (which doesn't support streaming).
|
||||||
|
|
||||||
|
Args:
|
||||||
|
message: The query to send
|
||||||
|
sources_only: Override the default sources_only setting
|
||||||
"""
|
"""
|
||||||
if not self._client:
|
if not self._client:
|
||||||
raise RuntimeError("Agent client not initialized")
|
raise RuntimeError("Agent client not initialized")
|
||||||
|
|
||||||
|
use_sources_only = sources_only if sources_only is not None else self.sources_only
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"x-user-roles": json.dumps(self.default_roles),
|
"x-user-roles": json.dumps(self.default_roles),
|
||||||
"x-sources-only": "true" if self.sources_only else "false",
|
"x-sources-only": "true" if use_sources_only else "false",
|
||||||
}
|
}
|
||||||
|
|
||||||
# AG-UI protocol request format (RunAgentInput)
|
# AG-UI protocol request format (RunAgentInput)
|
||||||
|
|||||||
@@ -58,11 +58,17 @@ class CavepediaBot(discord.Client):
|
|||||||
"""Called when the bot is starting up."""
|
"""Called when the bot is starting up."""
|
||||||
await self.agent_client.start()
|
await self.agent_client.start()
|
||||||
|
|
||||||
# Register the cavesearch command
|
# Register the cavesearch command (sources only)
|
||||||
@self.tree.command(name="cavesearch", description="Search the caving knowledge base")
|
@self.tree.command(name="cavesearch", description="Search the caving knowledge base (sources only)")
|
||||||
@app_commands.describe(query="Your question about caving")
|
@app_commands.describe(query="Your question about caving")
|
||||||
async def cavesearch(interaction: discord.Interaction, query: str):
|
async def cavesearch(interaction: discord.Interaction, query: str):
|
||||||
await self.handle_search(interaction, query)
|
await self.handle_search(interaction, query, sources_only=True)
|
||||||
|
|
||||||
|
# Register the cavechat command (full response)
|
||||||
|
@self.tree.command(name="cavechat", description="Ask the caving AI assistant")
|
||||||
|
@app_commands.describe(query="Your question about caving")
|
||||||
|
async def cavechat(interaction: discord.Interaction, query: str):
|
||||||
|
await self.handle_search(interaction, query, sources_only=False)
|
||||||
|
|
||||||
# Sync commands to specific guilds for instant availability
|
# Sync commands to specific guilds for instant availability
|
||||||
for guild_id in [1137321345718439959, 1454125232439955471]:
|
for guild_id in [1137321345718439959, 1454125232439955471]:
|
||||||
@@ -91,8 +97,8 @@ class CavepediaBot(discord.Client):
|
|||||||
else:
|
else:
|
||||||
logger.warning("Agent server health check failed")
|
logger.warning("Agent server health check failed")
|
||||||
|
|
||||||
async def handle_search(self, interaction: discord.Interaction, query: str):
|
async def handle_search(self, interaction: discord.Interaction, query: str, sources_only: bool):
|
||||||
"""Handle the /cavesearch command."""
|
"""Handle the /cavesearch and /cavechat commands."""
|
||||||
# Check if channel is allowed
|
# Check if channel is allowed
|
||||||
if interaction.channel_id not in self.config.allowed_channels:
|
if interaction.channel_id not in self.config.allowed_channels:
|
||||||
await interaction.response.send_message(
|
await interaction.response.send_message(
|
||||||
@@ -115,7 +121,7 @@ class CavepediaBot(discord.Client):
|
|||||||
f"Processing query from {interaction.user} in #{interaction.channel}: {query[:100]}..."
|
f"Processing query from {interaction.user} in #{interaction.channel}: {query[:100]}..."
|
||||||
)
|
)
|
||||||
|
|
||||||
response = await self.agent_client.query(query)
|
response = await self.agent_client.query(query, sources_only=sources_only)
|
||||||
|
|
||||||
# Discord has a 2000 character limit
|
# Discord has a 2000 character limit
|
||||||
if len(response) > 2000:
|
if len(response) > 2000:
|
||||||
|
|||||||
Reference in New Issue
Block a user