-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Cohere): Added Cohere to list of supported models and more...
- Added Cohere Driver - Refactored code - Added ability to design the request using requestRules - Removed config and instead reference in the driver - Updated Playground on Conversations to allow the user to change AI/Model - Ability to modify the key for certain colums when building up array for payload This is mainly prep for a future release, there are still a few things that need ironing out before it can tagged as a new version
- Loading branch information
1 parent
a8c7bac
commit c5c15c9
Showing
14 changed files
with
379 additions
and
156 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,97 @@ | ||
<?php | ||
|
||
namespace PapaRascalDev\Sidekick\Drivers; | ||
|
||
use PapaRascalDev\Sidekick\Features\Completion; | ||
|
||
class Cohere implements Driver | ||
{ | ||
|
||
/** | ||
* OpenAi Api Base URL | ||
* @strind $baseUrl | ||
*/ | ||
private string $baseUrl = "https://api.cohere.com/v1"; | ||
|
||
/** | ||
* Headers | ||
* | ||
* To be passed with every request | ||
* | ||
* @array $headers | ||
*/ | ||
protected array $headers; | ||
|
||
public array $messageRoles = [ | ||
'user' => 'USER', | ||
'assistant' => 'CHATBOT' | ||
]; | ||
|
||
public bool $listAsObject = true; | ||
|
||
public array $chatMaps = [ | ||
'content' => 'message' | ||
]; | ||
|
||
|
||
function __construct() | ||
{ | ||
$apiToken = getenv("SIDEKICK_COHERE_TOKEN"); | ||
|
||
$this->headers = [ | ||
"Authorization" => "Bearer {$apiToken}", | ||
"Content-Type" => "application/json", | ||
"Accept" => "application/json", | ||
]; | ||
} | ||
|
||
/** | ||
* @return Completion | ||
*/ | ||
public function complete(): Completion | ||
{ | ||
return new Completion( | ||
url: "{$this->baseUrl}/chat", | ||
headers: $this->headers, | ||
requestRules: [ | ||
'chat_history' => '$allMessages ? $allMessages : null', | ||
'message' => '$message' | ||
], | ||
responseFormat: [] | ||
); | ||
} | ||
|
||
/** | ||
* @param $response | ||
* @return mixed | ||
*/ | ||
public function getResponse($response) | ||
{ | ||
return $response['text']; | ||
} | ||
|
||
/** | ||
* @param $response | ||
* @return array | ||
*/ | ||
public function getErrorMessage($response) | ||
{ | ||
return [ | ||
'driver' => 'Cohere', | ||
'error' => [ | ||
'type' => 'error', | ||
'code' => null, | ||
'message' => $response['message'] | ||
] | ||
]; | ||
} | ||
|
||
/** | ||
* @param $response | ||
* @return bool | ||
*/ | ||
public function validate($response): bool | ||
{ | ||
return !(isset($response['message'])); | ||
} | ||
} |
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
Oops, something went wrong.