Solution providers

The most relevant components when it comes to the actual problem solving are solution providers. Each solution provider describes a way to solve a given problem.

interface EliasHaeussler\Typo3Solver\ProblemSolving\Solution\Provider\SolutionProvider

Interface for solution providers used to provide a solution for a given problem. Solution providers can be combined with EliasHaeussler\Typo3Solver\ProblemSolving\Solution\Provider\CacheSolutionProvider if they are cacheable.

static create

Create a new instance of the solution provider. This is mainly used on a low level basis where dependency injection is not available.

Returns

An instance of the current solution provider.

getSolution($problem)

Provide a solution for the given problem.

Parameters
  • $problem (EliasHaeussler\Typo3Solver\ProblemSolving\Problem\Problem) -- The problem to be solved

Return type

EliasHaeussler\Typo3Solver\ProblemSolving\Solution\Solution

Throws

EliasHaeussler\Typo3Solver\Exception\UnableToSolveException

canBeUsed($exception)

Define whether the solution provider can handle the given exception. This is especially useful to skip problem solving for some exceptions whose solution is already known or is too specific to solve.

Parameters
  • $exception (Throwable) -- The exception to test for compatibility

Return type

bool

isCacheable()

Define whether solutions provided by this solution provider should be cached when using the solution provider in combination with EliasHaeussler\Typo3Solver\ProblemSolving\Solution\Provider\CacheSolutionProvider.

Return type

bool

interface EliasHaeussler\Typo3Solver\ProblemSolving\Solution\Provider\StreamedSolutionProvider

Extended interface for solution providers that are able to stream solutions. Read more about a practical use case of this interface at Streamed solution.

getStreamedSolution($problem)

Provide a solution stream for the given problem. The stream is returned as an instance of Traversable, while each traversed item is an instance of EliasHaeussler\Typo3Solver\ProblemSolving\Solution\Solution.

Parameters
  • $problem (EliasHaeussler\Typo3Solver\ProblemSolving\Problem\Problem) -- The problem to be solved

Return type

Traversable<EliasHaeussler\Typo3Solver\ProblemSolving\Solution\Solution>

Throws

EliasHaeussler\Typo3Solver\Exception\UnableToSolveException

Default providers

The extension ships with a default provider:

class EliasHaeussler\Typo3Solver\ProblemSolving\Solution\Provider\OpenAISolutionProvider

Default provider used to generate solutions using the configured OpenAI model. It uses the chat completion endpoint and is therefore streamable.

Note

Streamed solutions always provide the complete solution delivered until the current solution delta for each iteration.

In addition, there's also a cached provider. It decorates a concrete solution provider with an additional cache layer. This avoids too many requests to the OpenAI endpoint.

class EliasHaeussler\Typo3Solver\ProblemSolving\Solution\Provider\CacheSolutionProvider

This provider decorates a concrete solution provider with an additional cache layer. The concrete solution provider must be provided in the EliasHaeussler\Typo3Solver\ProblemSolving\Solution\Provider\SolutionProvider::create method.

Note

Read more at Caching.