src.ai.providers.openai_provider module#

OpenAI Provider for Marcus AI.

Implements semantic task analysis using OpenAI’s GPT models as a fallback or alternative to Anthropic Claude.

This provider integrates with OpenAI’s API to provide: - Task semantic analysis - Dependency inference - Enhanced descriptions - Effort estimation - Blocker analysis

Classes#

OpenAIProvider

OpenAI GPT provider implementation

Notes

Requires OPENAI_API_KEY environment variable. Model selection via OPENAI_MODEL environment variable.

class src.ai.providers.openai_provider.OpenAIProvider[source]#

Bases: BaseLLMProvider

OpenAI GPT provider for semantic AI analysis.

Provides fallback capability when Anthropic is unavailable or alternative AI perspective for comparison.

Parameters:

None

api_key#

OpenAI API key from environment

Type:

str

base_url#

OpenAI API base URL

Type:

str

model#

GPT model to use (default: gpt-3.5-turbo)

Type:

str

max_tokens#

Maximum tokens for responses

Type:

int

timeout#

API request timeout in seconds

Type:

float

client#

Async HTTP client for API calls

Type:

httpx.AsyncClient

Raises:

ValueError – If OPENAI_API_KEY is not set

Examples

>>> provider = OpenAIProvider()
>>> analysis = await provider.analyze_task(task, context)
__init__()[source]#
Return type:

None

async analyze_task(task, context)[source]#

Analyze task semantics using GPT.

Parameters:
  • task (Task) – Task to analyze

  • context (Dict[str, Any]) – Project context

Returns:

Semantic analysis with fallback on error

Return type:

SemanticAnalysis

async infer_dependencies(tasks)[source]#

Infer semantic dependencies using GPT.

Parameters:

tasks (List[Task]) – Tasks to analyze for dependencies

Returns:

Inferred dependencies, empty list on error

Return type:

List[SemanticDependency]

async generate_enhanced_description(task, context)[source]#

Generate enhanced description using GPT.

Return type:

str

Parameters:
async estimate_effort(task, context)[source]#

Estimate effort using GPT.

Return type:

EffortEstimate

Parameters:
async analyze_blocker(task, blocker, context)[source]#

Analyze blocker using GPT.

Return type:

List[str]

Parameters:
async complete(prompt, max_tokens=2000)[source]#

Generate a completion for the given prompt.

Parameters:
  • prompt (str)

  • max_tokens (int)

Return type:

str

Returns:

The completion text

async close()[source]#

Close HTTP client.

Return type:

None