Skip to content

Conversation

Coussecousse
Copy link

This PR adds web search functionality to the Discord bot, allowing users to get real-time information from the internet through OpenAI's web search preview API.

New Features :

Commands
/websearch [message] - Direct web search command that always uses web search capabilities
/togglewebsearch - Toggle web search mode for all chat interactions (affects both /chat and replyall mode)
Enhanced /chat - Now respects the web search toggle setting

Functionality :

Smart fallback: If web search fails, automatically falls back to regular chat completion
OpenAI integration: Uses OpenAI's responses.create() API with web search preview tools

Web Search Flow

Check if OpenAI is enabled and web search conditions are met
Attempt web search using OpenAI's responses API with web_search_preview tool
On success: Return web search results with citations
On failure: Automatically fallback to regular chat completion

Dependencies

Why httpx==0.27.2 is Required ?
OpenAI Client Dependency: The OpenAI Python library uses httpx as its underlying HTTP client for making async requests
Web Search API: OpenAI's responses API (used for web search) requires reliable async HTTP handling
Version Compatibility: Version 0.27.2 ensures compatibility with openai==1.93.0 and provides:

  • Stable async/await support
  • Proper connection pooling for multiple API calls
  • Timeout handling for web search requests
  • HTTP/2 support for better performance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant