Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Bug]: This is a chat model and not supported in the v1/completions endpoint. Did you mean to use v1/chat/completions? #491

Copy link
Copy link
Closed
@marcellopato

Description

@marcellopato
Issue body actions

Description

Laravel Framework 11.29.0

`public function extractDataFromPDF($pdfPath)
{
    // Extrair o texto do PDF usando o PdfParser
    $parser = new Parser();
    $pdf = $parser->parseFile($pdfPath);
    $pdfText = $pdf->getText();

    // Dividir o texto em partes menores, se necessário, para evitar o limite de tokens
    $chunks = str_split($pdfText, 4000); // Ajuste o tamanho do chunk conforme necessário
    $extractedData = [];

    foreach ($chunks as $chunk) {
        $result = $this->client->completions()->create([
            'model' => 'gpt-4',
            'prompt' => "Aqui está uma parte do conteúdo do PDF:\n\n" . $chunk . "\n\nExtraia os dados estruturados de forma adequada para alimentar o banco de dados.",
            'max_tokens' => 1500,
        ]);

        $extractedData[] = $result['choices'][0]['text'];
    }

    // Combinar os dados extraídos de cada parte
    $finalData = implode(" ", $extractedData);

    // Tentar decodificar para JSON, caso o ChatGPT tenha retornado em JSON
    $structuredData = json_decode($finalData, true);

    // Retorna os dados estruturados ou o texto completo
    return $structuredData ?: $finalData;
}`

Steps To Reproduce

Uploading a file
Extract the text from the PDF using PdfParser
Split the text into smaller parts, if necessary, to avoid the token limit

OpenAI PHP Client Version

^0.10.2

PHP Version

PHP 8.3.12 (cli) (built: Sep 27 2024 03:53:05) (NTS) Copyright (c) The PHP Group Zend Engine v4.3.12, Copyright (c) Zend Technologies with Zend OPcache v8.3.12, Copyright (c), by Zend Technologies with Xdebug v3.3.2, Copyright (c) 2002-2024, by Derick Rethans

Notes

Can someone help me!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.