Repository navigation
Releases: elliotjreed/php-ai
Release list
2.2.0
Adds PromptInterface for easier testing and autowiring in Symfony.
Here's an example of a Symfony integration in the services.yaml file using the interface:
guzzle.client.ai:
class: GuzzleHttp\Client
arguments:
- {
timeout: 10,
headers: {
'User-Agent': 'My Symfony Project'
}
}
ElliotJReed\AI\PromptInterface:
class: ElliotJReed\AI\ChatGPT\Prompt
arguments:
$apiKey: '%env(string:CHATGPT_API_KEY)%'
$model: 'gpt-4o-mini'
$client: '@guzzle.client.ai'By using the PromptInterface you can use it in your application like:
<?php
public function __construct(private \ElliotJReed\AI\Claude\PromptInterface $aiClient)
{
}2.1.2
This patch preserves HTML / XML elements inside XML CDATA for structured prompts.
StructuredPrompt in system / developer prompts. Eg.
$prompt = new ElliotJReed\AI\Claude\Prompt('API KEY', 'claude-3-5-haiku-latest');
$request = (new ElliotJReed\AI\Entity\Request())
->setSystemPrompt('You are responding to customer queries from a web form.')
->setSystemPrompt((new ElliotJReed\AI\Entity\StructuredPrompt())
->setContext('The customer is querying via a form on a e-commerce website based in the United Kingdom.')
->setInstructions('Only text and HTML <br /> tags are permitted. Respond using the data from the FAQs in a friendly and accurate way using British English.')
->setData('FAQs. Q: Do you offer next day deliver. A: Yes we do, however we do not offer same day delivery.')
->setExamples(['Hello! Unfortunately we are not open on Bank Holidays.']))
->setTextPrompt((new ElliotJReed\AI\Entity\StructuredPrompt())
->setContext('The current date and time is: ' . (new DateTime())->format('Y-m-d H:i:s'))
->setUserInput('Can you deliver today at my address?'))
->setMaximumTokens(300);
$response = $prompt->send($request);2.1.1
This patch fixes the underlying XML to string conversion of the StructuredPrompt.
StructuredPrompt in system / developer prompts. Eg.
$prompt = new ElliotJReed\AI\Claude\Prompt('API KEY', 'claude-3-5-haiku-latest');
$request = (new ElliotJReed\AI\Entity\Request())
->setSystemPrompt('You are responding to customer queries from a web form.')
->setSystemPrompt((new ElliotJReed\AI\Entity\StructuredPrompt())
->setContext('The customer is querying via a form on a e-commerce website based in the United Kingdom.')
->setInstructions('Respond using the data from the FAQs in a friendly and accurate way using British English.')
->setData('FAQs. Q: Do you offer next day deliver. A: Yes we do, however we do not offer same day delivery.')
->setExamples(['Hello! Unfortunately we are not open on Bank Holidays.']))
->setTextPrompt((new ElliotJReed\AI\Entity\StructuredPrompt())
->setContext('The current date and time is: ' . (new DateTime())->format('Y-m-d H:i:s'))
->setUserInput('Can you deliver today at my address?'))
->setMaximumTokens(300);
$response = $prompt->send($request);2.1.0
Allows StructuredPrompt in system / developer prompts. Eg.
$prompt = new ElliotJReed\AI\Claude\Prompt('API KEY', 'claude-3-5-haiku-latest');
$request = (new ElliotJReed\AI\Entity\Request())
->setSystemPrompt('You are responding to customer queries from a web form.')
->setSystemPrompt((new ElliotJReed\AI\Entity\StructuredPrompt())
->setContext('The customer is querying via a form on a e-commerce website based in the United Kingdom.')
->setInstructions('Respond using the data from the FAQs in a friendly and accurate way using British English.')
->setData('FAQs. Q: Do you offer next day deliver. A: Yes we do, however we do not offer same day delivery.')
->setExamples(['Hello! Unfortunately we are not open on Bank Holidays.']))
->setTextPrompt((new ElliotJReed\AI\Entity\StructuredPrompt())
->setContext('The current date and time is: ' . (new DateTime())->format('Y-m-d H:i:s'))
->setUserInput('Can you deliver today at my address?'))
->setMaximumTokens(300);
$response = $prompt->send($request);2.0.0
Improves error handling, refactors base prompt class, adds mocked helpers for unit testing.
1.0.0
Initial release with support for Anthropic Claude and OpenAI ChatGPT.
Currently, text prompts are supported via either a plain text input, or via a structured prompt to send the request using XML tags.
Images are supported via base64 encoding the image file, or by providing a URL.