Skip to content

feat(fim): add FIM request and response handling for Mistral AI#1014

Open
mssayari wants to merge 1 commit intoprism-php:mainfrom
mssayari:feat/fim-implementation
Open

feat(fim): add FIM request and response handling for Mistral AI#1014
mssayari wants to merge 1 commit intoprism-php:mainfrom
mssayari:feat/fim-implementation

Conversation

@mssayari
Copy link
Copy Markdown

@mssayari mssayari commented Apr 15, 2026

I've implemented the Mistral Fill-in-the-Middle (FIM) Completion endpoint. This involved creating a new generic FIM architecture within Prism so that other providers can also implement FIM in the future.

Key Changes

Core FIM Architecture

  • [NEW] Request.php: Data object for FIM requests.
  • [NEW] Response.php: Data object for FIM responses.
  • [NEW] PendingRequest.php: Fluent builder for configuring FIM requests.
  • [MODIFY] Prism.php: Added fim() method.
  • [MODIFY] Provider.php: Added fim() signature.

Mistral Provider Implementation

  • [MODIFY] Mistral.php: Integrated the FIM handler.
  • [NEW] Fim.php: Handler that interacts with Mistral's /fim/completions endpoint.

Testing

  • [NEW] MistralFimTest.php: Comprehensive tests covering successful generation and rate limit metadata.
  • [NEW] fim-completion-1.json: Test fixture for FIM responses.

Usage Example

use Prism\Prism\Facades\Prism;
use Prism\Prism\Enums\Provider;

$response = Prism::fim()
    ->using(Provider::Mistral, 'codestral-latest')
    ->withPrompt('def add(a, b):')
    ->withSuffix('    print("Done")')
    ->asText();

echo $response->text; // "return a+b"

Endpoint URLs:
https://docs.mistral.ai/api/endpoint/fim
https://docs.mistral.ai/capabilities/code_generation

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