Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
7a7b11b
Response.php and README.md file
charvimehradu Jun 7, 2025
f358113
Add AI provider interface and abstract provider files
charvimehradu Jun 9, 2025
ba8c0fd
Enhance abstract provider http factory handling
charvimehradu Jun 10, 2025
50ca86a
Add OpenAIProvider functionality and basic tests
charvimehradu Jun 11, 2025
d9d9140
Add OpenAIProvider chatwithVision method and Refactor existing structure
charvimehradu Jun 17, 2025
9324369
Add OpenAIProvider chatwithVision test
charvimehradu Jun 17, 2025
712bd33
Add model management capabilities
charvimehradu Jun 17, 2025
940f774
Add authentication for getting available models and test it
charvimehradu Jun 17, 2025
e9f8bab
Add image generation capability
charvimehradu Jun 18, 2025
7a4dd10
Add image generation capability-2
charvimehradu Jun 18, 2025
3dd5c7c
Response API works for browser settings only
charvimehradu Jun 18, 2025
c08b033
Add image generation capability and test for it
charvimehradu Jun 18, 2025
8ff42bb
Add image editing capabilities and test for it - 1
charvimehradu Jun 19, 2025
f6c08fe
Add the capability to create image variations and test for it
charvimehradu Jun 24, 2025
ca861fd
Add the capability to edit images
charvimehradu Jun 25, 2025
72820d5
Code cleanup and add the text to speech capability
charvimehradu Jun 26, 2025
c6dacd6
Add transcribe capability and test
charvimehradu Jun 28, 2025
222f228
Add translation capability and test
charvimehradu Jun 30, 2025
4ad02b9
Add embeddings creation capability
charvimehradu Jun 30, 2025
235c9c8
Add embeddings test and gpt-image-1 test
charvimehradu Jul 1, 2025
82f57c6
Add provision for custom openai servers
charvimehradu Jul 1, 2025
b4fc7df
Debug multi image capability for gpt-image-1 model
charvimehradu Jul 2, 2025
4837f78
Add Moderation capability and test/Restructure Test files
charvimehradu Jul 7, 2025
4c2aac6
Correct format
charvimehradu Jul 7, 2025
b378d47
Clean up code and refactor transcription and translation response par…
charvimehradu Jul 8, 2025
014e15b
Validate Image Inputs
charvimehradu Jul 8, 2025
14584cb
Validate Audio and Embeddings Inputs
charvimehradu Jul 9, 2025
448bd5e
Validate Chat Inputs
charvimehradu Jul 9, 2025
961fd62
Test chat input validation ad audio capability
charvimehradu Jul 10, 2025
faa6e9f
Add AIException class
charvimehradu Jul 12, 2025
f26ba30
Add InvalidArgumentException class and its implementation with OpenAI…
charvimehradu Jul 14, 2025
59eb85c
Resolve image generation test (default response_format=url)
charvimehradu Jul 14, 2025
72fcff4
Add AuthenticationException class and its implementation with OpenAI …
charvimehradu Jul 15, 2025
14c2274
Add RateLimit and QuotaExceeded tests
charvimehradu Jul 15, 2025
58d11ef
Add UnserializableResponse Exception and refactor other exceptions
charvimehradu Jul 16, 2025
2589a34
Add Provider Exception
charvimehradu Jul 16, 2025
dbb226b
Improve exception classes and keep defaults seet
charvimehradu Jul 17, 2025
7ff2d77
Resolve response_format errors with image payloads
charvimehradu Jul 21, 2025
82ee37b
Update composer to use http framework version 4.x
charvimehradu Jul 21, 2025
29fb7a0
Update composer to use filesystem framework and implement it
charvimehradu Jul 21, 2025
038c60b
Implement Anthropic provider
charvimehradu Jul 21, 2025
6db0bdf
To do in new branch
charvimehradu Jul 21, 2025
a3baa80
Add Ollama Provider implementation- Pull Model
charvimehradu Jul 22, 2025
6ab6efd
Work in progress-generate
charvimehradu Jul 23, 2025
0b980a6
Implement chat endpoint for Ollama for both streaming and non streami…
charvimehradu Jul 24, 2025
b771db9
Implement generate endpoint for Ollama for both streaming and non str…
charvimehradu Jul 28, 2025
b1aff87
Add the ability to set/unset the default model of a provider
charvimehradu Jul 29, 2025
a1e1cdc
Add tests fir Ollama Generate endpoint
charvimehradu Jul 29, 2025
cf1bb3f
Refactor code and add delete/copy/setDefault/unsetDefault model option
charvimehradu Jul 30, 2025
f03c17e
Implement messages endpoint for Anthropic
charvimehradu Jul 31, 2025
f287b9b
Add vision capability for Anthropic
charvimehradu Aug 4, 2025
726981e
Add model management capabilities
charvimehradu Aug 6, 2025
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
Empty file added README.md
Empty file.
43 changes: 43 additions & 0 deletions Tests/AnthropicChat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

