feat: adds ollama support
This commit is contained in:
@@ -20,7 +20,7 @@ Investbrain is a smart open-source investment tracker that helps you manage, tra
|
|||||||
|
|
||||||
## Under the hood
|
## Under the hood
|
||||||
|
|
||||||
Investbrain is a Laravel PHP web application that leverages Livewire and Tailwind for its frontend. Most databases should work, including MySQL and SQLite. Out of the box, we feature three market data providers: [Yahoo Finance](https://finance.yahoo.com/), [Finnhub](https://finnhub.io/pricing-stock-api-market-data), and [Alpha Vantage](https://www.alphavantage.co/support/). But we also offer an extensible market data provider interface for intrepid developers to create their own! We also offer an integration with OpenAI's LLMs for our ["chat with your holdings"](#chat-with-your-holdings) capability. Finally, of course we have robust support for i18n, a11y, and dark mode.
|
Investbrain is a Laravel PHP web application that leverages Livewire and Tailwind for its frontend. Most databases should work, including MySQL and SQLite. Out of the box, we feature three market data providers: [Yahoo Finance](https://finance.yahoo.com/), [Finnhub](https://finnhub.io/pricing-stock-api-market-data), and [Alpha Vantage](https://www.alphavantage.co/support/). But we also offer an extensible market data provider interface for intrepid developers to create their own! We also offer an integration with OpenAI for our ["chat with your holdings"](#chat-with-your-holdings) capability. Finally, of course we have robust support for i18n, a11y, and dark mode.
|
||||||
|
|
||||||
## Self hosting
|
## Self hosting
|
||||||
|
|
||||||
@@ -58,7 +58,9 @@ Investbrain offers an AI powered chat assistant that is grounded on *your* inves
|
|||||||
|
|
||||||
When self-hosting, you can enable the chat assistant by configuring your OpenAI Secret Key and Organization ID in your [.env](https://github.com/investbrainapp/investbrain/blob/main/.env.example) file. Navigate to OpenAI to [create your keys](https://platform.openai.com/api-keys).
|
When self-hosting, you can enable the chat assistant by configuring your OpenAI Secret Key and Organization ID in your [.env](https://github.com/investbrainapp/investbrain/blob/main/.env.example) file. Navigate to OpenAI to [create your keys](https://platform.openai.com/api-keys).
|
||||||
|
|
||||||
Always keep in mind the limitations of large language models. When in doubt, consult a licensed investment advisor.
|
If you are self-hosting your own large language models ("LLMs") that expose an OpenAI compatible API (e.g. [Ollama](https://ollama.com/blog/openai-compatibility)), you can update the `OPENAI_BASE_URI` configuration to your self-hosted instance. Ensure you also update the `OPENAI_MODEL` to an available model.
|
||||||
|
|
||||||
|
Always keep in mind the limitations of LLMs. When in doubt, consult a licensed investment advisor.
|
||||||
|
|
||||||
## Market data providers
|
## Market data providers
|
||||||
|
|
||||||
@@ -133,11 +135,12 @@ There are several optional configurations available when installing using the re
|
|||||||
| AI_CHAT_ENABLED | Whether to enable AI chat features | `false` |
|
| AI_CHAT_ENABLED | Whether to enable AI chat features | `false` |
|
||||||
| OPENAI_API_KEY | OpenAI secret key (required for AI chat) | `null` |
|
| OPENAI_API_KEY | OpenAI secret key (required for AI chat) | `null` |
|
||||||
| OPENAI_ORGANIZATION | OpenAI org id (required for AI chat) | `null` |
|
| OPENAI_ORGANIZATION | OpenAI org id (required for AI chat) | `null` |
|
||||||
|
| OPENAI_MODEL | The selected LLM used for AI chat | gpt-4o |
|
||||||
|
| OPENAI_BASE_URI | The URI for your self-hosted LLM | api.openai.com/v1 |
|
||||||
| DAILY_CHANGE_TIME | The time of day to capture daily change | 23:00 |
|
| DAILY_CHANGE_TIME | The time of day to capture daily change | 23:00 |
|
||||||
| REGISTRATION_ENABLED | Whether to enable registration of new users | `true` |
|
| REGISTRATION_ENABLED | Whether to enable registration of new users | `true` |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
> Note: These options affect the [docker-compose.yml](https://github.com/investbrainapp/investbrain/blob/main/docker-compose.yml) file, so if you decide to make any changes to these default configurations, you'll have to restart the Docker containers before your changes take effect.
|
> Note: These options affect the [docker-compose.yml](https://github.com/investbrainapp/investbrain/blob/main/docker-compose.yml) file, so if you decide to make any changes to these default configurations, you'll have to restart the Docker containers before your changes take effect.
|
||||||
|
|
||||||
## Updating
|
## Updating
|
||||||
|
|||||||
+1
-1
@@ -16,7 +16,7 @@
|
|||||||
"livewire/livewire": "^3.5",
|
"livewire/livewire": "^3.5",
|
||||||
"livewire/volt": "^1.6",
|
"livewire/volt": "^1.6",
|
||||||
"maatwebsite/excel": "^3.1",
|
"maatwebsite/excel": "^3.1",
|
||||||
"openai-php/laravel": "^0.10.2",
|
"openai-php/client": "^0.10.3",
|
||||||
"predis/predis": "^2.2",
|
"predis/predis": "^2.2",
|
||||||
"robsontenorio/mary": "^1.35",
|
"robsontenorio/mary": "^1.35",
|
||||||
"scheb/yahoo-finance-api": "^4.11",
|
"scheb/yahoo-finance-api": "^4.11",
|
||||||
|
|||||||
Generated
+415
-444
File diff suppressed because it is too large
Load Diff
@@ -27,5 +27,6 @@ return [
|
|||||||
'request_timeout' => env('OPENAI_REQUEST_TIMEOUT', 30),
|
'request_timeout' => env('OPENAI_REQUEST_TIMEOUT', 30),
|
||||||
|
|
||||||
//
|
//
|
||||||
|
'base_uri' => env('OPENAI_BASE_URI', 'api.openai.com/v1'),
|
||||||
'model' => env('OPENAI_MODEL', 'gpt-4o'),
|
'model' => env('OPENAI_MODEL', 'gpt-4o'),
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use App\Models\AiChat;
|
|||||||
use App\Models\Holding;
|
use App\Models\Holding;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Livewire\Volt\Component;
|
use Livewire\Volt\Component;
|
||||||
use OpenAI\Laravel\Facades\OpenAI;
|
use OpenAI;
|
||||||
use OpenAI\Responses\StreamResponse;
|
use OpenAI\Responses\StreamResponse;
|
||||||
|
|
||||||
new class extends Component {
|
new class extends Component {
|
||||||
@@ -67,7 +67,9 @@ new class extends Component {
|
|||||||
{
|
{
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$stream = OpenAI::chat()->createStreamed([
|
$client = $this->createOpenAiClient();
|
||||||
|
|
||||||
|
$stream = $client->chat()->createStreamed([
|
||||||
'model' => config('openai.model'),
|
'model' => config('openai.model'),
|
||||||
'messages' => [
|
'messages' => [
|
||||||
['role' => 'system', 'content' => "Today's date is "
|
['role' => 'system', 'content' => "Today's date is "
|
||||||
@@ -104,7 +106,9 @@ new class extends Component {
|
|||||||
public function generateSuggestedPrompts(): void
|
public function generateSuggestedPrompts(): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$suggested_prompts = OpenAI::chat()->create([
|
$client = $this->createOpenAiClient();
|
||||||
|
|
||||||
|
$suggested_prompts = $client->chat()->create([
|
||||||
'model' => config('openai.model'),
|
'model' => config('openai.model'),
|
||||||
'response_format' => [
|
'response_format' => [
|
||||||
'type' => 'json_schema',
|
'type' => 'json_schema',
|
||||||
@@ -192,6 +196,25 @@ new class extends Component {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function createOpenAiClient()
|
||||||
|
{
|
||||||
|
$apiKey = config('openai.api_key');
|
||||||
|
$organization = config('openai.organization');
|
||||||
|
$baseUri = config('openai.base_uri');
|
||||||
|
|
||||||
|
if (! is_string($apiKey) || ($organization !== null && ! is_string($organization))) {
|
||||||
|
throw new \InvalidArgumentException('The OpenAI API Key is missing. Please publish the [openai.php] configuration file and set the [api_key].');
|
||||||
|
}
|
||||||
|
|
||||||
|
return OpenAI::factory()
|
||||||
|
->withApiKey($apiKey)
|
||||||
|
->withOrganization($organization)
|
||||||
|
->withHttpHeader('OpenAI-Beta', 'assistants=v2')
|
||||||
|
->withHttpClient(new \GuzzleHttp\Client(['timeout' => config('openai.request_timeout', 30)]))
|
||||||
|
->withBaseUri($baseUri)
|
||||||
|
->make();
|
||||||
|
}
|
||||||
|
|
||||||
}; ?>
|
}; ?>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
|
|||||||
Reference in New Issue
Block a user