Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 73
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
PromptTypeTrait
0.00% covered (danger)
0.00%
0 / 73
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getPromptByFeatureAndName
0.00% covered (danger)
0.00%
0 / 73
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace App\Traits\Prompts;
4
5use App\Http\Models\Prompts\PromptType;
6
7trait PromptTypeTrait
8{
9    public function getPromptByFeatureAndName($feature, $name)
10    {
11        $pipeline = [
12            [
13                '$match' => [
14                    'is_active' => true,
15                    'feature' => $feature,
16                    'name' => $name
17                ]
18            ],
19            [
20                '$lookup' => [
21                    'from' => 'prompt_setting',
22                    'let' => [
23                        'prompt_setting_id' => ['$toObjectId' => '$prompt_setting_id']
24                    ],
25                    'pipeline' => [
26                        [
27                            '$match' => [
28                                '$expr' => [
29                                    '$and' => [
30                                        ['$eq' => ['$_id', '$$prompt_setting_id']],
31                                        ['$eq' => ['$is_active', true]]
32                                    ]
33                                ]
34                            ]
35                        ],
36                        [
37                            '$lookup' => [
38                                'from' => 'prompt_model',
39                                'let' => [
40                                    'prompt_model_id' => ['$toObjectId' => '$prompt_model_id']
41                                ],
42                                'pipeline' => [
43                                    [
44                                        '$match' => [
45                                            '$expr' => [
46                                                '$and' => [
47                                                    ['$eq' => ['$_id', '$$prompt_model_id']],
48                                                    ['$eq' => ['$is_active', true]]
49                                                ]
50                                            ]
51                                        ]
52                                    ]
53                                ],
54                                'as' => 'model'
55                            ]
56                        ]
57                    ],
58                    'as' => 'setting'
59                ]
60            ],
61            [
62                '$unwind' => '$setting'
63            ],
64            [
65                '$unwind' => '$setting.model'
66            ],
67            [
68                '$project' => [
69                    'promptInstructions' => '$instructions',
70                    'query' => '$mission',
71                    'persona' => '$persona',
72                    'region' => '$setting.region',
73                    'temperature' => '$setting.temperature',
74                    'output_token_limit' => '$setting.output_token_limit',
75                    'top_p' => '$setting.top_p',
76                    'model' => '$setting.model.name',
77                    'settingInstructions' => '$setting.instructions'
78                ]
79            ]
80        ];
81
82        return PromptType::raw(function ($collection) use ($pipeline) {
83            return $collection->aggregate($pipeline);
84        });
85    }
86}