require_once '../vendor/autoload.php';

use Joomla\AI\Provider\AnthropicProvider;

echo "Testing Real Anthropic API Calls...\n\n";

$configFile = __DIR__ . '/../config.json';
$config = json_decode(file_get_contents($configFile), true);
$api_key = $config['anthropic_api_key'] ?? null;

try {
// Create provider with your API key
$provider = new AnthropicProvider([
'api_key' => $api_key
]);

echo "Provider created with API key\n";
echo "Provider name: " . $provider->getName() . "\n\n";

// Test 1: Simple prompt
echo "Test 1: Simple prompt\n";
echo str_repeat('-', 50) . "\n";

$response = $provider->chat("Translate the following sentence into French: Joomla makes website building easy and fun.", ['model' => 'claude-3-haiku-20240307']);

echo "API call successful!\n";
echo "Response: " . $response->getContent() . "\n";
echo "Provider: " . $response->getProvider() . "\n";
echo "Status: " . $response->getStatusCode() . "\n";

$metadata = $response->getMetadata();
echo "Model used: " . ($metadata['model']) . "\n";
echo "Input Tokens used: " . ($metadata['input_tokens']) . "\n";
echo "Output Tokens used: " . ($metadata['output_tokens']) . "\n";
echo "\n";

echo "\n" . str_repeat('=', 60) . "\n";
echo "All Messages endpoint tests completed successfully!\n";
} catch (Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
}
134 changes: 134 additions & 0 deletions Tests/AnthropicModelManagement.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?php

require_once '../vendor/autoload.php';

use Joomla\AI\Provider\AnthropicProvider;

echo "=== Anthropic Provider Comprehensive Test ===\n\n";

$configFile = __DIR__ . '/../config.json';
$config = json_decode(file_get_contents($configFile), true);
$api_key = $config['anthropic_api_key'] ?? null;

