Skip to content

Commit 94a945d

Browse files
authored
Remove unused code (#32)
* Remove unused code * Remove controller * Remove ignored errors
1 parent fc41f18 commit 94a945d

File tree

3 files changed

+0
-282
lines changed

3 files changed

+0
-282
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,5 @@
11
parameters:
22
ignoreErrors:
3-
-
4-
message: '#^Cannot access an offset on mixed\.$#'
5-
identifier: offsetAccess.nonOffsetAccessible
6-
count: 1
7-
path: src/Http/Controllers/LoopController.php
8-
9-
-
10-
message: '#^Cannot access offset ''completion_tokens'' on Prism\\Prism\\ValueObjects\\Usage\.$#'
11-
identifier: offsetAccess.nonOffsetAccessible
12-
count: 1
13-
path: src/Http/Controllers/LoopController.php
14-
15-
-
16-
message: '#^Cannot access offset ''message'' on mixed\.$#'
17-
identifier: offsetAccess.nonOffsetAccessible
18-
count: 1
19-
path: src/Http/Controllers/LoopController.php
20-
21-
-
22-
message: '#^Cannot access offset ''prompt_tokens'' on Prism\\Prism\\ValueObjects\\Usage\.$#'
23-
identifier: offsetAccess.nonOffsetAccessible
24-
count: 1
25-
path: src/Http/Controllers/LoopController.php
26-
27-
-
28-
message: '#^Cannot access offset ''total_tokens'' on Prism\\Prism\\ValueObjects\\Usage\.$#'
29-
identifier: offsetAccess.nonOffsetAccessible
30-
count: 1
31-
path: src/Http/Controllers/LoopController.php
32-
33-
-
34-
message: '#^Cannot access offset ''user'' on mixed\.$#'
35-
identifier: offsetAccess.nonOffsetAccessible
36-
count: 1
37-
path: src/Http/Controllers/LoopController.php
38-
39-
-
40-
message: '#^Cannot cast Prism\\Prism\\Text\\Response to string\.$#'
41-
identifier: cast.string
42-
count: 2
43-
path: src/Http/Controllers/LoopController.php
44-
45-
-
46-
message: '#^Method Kirschbaum\\Loop\\Http\\Controllers\\LoopController\:\:getStoredMessages\(\) should return array\<mixed\> but returns mixed\.$#'
47-
identifier: return.type
48-
count: 1
49-
path: src/Http/Controllers/LoopController.php
50-
51-
-
52-
message: '#^Method Kirschbaum\\Loop\\Http\\Controllers\\LoopController\:\:storeMessageInCache\(\) has parameter \$message with no value type specified in iterable type array\.$#'
53-
identifier: missingType.iterableValue
54-
count: 1
55-
path: src/Http/Controllers/LoopController.php
56-
57-
-
58-
message: '#^Cannot access offset ''message'' on mixed\.$#'
59-
identifier: offsetAccess.nonOffsetAccessible
60-
count: 2
61-
path: src/Loop.php
62-
63-
-
64-
message: '#^Cannot access offset ''user'' on mixed\.$#'
65-
identifier: offsetAccess.nonOffsetAccessible
66-
count: 1
67-
path: src/Loop.php
68-
693
-
704
message: '#^Cannot call method build\(\) on Kirschbaum\\Loop\\Contracts\\Tool\|null\.$#'
715
identifier: method.nonObject
@@ -78,24 +12,6 @@ parameters:
7812
count: 1
7913
path: src/Loop.php
8014

81-
-
82-
message: '#^Parameter \#1 \$content of class Prism\\Prism\\ValueObjects\\Messages\\AssistantMessage constructor expects string, mixed given\.$#'
83-
identifier: argument.type
84-
count: 1
85-
path: src/Loop.php
86-
87-
-
88-
message: '#^Parameter \#1 \$content of class Prism\\Prism\\ValueObjects\\Messages\\UserMessage constructor expects string, mixed given\.$#'
89-
identifier: argument.type
90-
count: 1
91-
path: src/Loop.php
92-
93-
-
94-
message: '#^Parameter \#1 \$tools of method Prism\\Prism\\Text\\PendingRequest\:\:withTools\(\) expects array\<int, Prism\\Prism\\Tool\>, Illuminate\\Support\\Collection given\.$#'
95-
identifier: argument.type
96-
count: 1
97-
path: src/Loop.php
98-
9915
-
10016
message: '#^Instanceof between Prism\\Prism\\Tool and Prism\\Prism\\Tool will always evaluate to true\.$#'
10117
identifier: instanceof.alwaysTrue

src/Http/Controllers/LoopController.php

Lines changed: 0 additions & 145 deletions
This file was deleted.

src/Loop.php

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,9 @@
33
namespace Kirschbaum\Loop;
44

55
use Illuminate\Support\Collection;
6-
use Illuminate\Support\Facades\Auth;
76
use Kirschbaum\Loop\Contracts\Tool;
87
use Kirschbaum\Loop\Contracts\Toolkit;
9-
use Prism\Prism\Enums\Provider;
10-
use Prism\Prism\Prism;
11-
use Prism\Prism\Text\Response;
128
use Prism\Prism\Tool as PrismTool;
13-
use Prism\Prism\ValueObjects\Messages\AssistantMessage;
14-
use Prism\Prism\ValueObjects\Messages\UserMessage;
159

1610
class Loop
1711
{
@@ -42,53 +36,6 @@ public function toolkit(Toolkit $toolkit): static
4236
return $this;
4337
}
4438

45-
/**
46-
* @param Collection<array-key, mixed> $messages
47-
*/
48-
public function ask(string $question, Collection $messages): Response
49-
{
50-
$prompt = sprintf(
51-
"
52-
You are a helpful assistant. You will have many tools available to you. You need to give informations about the data and ask the user what you need to give him what he needs. \n\n
53-
Today is %s. Current month is %s. Current day is %s. Database being used is %s. \n\n
54-
When using the tools, always pass all the parameters listed in the tool. If you don't have all the information, ask the user for it. If it's optional, pass null. \n
55-
When a field is tagged with a access_type read, it means that the field is automatically calculated and is not stored in the database. \n
56-
When referencing an ID, try to fetch the resource of that ID from the database and give additional informations about it. \n\n
57-
When giving the final output, please compress the information to the minimum needed to answer the question. No need to explain what math you did unless explicitly asked. \n\n
58-
Parameter names in tools never include the $ symbol. \n\n
59-
%s \n\n
60-
You are logged in as %s (User ID: %s)
61-
",
62-
now()->format('Y-m-d'),
63-
now()->format('F'),
64-
now()->format('d'),
65-
config()->string('database.default'),
66-
$this->context,
67-
Auth::user()?->name, /** @phpstan-ignore property.notFound */
68-
Auth::user()?->id,
69-
);
70-
dump($prompt);
71-
72-
$messages = $messages
73-
->reject(fn ($message) => empty($message['message']))
74-
->map(function ($message) {
75-
return $message['user'] === 'AI'
76-
? new AssistantMessage($message['message'])
77-
: new UserMessage($message['message']);
78-
})->toArray();
79-
80-
$messages[] = new UserMessage($question);
81-
82-
return Prism::text()
83-
// ->using(Provider::Anthropic, 'claude-3-5-sonnet-latest')
84-
->using(Provider::OpenAI, 'gpt-4o-mini')
85-
->withMaxSteps(10)
86-
->withMessages($messages)
87-
->withSystemPrompt($prompt)
88-
->withTools($this->getPrismTools())
89-
->asText();
90-
}
91-
9239
public function getPrismTools(): Collection
9340
{
9441
return $this->loopTools

0 commit comments

Comments
 (0)