File tree 2 files changed +22
-0
lines changed
2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change 11
11
use EchoLabs \Prism \Requests \TextRequest ;
12
12
use EchoLabs \Prism \ValueObjects \ToolCall ;
13
13
use EchoLabs \Prism \ValueObjects \Usage ;
14
+ use InvalidArgumentException ;
14
15
use Throwable ;
15
16
16
17
class Ollama implements Provider
@@ -24,6 +25,8 @@ public function __construct(
24
25
public function text (TextRequest $ request ): ProviderResponse
25
26
{
26
27
try {
28
+ $ this ->validateTextRequest ($ request );
29
+
27
30
$ response = $ this
28
31
->client ($ request ->clientOptions )
29
32
->messages (
@@ -68,6 +71,13 @@ public function text(TextRequest $request): ProviderResponse
68
71
);
69
72
}
70
73
74
+ protected function validateTextRequest (TextRequest $ textRequest ): void
75
+ {
76
+ if ($ textRequest ->toolChoice ) {
77
+ throw new InvalidArgumentException ('Invalid tool choice ' );
78
+ }
79
+ }
80
+
71
81
/**
72
82
* @param array<int, array<string, mixed>> $toolCalls
73
83
* @return array<int, ToolCall>
Original file line number Diff line number Diff line change 5
5
namespace Tests \Providers \Ollama ;
6
6
7
7
use EchoLabs \Prism \Enums \Provider ;
8
+ use EchoLabs \Prism \Exceptions \PrismException ;
8
9
use EchoLabs \Prism \Facades \Tool ;
9
10
use EchoLabs \Prism \Prism ;
10
11
use EchoLabs \Prism \ValueObjects \Messages \Support \Image ;
102
103
"Today's Tigers game in Detroit starts at 3 PM. The current temperature is 75°F with clear skies, so you shouldn't need a coat. Enjoy the game! "
103
104
);
104
105
});
106
+
107
+ it ('throws an exception for ToolChoice ' , function (): void {
108
+ $ this ->expectException (PrismException::class);
109
+ $ this ->expectExceptionMessage ('Invalid tool choice ' );
110
+
111
+ Prism::text ()
112
+ ->using (Provider::Ollama, 'qwen2.5:14b ' )
113
+ ->withPrompt ('Who are you? ' )
114
+ ->withToolChoice ('weather ' )
115
+ ->generate ();
116
+ });
105
117
});
106
118
107
119
describe ('Image support ' , function (): void {
You can’t perform that action at this time.
0 commit comments