try {
// Create provider
$provider = new AnthropicProvider([
'api_key' => $api_key
]);

echo "Provider: " . $provider->getName() . "\n";
echo "Provider created successfully!\n\n";

// Test 1: Get all available models
echo "=== Test 1: Get Available Models ===\n";

$availableModels = $provider->getAvailableModels();
echo "Available Models: " . implode(', ', $availableModels) . "\n";
echo "Total: " . count($availableModels) . " models\n";

echo "\n" . str_repeat("=", 60) . "\n\n";

// Test 2: Test with a known model ID (if different from available models)
echo "=== Test 2: Get Known Model (claude-3-haiku-20240307) ===\n";

try {
$validModelResponse = $provider->getModel('claude-3-haiku-20240307');

echo "Model Information:\n";
echo $validModelResponse->getContent() . "\n";

} catch (Exception $e) {
echo "Error getting known model: " . $e->getMessage() . "\n";
}

echo "\n" . str_repeat("=", 60) . "\n\n";

// Test 3: Test with invalid model ID (error handling)
echo "=== Test 3: Error Handling - Invalid Model ID ===\n";

try {
$invalidModelResponse = $provider->getModel('invalid-model-12345');
echo "Unexpected success with invalid model\n";
} catch (Exception $e) {
echo "Expected error caught: " . $e->getMessage() . "\n";
}

echo "\n" . str_repeat("=", 60) . "\n\n";

// Test 4: Basic Chat with saveFile
echo "=== Test 4: Basic Chat with saveFile ===\n";
echo str_repeat("-", 50) . "\n";

$chatResponse = $provider->chat(
"Hi",
[
'model' => 'claude-3-haiku-20240307',
'max_tokens' => 150
]
);

echo "Chat Response:\n";
echo $chatResponse->getContent() . "\n";
echo "Status: " . $chatResponse->getStatusCode() . "\n";
echo "Provider: " . $chatResponse->getProvider() . "\n";

$metadata = $chatResponse->getMetadata();
echo "Model: " . $metadata['model'] . "\n";
echo "Input Tokens: " . $metadata['input_tokens'] . "\n";
echo "Output Tokens: " . $metadata['output_tokens'] . "\n";
echo "Stop Reason: " . $metadata['stop_reason'] . "\n";

echo "\n" . str_repeat("=", 60) . "\n\n";

// Test 5: Vision Analysis
echo "=== Test 5: Vision Analysis ===\n";
echo str_repeat("-", 50) . "\n";

$testImage = "test_files/fish.png";
$visionResponse = $provider->vision(
"What do you see in this image? Describe in one line.",
$testImage,
);

echo "Vision Response:\n";
echo $visionResponse->getContent() . "\n";
echo "Status: " . $visionResponse->getStatusCode() . "\n";

$visionMetadata = $visionResponse->getMetadata();
echo "Model: " . $visionMetadata['model'] . "\n";
echo "Input Tokens: " . $visionMetadata['input_tokens'] . "\n";
echo "Output Tokens: " . $visionMetadata['output_tokens'] . "\n";

echo "\n" . str_repeat("=", 60) . "\n\n";

// Test 6: Advanced Chat with Options
echo "=== Test 6: Advanced Chat with Options ===\n";
echo str_repeat("-", 50) . "\n";

$advancedResponse = $provider->chat(
"What is the full form of AI?",
[
'model' => 'claude-3-haiku-20240307',
'max_tokens' => 200,
'temperature' => 0.7,
'top_p' => 0.9,
'stop_sequences' => ['\n\n\n']
]
);

echo "Advanced Chat Response:\n";
echo $advancedResponse->getContent() . "\n";

$advancedMetadata = $advancedResponse->getMetadata();
echo "Model: " . $advancedMetadata['model'] . "\n";
echo "Input Tokens: " . $advancedMetadata['input_tokens'] . "\n";
echo "Output Tokens: " . $advancedMetadata['output_tokens'] . "\n";
echo "Stop Reason: " . $advancedMetadata['stop_reason'] . "\n";

echo "\n" . str_repeat("=", 60) . "\n\n";

echo "\nAll Anthropic tests completed successfully!\n";

} catch (Exception $e) {
echo "Test failed with error: " . $e->getMessage() . "\n";
}
52 changes: 52 additions & 0 deletions Tests/AnthropicVision.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

require_once '../vendor/autoload.php';

use Joomla\AI\Provider\AnthropicProvider;

echo "Testing Anthropic Vision API Calls...\n\n";

$configFile = __DIR__ . '/../config.json';
$config = json_decode(file_get_contents($configFile), true);
$api_key = $config['anthropic_api_key'] ?? null;

try {
// Create provider with your API key
$provider = new AnthropicProvider([
'api_key' => $api_key
]);

echo "Provider created with API key\n";
echo "Provider name: " . $provider->getName() . "\n\n";

// Test vision capability
echo "Test: Vision with image description\n";
echo str_repeat('-', 50) . "\n";

// You can use a base64 image or URL
$imageUrl = "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg";

$response = $provider->vision(
"What do you see in this image? Describe it in detail.",
$imageUrl,
[
'model' => 'claude-3-5-sonnet-20241022',
]
);

echo "Vision API call successful!\n";
echo "Response: " . $response->getContent() . "\n";
echo "Provider: " . $response->getProvider() . "\n";
echo "Status: " . $response->getStatusCode() . "\n";

$metadata = $response->getMetadata();
echo "Model used: " . ($metadata['model']) . "\n";
echo "Input Tokens used: " . ($metadata['input_tokens']) . "\n";
echo "Stop reason: " . ($metadata['stop_reason']) . "\n";
echo "\n";

echo "\n" . str_repeat('=', 60) . "\n";
echo "Anthropic Vision tests completed successfully!\n";
} catch (Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
}
105 changes: 105 additions & 0 deletions Tests/ChatCompletionsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

