Skip to content

Commit

Permalink
Added support for multiple OpenAI endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
jiten14 committed Sep 19, 2024
1 parent c0b4068 commit 9a465bf
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 14 deletions.
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ All notable changes to `jitone-ai` will be documented in this file.

## v0.0.1-alpha - 2024-09-08

- Alpha Release for Internal Testing
- Alpha Release for Internal Testing.

## v0.0.8-beta - 2024-09-09

- Release beta version
- Release beta version.

## v0.1.0 - 2024-09-10

- Initial Release
- Initial Release.

## v0.1.1 - 2024-09-19

- Added support for multiple OpenAI endpoints.
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/jiten14/jitone-ai/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/jiten14/jitone-ai/actions?query=workflow%3Arun-tests+branch%3Amain)
[![Total Downloads](https://img.shields.io/packagist/dt/jiten14/jitone-ai.svg?style=flat-square)](https://packagist.org/packages/jiten14/jitone-ai)

## What's New in Jitone AI v0.1.1

1. **Support for Multiple OpenAI Endpoints**:
- The latest OpenAI models, including the `gpt-4` and `gpt-3.5-turbo`, now use the **Chat API endpoint**, improving performance and response flexibility.
- The `gpt-3.5-turbo-instruct` model will continue using the **Completion API endpoint**.

2. **Completion Models Now Considered Legacy**:
- Please note that the models using the Completion endpoint, such as `gpt-3.5-turbo-instruct`, are now considered **legacy models**.
- We highly recommend trying out the latest models for improved results and future-proofing. You can explore them here: [OpenAI Models Documentation](https://platform.openai.com/docs/models).

## Installation

Expand Down Expand Up @@ -170,6 +179,7 @@ AIFileUpload::make('image')
Jitone AI follows semantic versioning:

- **v0.1.0**: Initial release.
- **v0.1.1**: Added support for multiple OpenAI endpoints.

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Expand All @@ -178,9 +188,8 @@ Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed re
Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

## FAQ
- **File upload previews not loading after generating Image.**

**Ans.**- Make sure that the APP_URL variable in your .env file matches the domain you're using to access your app from, including the protocol (http or https).
1. **File upload previews not loading after generating Image.**
- **Ans.**- Make sure that the APP_URL variable in your .env file matches the domain you're using to access your app from, including the protocol (http or https).

## Security Vulnerabilities

Expand Down
2 changes: 1 addition & 1 deletion config/jitone-ai.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

return [
'default_model' => 'gpt-3.5-turbo-instruct',
'default_model' => 'gpt-4o',
'default_max_tokens' => 150,
'default_temperature' => 0.7,
'default_image_size' => '1024x1024',
Expand Down
31 changes: 24 additions & 7 deletions src/Services/OpenAIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,30 @@ public function generateContent(string $prompt, array $options = [])
$maxTokens = $options['max_tokens'] ?? config('jitone-ai.default_max_tokens');
$temperature = $options['temperature'] ?? config('jitone-ai.default_temperature');

$completion = OpenAI::completions()->create([
'model' => $model,
'prompt' => $prompt,
'max_tokens' => $maxTokens,
'temperature' => $temperature,
]);
if ($model === 'gpt-3.5-turbo-instruct') {
$completion = OpenAI::completions()->create([
'model' => $model,
'prompt' => $prompt,
'max_tokens' => $maxTokens,
'temperature' => $temperature,
]);

return $completion['choices'][0]['text'];
return $completion['choices'][0]['text'];
} else {
$result = OpenAI::chat()->create([
'model' => $model,
'messages' => [
[
'role' => 'user',
'content' => $prompt,
],
],
'max_tokens' => $maxTokens,
'temperature' => $temperature,
]);

return $result->choices[0]->message->content;
}
}

}

0 comments on commit 9a465bf

Please sign in to comment.