Skip to content

Commit

Permalink
Merge pull request #5 from aydinfatih/main
Browse files Browse the repository at this point in the history
Added startChat method to ChatSessionContract
  • Loading branch information
aydinfatih committed Feb 27, 2024
2 parents 1db9396 + 0060511 commit 6e48284
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Contracts/Resources/ChatSessionContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ interface ChatSessionContract
* @param string|Blob|array<string|Blob>|Content ...$parts
*/
public function sendMessage(string|Blob|array|Content ...$parts): GenerateContentResponse;

/**
* @param array<Content> $history
*/
public function startChat(array $history = []): ChatSessionContract;
}
8 changes: 8 additions & 0 deletions src/Resources/ChatSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,12 @@ public function sendMessage(string|Blob|array|Content ...$parts): GenerateConten

return $response;
}

/**
* @param array<Content> $history
*/
public function startChat(array $history = []): ChatSession
{
return new self(model: $this->model, history: $history);
}
}
8 changes: 8 additions & 0 deletions src/Testing/Resources/ChatSessionTestResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,12 @@ public function sendMessage(string|array|Blob|Content ...$parts): GenerateConten
{
return $this->record(method: __FUNCTION__, args: func_get_args(), model: $this->model);
}

/**
* @param array<Content> $history
*/
public function startChat(array $history = []): ChatSessionTestResource
{
return $this->record(method: __FUNCTION__, args: func_get_args(), model: $this->model);
}
}
11 changes: 11 additions & 0 deletions tests/Resources/ChatSession.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Gemini\Enums\Method;
use Gemini\Enums\ModelType;
use Gemini\Resources\ChatSession;
use Gemini\Responses\GenerativeModel\GenerateContentResponse;

Expand All @@ -12,3 +13,13 @@
expect($result)
->toBeInstanceOf(ChatSession::class);
});

test('start chat', function () {
$modelType = ModelType::GEMINI_PRO;
$client = mockClient(method: Method::POST, endpoint: "{$modelType->value}:generateContent", response: GenerateContentResponse::fake(), times: 0);

$result = $client->chat()->startChat();

expect($result)
->toBeInstanceOf(ChatSession::class);
});

0 comments on commit 6e48284

Please sign in to comment.