Skip to content

Commit

Permalink
Claude tools working
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed Apr 5, 2024
1 parent ec8f667 commit e2170a1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
19 changes: 9 additions & 10 deletions app/LlmDriver/ClaudeClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ protected function getClient()
])->baseUrl($this->baseUrl);
}

/**
/**
* This is to get functions out of the llm
* if none are returned your system
* can error out or try another way.
Expand All @@ -145,7 +145,7 @@ public function functionPromptChat(array $messages, array $only = []): array
'system' => 'Return a markdown response.',
'max_tokens' => $maxTokens,
'messages' => $messages,
'tools' => $this->getFunctions()
'tools' => $this->getFunctions(),
]);

$functions = [];
Expand All @@ -162,18 +162,17 @@ public function functionPromptChat(array $messages, array $only = []): array

$stop_reason = $results->json()['stop_reason'];

if($stop_reason === 'tool_use') {
if ($stop_reason === 'tool_use') {

foreach ($results->json()['content'] as $content) {
if(data_get($content, 'type') === 'tool_use') {
if (data_get($content, 'type') === 'tool_use') {
$functions[] = [
'name' => data_get($content, 'name') ,
'name' => data_get($content, 'name'),
'arguments' => data_get($content, 'input'),
];
}
}
}
}

}

/**
* @TODO
Expand All @@ -182,7 +181,6 @@ public function functionPromptChat(array $messages, array $only = []): array
return $functions;
}


/**
* @NOTE
* Since this abstraction layer is based on OpenAi
Expand Down Expand Up @@ -228,7 +226,8 @@ public function getFunctions(): array
/**
* @param MessageInDto[] $messages
*/
protected function remapMessagesForClaude(array $messages) : array {
protected function remapMessagesForClaude(array $messages): array
{
$messages = collect($messages)->map(function ($item) {
if ($item->role === 'system') {
$item->role = 'assistant';
Expand Down
1 change: 0 additions & 1 deletion tests/Feature/ClaudeClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ public function test_chat_with_multiple_assistant_messages(): void

}


public function test_get_functions(): void
{
$openaiClient = new \App\LlmDriver\ClaudeClient();
Expand Down

0 comments on commit e2170a1

Please sign in to comment.