Skip to content

refactor(core): Introduce provider architecture#382

Merged
Mzack9999 merged 5 commits intoprojectdiscovery:devfrom
hanXen:refactor/provider-architecture
Oct 21, 2025
Merged

refactor(core): Introduce provider architecture#382
Mzack9999 merged 5 commits intoprojectdiscovery:devfrom
hanXen:refactor/provider-architecture

Conversation

@hanXen
Copy link
Copy Markdown

@hanXen hanXen commented Aug 5, 2025

Related to #306

1. What this PR does / Why we need it

This Pull Request addresses issue #306 by refactoring the core architecture of aix to support multiple LLM providers. It decouples the application from its tight integration with OpenAI by introducing a generic Provider interface.

This PR focuses exclusively on the foundational architectural changes and does not yet add a new provider. The primary goal here is to make the codebase more scalable, maintainable, and future-proof without altering any existing functionality.

A subsequent PR will leverage this new architecture to add support for local LLMs via Ollama.

2. Key Architectural Changes

To address the limitations of the original design, we've implemented a provider-centric architecture. The key changes are as follows:

2.1. Provider Interface

  • We introduced a new Provider interface in internal/provider/provider.go.
  • This interface defines a common contract that all LLM providers must adhere to, standardizing core operations:
    type Provider interface {
        Name() string
        ListModels(ctx context.Context) ([]string, error)
        Chat(ctx context.Context, prompt string, systemPrompt string, opts ChatOptions) (Result, error)
        ChatStream(ctx context.Context, prompt string, systemPrompt string, opts ChatOptions) (StreamResult, error)
    }

2.2. OpenAIProvider

  • The original OpenAI logic from runner.go was migrated into a new internal/provider/openai.go file.
  • This new OpenAIProvider fully implements the Provider interface, encapsulating all OpenAI-specific logic.

2.3. Refactored runner.go

  • The Runner now acts as a high-level dispatcher.
  • It is no longer concerned with the implementation details of any specific provider. Based on the --provider flag, it will instantiate the appropriate provider and delegate all LLM-related tasks to it.

2.4. Unified and Improved CLI Flags

  • --provider: A new flag to select the desired provider. In this PR, it only supports the default openai.
  • --model Consolidation: The --gpt3 and --gpt4 flags have been removed. Model selection is now handled exclusively by the --model flag for a consistent experience (e.g., aix --model gpt-4-turbo).

    This change is backward-compatible for typical usage. Scripts explicitly using --gpt3 or --gpt4 may need to update.


3. Verification: No Functionality Change

A primary goal of this refactoring was to ensure no existing functionality was lost. All features from the original OpenAI-only implementation have been successfully carried over.

Original Feature Current Status & Analysis
API Key Handling Preserved. The logic for handling the OpenAI API key remains unchanged.
Model Selection Improved. The --gpt3/--gpt4 flags were deprecated in favor of a single, clearer --model flag. This is a non-breaking improvement in user experience and extensibility.
--list-models Preserved. This flag continues to list models for OpenAI as before.
Chat (Non-Streaming) Preserved. All parameters, including Temperature and TopP, are correctly passed to the OpenAI client via the new ChatOptions struct.
Chat (Streaming) Preserved. The core logic using go-openai's streaming client and io.Pipe remains identical, ensuring the same performance and behavior.
System Prompt Preserved. The --system-context (-sc) flag functions exactly as it did before.

4. Next Steps

Once this PR is approved and merged, I will submit a follow-up PR introducing the OllamaProvider. This will enable local LLM support, fully resolving issue #306.

@dogancanbakir dogancanbakir self-requested a review August 12, 2025 19:16
@Mzack9999 Mzack9999 linked an issue Oct 21, 2025 that may be closed by this pull request
@Mzack9999 Mzack9999 merged commit d149a75 into projectdiscovery:dev Oct 21, 2025
7 checks passed
@hanXen hanXen deleted the refactor/provider-architecture branch November 27, 2025 12:19
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.

Support local LLMs

2 participants