require_once '../vendor/autoload.php';

use Joomla\AI\Provider\OpenAIProvider;

echo "Testing Real OpenAI API Calls...\n\n";

$configFile = __DIR__ . '/../config.json';
$config = json_decode(file_get_contents($configFile), true);
$api_key = $config['openai_api_key'] ?? null;

try {
// Create provider with your API key
$provider = new OpenAIProvider([
'api_key' => $api_key
]);

echo "Provider created with API key\n";
echo "Provider name: " . $provider->getName() . "\n\n";

// To Do: Check if the provider is supported. Currently key set as env variables only
// if (!OpenAIProvider::isSupported()) {
// throw new \Exception('OpenAI API is not supported or API key is missing.');
// }

// Test 1: Simple prompt
echo "Test 1: Simple prompt\n";
echo str_repeat('-', 50) . "\n";

$response = $provider->chat("Hello! How are you?");

echo "API call successful!\n";
echo "Response: " . $response->getContent() . "\n";
echo "Provider: " . $response->getProvider() . "\n";
echo "Status: " . $response->getStatusCode() . "\n";

$metadata = $response->getMetadata();
if (!empty($metadata)) {
echo "Model used: " . ($metadata['model']) . "\n";
if (isset($metadata['usage'])) {
echo "Tokens used: " . ($metadata['usage']['total_tokens']) . "\n";
}
}
echo "\n";

// Test 2: Multiple Response Choices (n parameter)
echo "Test 2: Multiple Response Choices (n parameter)\n";
echo str_repeat('-', 50) . "\n";
$response = $provider->chat("Suggest a name for a movie based on pilots and astronauts", [
'n' => 3,
]);
echo "Model: " . $response->getMetadata()['model'] . "\n";
echo "Response: " . $response->getContent() . "\n";

$metadata = $response->getMetadata();
if (isset($metadata['choices']) && is_array($metadata['choices'])) {
echo "Number of choices returned: " . count($metadata['choices']) . "\n";
for ($i = 0; $i < count($metadata['choices']); $i++) {
echo "Choice " . ($i + 1) . ": " . ($metadata['choices'][$i]['message']['content'] ?? 'No content') . "\n";
}
} else {
echo "Expected multiple choices but got single response. Check OpenAI provider implementation.\n";
}
echo "\n";

// Test 3:Test chat completions audio capability
echo "Test 3: Test chat completions audio capability\n";
echo str_repeat('-', 50) . "\n";
$response = $provider->chat("Say a few words on Joomla! for about 30 seconds in english.", [
'model' => 'gpt-4o-audio-preview',
'modalities' => ['text', 'audio'],
'audio' => [
'voice' => 'alloy',
'format' => 'wav'
],
]);

$metadata = $response->getMetadata();
$debugFile = "output/full_audio_response_structure.json";
$fullStructure = [
'response_class' => get_class($response),
'content' => $response->getContent(),
'status_code' => $response->getStatusCode(),
'provider' => $response->getProvider(),
'metadata' => $metadata
];
file_put_contents($debugFile, json_encode($fullStructure, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
echo "Full response structure saved to: $debugFile\n";

if (isset($metadata['choices'][0]['message']['audio']['data'])) {
$audioData = $metadata['choices'][0]['message']['audio']['data'];
$audioDatab64 = base64_decode($audioData, true);
$audioFile = file_put_contents("output/chat_completions_audio.wav", $audioDatab64);
echo "Audio file found and saved to: \"output/chat_completions_audio.wav\".\n";
} else {
echo "Audio file not found.\n";
}
echo "\n";

echo "\n" . str_repeat('=', 60) . "\n";
echo "All Chat Completions API tests completed successfully!\n";
} catch (Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
}
Loading