|
3 | 3 | namespace Kirschbaum\Loop;
|
4 | 4 |
|
5 | 5 | use Illuminate\Support\Collection;
|
6 |
| -use Illuminate\Support\Facades\Auth; |
7 | 6 | use Kirschbaum\Loop\Contracts\Tool;
|
8 | 7 | use Kirschbaum\Loop\Contracts\Toolkit;
|
9 |
| -use Prism\Prism\Enums\Provider; |
10 |
| -use Prism\Prism\Prism; |
11 |
| -use Prism\Prism\Text\Response; |
12 | 8 | use Prism\Prism\Tool as PrismTool;
|
13 |
| -use Prism\Prism\ValueObjects\Messages\AssistantMessage; |
14 |
| -use Prism\Prism\ValueObjects\Messages\UserMessage; |
15 | 9 |
|
16 | 10 | class Loop
|
17 | 11 | {
|
@@ -42,53 +36,6 @@ public function toolkit(Toolkit $toolkit): static
|
42 | 36 | return $this;
|
43 | 37 | }
|
44 | 38 |
|
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 |
| - |
92 | 39 | public function getPrismTools(): Collection
|
93 | 40 | {
|
94 | 41 | return $this->loopTools
|
|
0 commit comments