-
Notifications
You must be signed in to change notification settings - Fork 0
/
03-extract-class-info.php
117 lines (107 loc) · 3.65 KB
/
03-extract-class-info.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
declare(strict_types=1);
/*
* This file is part of PHP LLM Documents.
*
* (c) Thomas Joußen <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
use Google\Client;
use Thojou\LLMDocuments\Crawler\Spatie\SpatieCrawlerConfig;
use Thojou\LLMDocuments\Crawler\Spatie\SpatieCrawlerFactory;
use Thojou\LLMDocuments\Document\Document;
use Thojou\LLMDocuments\Document\DocumentInterface;
use Thojou\LLMDocuments\Embedding\OpenAi\OpenAiEmbeddings;
use Thojou\LLMDocuments\Loader\FilesystemLoader;
use Thojou\LLMDocuments\Loader\WebSearchLoader;
use Thojou\LLMDocuments\Parser\Unstructured\Api\UnstructuredAPI;
use Thojou\LLMDocuments\Parser\Unstructured\UnstructuredParserFactory;
use Thojou\LLMDocuments\Retriever\ParentDocumentRetriever;
use Thojou\LLMDocuments\Retriever\SimilarityRetriever;
use Thojou\LLMDocuments\Search\Google\GoogleSearchEngineFactory;
use Thojou\LLMDocuments\Splitter\RecursiveTextSplitter;
use Thojou\LLMDocuments\Storage\DocumentStore\LocalDocumentStore;
use Thojou\LLMDocuments\Storage\VectorStore\LocalVectorStore;
use Thojou\LLMDocuments\Transformation\DocumentTransformationBuilder;
use Thojou\LLMDocuments\ValueObjects\DoctranConfig;
use Thojou\LLMDocuments\ValueObjects\ExtractProperty;
use Thojou\LLMDocuments\ValueObjects\FunctionParameters;
use Thojou\OpenAi\OpenAi;
use Thojou\SimpleApiClient\Adapter\GuzzleClientFactory;
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/credentials.php';
// INPUT
$filepath = $argv[1];
// Define the OpenAI API Interface
$openAI = new OpenAi(
OPENAI_KEY,
);
$loader = new FilesystemLoader('/.*.php/');
$documents = $loader->load($filepath);
$extractor = (new DocumentTransformationBuilder(new DoctranConfig($openAI, 'gpt-4', 4000)))
->extract([
new ExtractProperty(
'className',
'string',
'The class\'s FQN',
),
new ExtractProperty(
'type',
'string',
'The type of the class (interface, class, trait)',
),
new ExtractProperty(
'extends',
'string',
'The name of the extended class.',
),
new ExtractProperty(
'docBlock',
'string',
'The docblock above the class definition',
),
new ExtractProperty(
'interfaces',
'array',
'A list of FQN names of all implemented interfaces.',
items: [
'type' => 'string',
'description' => 'The FQN of the implemented interface',
]
),
new ExtractProperty(
'imports',
'array',
'List of all imports inside the file',
items: [
'type' => 'string',
'description' => 'The FQN of the imported file',
]
),
new ExtractProperty(
'methods',
'array',
'A List of all method signatures',
items: (new FunctionParameters())
->add(new ExtractProperty(
'name',
'string',
'The name of the method',
))
->add(new ExtractProperty(
'signature',
'string',
'The method signature',
))
->add(new ExtractProperty(
'docBlock',
'string',
'The docblock describing the method',
))
->toArray()
)
]);
var_dump($extractor->execute($documents));
exit;