2
2
3
3
namespace NeuronAI \Providers ;
4
4
5
+ use GuzzleHttp \Exception \GuzzleException ;
6
+ use NeuronAI \Messages \AssistantMessage ;
5
7
use NeuronAI \Messages \Message ;
8
+ use NeuronAI \Messages \UserMessage ;
6
9
use NeuronAI \Tools \Tool ;
7
10
use NeuronAI \Tools \ToolInterface ;
8
11
use NeuronAI \Tools \ToolCallMessage ;
@@ -40,9 +43,8 @@ class Anthropic implements AIProviderInterface
40
43
public function __construct (
41
44
protected string $ key ,
42
45
protected string $ model ,
43
- protected string $ version ,
44
- protected int $ max_tokens ,
45
- protected int $ context_window ,
46
+ protected string $ version = '2023-06-01 ' ,
47
+ protected int $ max_tokens = 8192 ,
46
48
protected ?float $ temperature = null ,
47
49
protected ?array $ stop_sequences = null ,
48
50
) {
@@ -68,14 +70,14 @@ public function systemPrompt(string $prompt): AIProviderInterface
68
70
/**
69
71
* Send a prompt to the AI agent.
70
72
*
71
- * @param array|string $prompt
72
- * @return Message
73
- * @throws \Exception
73
+ * @throws GuzzleException
74
74
*/
75
75
public function chat (array |string $ prompt ): Message
76
76
{
77
77
if (\is_string ($ prompt )) {
78
- $ prompt = [['role ' => 'user ' , 'content ' => $ prompt ]];
78
+ $ prompt = [
79
+ new UserMessage ($ prompt )
80
+ ];
79
81
}
80
82
81
83
$ json = \array_filter ([
@@ -106,7 +108,7 @@ public function chat(array|string $prompt): Message
106
108
$ content ['input ' ]
107
109
);
108
110
} else {
109
- $ response = new Message ( ' assistant ' , \last ($ result ['content ' ])['text ' ]);
111
+ $ response = new AssistantMessage ( \last ($ result ['content ' ])['text ' ]);
110
112
}
111
113
112
114
// Attach the usage for the current interaction
@@ -122,26 +124,6 @@ public function chat(array|string $prompt): Message
122
124
return $ response ;
123
125
}
124
126
125
- /**
126
- * The context window limitation of the LLM.
127
- *
128
- * @return int
129
- */
130
- public function contextWindow (): int
131
- {
132
- return $ this ->context_window ;
133
- }
134
-
135
- /**
136
- * The maximum number of tokens to generate before stopping.
137
- *
138
- * @return int
139
- */
140
- public function maxCompletionTokens (): int
141
- {
142
- return $ this ->max_tokens ;
143
- }
144
-
145
127
public function setTools (array $ tools ): self
146
128
{
147
129
$ this ->tools = $ tools ;
0 commit comments