Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/code-ql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
- name: Run CodeQL
run: |
docker run --rm -v $PWD:/app composer:2.6 sh -c \
"composer install --profile --ignore-platform-reqs && composer check"
"composer install --profile --ignore-platform-reqs && composer check"
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
"utopia-php/fetch": "0.5.*"
},
"require-dev": {
"laravel/pint": "^1.18",
"phpstan/phpstan": "^2.0",
"phpunit/phpunit": "^9.3",
Comment thread
ChiragAgg5k marked this conversation as resolved.
Outdated
"vimeo/psalm": "4.0.1",
"laravel/pint": "1.2.*",
"phpstan/phpstan": "1.9.x-dev"
"vimeo/psalm": "4.0.1"
Comment thread
ChiragAgg5k marked this conversation as resolved.
Outdated
}
}
57 changes: 25 additions & 32 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: max
paths:
- src
- tests
5 changes: 5 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"php_unit_method_casing": false
}
}
61 changes: 2 additions & 59 deletions src/Agents/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,58 +6,44 @@ abstract class Adapter
{
/**
* The agent instance
*
* @var ?Agent
*/
protected ?Agent $agent = null;

/**
* Input tokens count
*
* @var int
*/
protected int $inputTokens = 0;

/**
* Output tokens count
*
* @var int
*/
protected int $outputTokens = 0;

/**
* Cache creation input tokens count
*
* @var int
*/
protected int $cacheCreationInputTokens = 0;

/**
* Cache read input tokens count
*
* @var int
*/
protected int $cacheReadInputTokens = 0;

/**
* Request timeout in milliseconds
*
* @var int
*/
protected int $timeout = 90000;

/**
* Get the adapter name
*
* @return string
*/
abstract public function getName(): string;

/**
* Send a message to the AI model
*
* @param array<Message> $messages The messages to send to the AI model
* @param callable|null $listener The listener to call when the message is sent
* @param array<Message> $messages The messages to send to the AI model
* @param callable|null $listener The listener to call when the message is sent
* @return Message Response from the AI model
*
* @throws \Exception
Expand All @@ -73,37 +59,27 @@ abstract public function getModels(): array;

/**
* Get the currently selected model
*
* @return string
*/
abstract public function getModel(): string;

/**
* Set the model to use
*
* @param string $model
* @return self
*/
abstract public function setModel(string $model): self;

/**
* Check if the model supports JSON schema
*
* @return bool
*/
abstract public function isSchemaSupported(): bool;

/**
* Does this adapter support embeddings?
*
* @return bool
*/
abstract public function getSupportForEmbeddings(): bool;

/**
* Generate embedding for input text (must be implemented if getSupportForEmbeddings is true)
*
* @param string $text
* @return array{
* embedding: array<int, float>,
* tokensProcessed: int|null,
Expand All @@ -122,14 +98,11 @@ abstract public function getEmbeddingDimension(): int;
* Format error message
*
* @param mixed $json
* @return string
*/
abstract protected function formatErrorMessage($json): string;

/**
* Get the current agent
*
* @return ?Agent
*/
public function getAgent(): ?Agent
{
Expand All @@ -138,9 +111,6 @@ public function getAgent(): ?Agent

/**
* Set the agent
*
* @param Agent $agent
* @return self
*/
public function setAgent(Agent $agent): self
{
Expand All @@ -151,8 +121,6 @@ public function setAgent(Agent $agent): self

/**
* Get input tokens count
*
* @return int
*/
public function getInputTokens(): int
{
Expand All @@ -161,8 +129,6 @@ public function getInputTokens(): int

/**
* Get output tokens count
*
* @return int
*/
public function getOutputTokens(): int
{
Expand All @@ -171,8 +137,6 @@ public function getOutputTokens(): int

/**
* Get cache creation input tokens count
*
* @return int
*/
public function getCacheCreationInputTokens(): int
{
Expand All @@ -181,8 +145,6 @@ public function getCacheCreationInputTokens(): int

/**
* Get cache read input tokens count
*
* @return int
*/
public function getCacheReadInputTokens(): int
{
Expand All @@ -191,9 +153,6 @@ public function getCacheReadInputTokens(): int

/**
* Add to input tokens count
*
* @param int $tokens
* @return self
*/
public function countInputTokens(int $tokens): self
{
Expand All @@ -204,9 +163,6 @@ public function countInputTokens(int $tokens): self

/**
* Add to output tokens count
*
* @param int $tokens
* @return self
*/
public function countOutputTokens(int $tokens): self
{
Expand All @@ -217,9 +173,6 @@ public function countOutputTokens(int $tokens): self

/**
* Add to cache creation input tokens count
*
* @param int $tokens
* @return self
*/
public function countCacheCreationInputTokens(int $tokens): self
{
Expand All @@ -230,9 +183,6 @@ public function countCacheCreationInputTokens(int $tokens): self

/**
* Add to cache read input tokens count
*
* @param int $tokens
* @return self
*/
public function countCacheReadInputTokens(int $tokens): self
{
Expand All @@ -243,8 +193,6 @@ public function countCacheReadInputTokens(int $tokens): self

/**
* Get total tokens count
*
* @return int
*/
public function getTotalTokens(): int
{
Expand All @@ -253,9 +201,6 @@ public function getTotalTokens(): int

/**
* Set timeout in milliseconds
*
* @param int $timeout
* @return self
*/
public function setTimeout(int $timeout): self
{
Expand All @@ -266,8 +211,6 @@ public function setTimeout(int $timeout): self

/**
* Get timeout in milliseconds
*
* @return int
*/
public function getTimeout(): int
{
Expand Down
Loading