-
-
Notifications
You must be signed in to change notification settings - Fork 507
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for tool_calls on the chat completion endpoint
- Loading branch information
1 parent
03a24a6
commit cf6c443
Showing
19 changed files
with
428 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenAI\Responses\Chat; | ||
|
||
final class CreateResponseToolCall | ||
{ | ||
private function __construct( | ||
public readonly string $id, | ||
public readonly string $type, | ||
public readonly CreateResponseToolCallFunction $function, | ||
) { | ||
} | ||
|
||
/** | ||
* @param array{id: string, type: string, function: array{name: string, arguments: string}} $attributes | ||
*/ | ||
public static function from(array $attributes): self | ||
{ | ||
return new self( | ||
$attributes['id'], | ||
$attributes['type'], | ||
CreateResponseToolCallFunction::from($attributes['function']), | ||
); | ||
} | ||
|
||
/** | ||
* @return array{id: string, type: string, function: array{name: string, arguments: string}} | ||
*/ | ||
public function toArray(): array | ||
{ | ||
return [ | ||
'id' => $this->id, | ||
'type' => $this->type, | ||
'function' => $this->function->toArray(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenAI\Responses\Chat; | ||
|
||
final class CreateResponseToolCallFunction | ||
{ | ||
private function __construct( | ||
public readonly string $name, | ||
public readonly string $arguments, | ||
) { | ||
} | ||
|
||
/** | ||
* @param array{name: string, arguments: string} $attributes | ||
*/ | ||
public static function from(array $attributes): self | ||
{ | ||
return new self( | ||
$attributes['name'], | ||
$attributes['arguments'], | ||
); | ||
} | ||
|
||
/** | ||
* @return array{name: string, arguments: string} | ||
*/ | ||
public function toArray(): array | ||
{ | ||
return [ | ||
'name' => $this->name, | ||
'arguments' => $this->arguments, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenAI\Responses\Chat; | ||
|
||
final class CreateStreamedResponseToolCall | ||
{ | ||
private function __construct( | ||
public readonly ?string $id, | ||
public readonly ?string $type, | ||
public readonly CreateStreamedResponseToolCallFunction $function, | ||
) { | ||
} | ||
|
||
/** | ||
* @param array{id?: string, type?: string, function: array{name?: string, arguments: string}} $attributes | ||
*/ | ||
public static function from(array $attributes): self | ||
{ | ||
return new self( | ||
$attributes['id'] ?? null, | ||
$attributes['type'] ?? null, | ||
CreateStreamedResponseToolCallFunction::from($attributes['function']), | ||
); | ||
} | ||
|
||
/** | ||
* @return array{id?: string, type?: string, function?: array{name?: string, arguments: string}} | ||
*/ | ||
public function toArray(): array | ||
{ | ||
return array_filter([ | ||
'id' => $this->id, | ||
'type' => $this->type, | ||
'function' => $this->function->toArray(), | ||
]); | ||
} | ||
} |
Oops, something went wrong.