Skip to content

Is there any way to detect and log api calls to providers such as open ai ? #924

@sagautam5

Description

@sagautam5

Previous Flow

Previously, I was using custom approach for api integration with open ai for prompt based response like this:

$response = $this->client->request('POST', $apiUrl, [
            'headers' => [
                'Content-Type' => 'application/json',
                'Authorization' => 'Bearer '.config('openai.api_key'),
            ],
            'json' => $body,
        ]);

In this approach, I knew what's the request body and response body and logged this information into database table. Main purpose was for debugging and evaluation purpose.

Upgrade flow to align with Prism PHP

Now I have upgraded this logic with prism php. Now, it looks like this:

Prism::structured()
            ->withSchema($schema)
            ->using(Provider::OpenAI, config('openai.model'))
            ->withSystemPrompt($systemPrompt)
            ->withProviderOptions([
                'temperature' => Config::get('openai.temperature'),
                'max_tokens' => Config::get('openai.max_tokens'),
            ])
            ->asStructured()
            ->structured;

Additional Context

In this flow, it's really hard to identify request body and response body. Generally these kind of things are handled via events and listeners.
Is there any built in workflow that allows us to detect requests and responses so that we can log details into database or some file ?

Note: I went through the docs, existing issues and opened pull requests and looked for relevant information, but could not find such thing

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions