Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions docs/.vitepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export default defineConfig({
text: 'Introduction',
items: [
{ text: 'What is Converse?', link: '/guide/what-is-converse' },
{ text: 'Getting Started', link: '/guide/getting-started' },
{ text: 'Installation', link: '/guide/installation' }
{ text: 'Installation', link: '/guide/installation' },
{ text: 'Setup', link: '/guide/getting-started' }
]
},
{
Expand Down
104 changes: 71 additions & 33 deletions docs/guide/getting-started.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
# Getting Started
# Setup

This guide will help you get up and running with Converse quickly. For detailed installation instructions, see the [Installation Guide](/guide/installation).
Get up and running with your first AI conversation in minutes.

## Quick Start
## Prerequisites

### 1. Install the Package
Make sure you've completed the [installation](/guide/installation):
- Package installed via Composer
- Migrations run
- (Optional) Configuration published

```bash
composer require elliottlawson/converse
```

### 2. Run Migrations

```bash
php artisan migrate
```
## Your First Conversation

That's it! You're ready to start using Converse.

## Basic Setup

### 1. Add the Trait to Your Model
### 1. Add the Trait

Add the `HasAIConversations` trait to any model that should have conversations:

Expand All @@ -38,7 +29,7 @@ class User extends Model
}
```

### 2. Create Your First Conversation
### 2. Start a Conversation

```php
$user = User::find(1);
Expand All @@ -52,34 +43,81 @@ $conversation = $user->startConversation([
### 3. Add Messages

```php
// Add a system message to set the context
// Set the AI's behavior
$conversation->addSystemMessage('You are a helpful assistant.');

// Add a user message
// Add a user question
$conversation->addUserMessage('What is Laravel?');

// Add an assistant response
// Add the AI's response
$conversation->addAssistantMessage(
'Laravel is a PHP web application framework with expressive, elegant syntax...'
'Laravel is a PHP web application framework with expressive, elegant syntax.
It provides tools for routing, sessions, caching, and more.'
);
```

## Fluent API
## The Fluent API

Converse provides a fluent API for building conversations:
Chain methods for a more natural flow:

```php
$conversation = $user->startConversation(['title' => 'Laravel Help'])
->addSystemMessage('You are a Laravel expert.')
->addUserMessage('How do I create a middleware?')
->addAssistantMessage('To create a middleware in Laravel, you can use the artisan command...')
->addUserMessage('Can you show me an example?')
->addAssistantMessage("Here's a simple example of a Laravel middleware...");
->addAssistantMessage('To create middleware: `php artisan make:middleware MyMiddleware`')
->addUserMessage('Where does it go?')
->addAssistantMessage('Middleware files are stored in `app/Http/Middleware/`');
```

## Continuing Conversations

Resume any conversation later:

```php
// Find an existing conversation
$conversation = $user->conversations()->find($conversationId);

// Or use the helper method
$conversation = $user->continueConversation($conversationId);

// Add more messages
$conversation->addUserMessage('Thanks! How do I register it?');
```

## Next Steps
## Integrating with AI Providers

Here's a real example using OpenAI:

```php
use OpenAI\Laravel\Facades\OpenAI;

// Get user input
$userMessage = $request->input('message');

// Add to conversation
$conversation->addUserMessage($userMessage);

// Prepare context for AI
$messages = $conversation->messages->map(fn($msg) => [
'role' => $msg->role->value,
'content' => $msg->content
])->toArray();

// Get AI response
$response = OpenAI::chat()->create([
'model' => 'gpt-4',
'messages' => $messages,
]);

// Store the response
$conversation->addAssistantMessage($response->choices[0]->message->content);
```

## What's Next?

Now that you've created your first conversation, explore:

- Learn about [different message types](/guide/messages)
- Explore [streaming responses](/guide/streaming)
- Set up [real-time updates](/guide/events) with Laravel Broadcasting
- Discover [advanced features](/guide/conditional-logic) like conditional logic
- [Message Types](/guide/messages) - Learn about all message types and when to use them
- [Conversations](/guide/conversations) - Deep dive into conversation management
- [Streaming](/guide/streaming) - Handle real-time streaming responses
- [Events](/guide/events) - React to conversation changes
161 changes: 74 additions & 87 deletions docs/guide/installation.md
Original file line number Diff line number Diff line change
@@ -1,88 +1,44 @@
# Installation

This guide covers the installation and configuration of Converse in detail.
This guide covers installing and configuring Converse in your Laravel application.

## Requirements

- PHP 8.2 or higher
- Laravel 11.0 or 12.0
- Laravel 11.0 or higher
- A database supported by Laravel (MySQL, PostgreSQL, SQLite, SQL Server)

## Installation via Composer
## Installation

Install the package using Composer:
Install the package via Composer:

```bash
composer require elliottlawson/converse
```

## Service Provider

Laravel will automatically discover the `ConverseServiceProvider`. This provider:
- Registers the configuration
- Loads migrations
- Sets up event listeners

## Basic Setup (Zero Configuration)

For most applications, you can start using Converse immediately after installation:
Run the migrations:

```bash
# Run migrations
php artisan migrate
```

That's it! The package will use sensible defaults and you can start creating conversations.
That's it! Converse is now installed with sensible defaults.

## Advanced Configuration
## Configuration (Optional)

### Publishing the Config File

If you need to customize settings, publish the configuration file:
If you need to customize settings, you can publish the config:

```bash
php artisan vendor:publish --tag=converse-config
```

This creates `config/converse.php` with the following options:
This creates `config/converse.php` where you can customize:

```php
return [
// Customize table names
'tables' => [
'conversations' => 'ai_conversations',
'messages' => 'ai_messages',
'message_chunks' => 'ai_message_chunks',
'message_attachments' => 'ai_message_attachments',
],

// Override model classes
'models' => [
'conversation' => \ElliottLawson\Converse\Models\Conversation::class,
'message' => \ElliottLawson\Converse\Models\Message::class,
// ... other models
],

// Attachment storage
'attachments' => [
'disk' => env('CONVERSE_DISK', 'local'),
'path' => env('CONVERSE_PATH', 'conversations'),
],

// Auto-cleanup settings
'prune_after_days' => env('CONVERSE_PRUNE_DAYS', null),

// Broadcasting settings
'broadcasting' => [
'enabled' => env('CONVERSE_BROADCASTING_ENABLED', true),
'queue' => env('CONVERSE_BROADCAST_QUEUE', null),
],
];
```

### Customizing Table Names
### Table Names

To use custom table names, update the config **before** running migrations:
If you need custom table names, update the config **before** running migrations:

```php
// config/converse.php
Expand All @@ -94,17 +50,42 @@ To use custom table names, update the config **before** running migrations:
],
```

### Publishing Migrations
### Model Classes

If you need to modify the database schema, publish the migrations:
Override the default models if needed:

```bash
php artisan vendor:publish --tag=converse-migrations
```php
'models' => [
'conversation' => \App\Models\CustomConversation::class,
'message' => \App\Models\CustomMessage::class,
],
```

### Storage Settings

Configure where attachments are stored:

```php
'attachments' => [
'disk' => env('CONVERSE_DISK', 'local'),
'path' => env('CONVERSE_PATH', 'conversations'),
],
```

### Broadcasting

Configure real-time broadcasting:

```php
'broadcasting' => [
'enabled' => env('CONVERSE_BROADCASTING_ENABLED', true),
'queue' => env('CONVERSE_BROADCAST_QUEUE', null),
],
```

## Environment Variables

Configure the package using environment variables:
Available environment variables:

```bash
# Attachment storage
Expand All @@ -119,49 +100,55 @@ CONVERSE_BROADCASTING_ENABLED=true
CONVERSE_BROADCAST_QUEUE=broadcasting
```

## Verifying Installation
## Publishing Migrations (Advanced)

After installation, verify everything is working:
If you need to modify the database schema:

```php
use ElliottLawson\Converse\Models\Conversation;
```bash
php artisan vendor:publish --tag=converse-migrations
```

// Create a test conversation
$conversation = Conversation::create([
'title' => 'Test Conversation'
]);
Then edit the migrations in `database/migrations/` before running them.

$conversation->addUserMessage('Hello!')
->addAssistantMessage('Hi there!');
## Service Provider

// Check if messages were created
dd($conversation->messages->toArray());
```
Laravel automatically discovers the `ConverseServiceProvider`. It handles:
- Configuration registration
- Migration loading
- Event listener setup

No manual registration is needed.

## Troubleshooting

### Migration Errors

If you encounter migration errors:
- **Table already exists**: You may have conflicting table names. Use custom table names in the config.
- **JSON column errors**: Ensure your database version supports JSON columns.
- **Foreign key errors**: Check that referenced tables exist.

### Configuration Issues

1. Check for table name conflicts
2. Ensure your database supports JSON columns
3. Verify foreign key constraints
```bash
# Clear config cache
php artisan config:clear

### Configuration Not Loading
# Clear all caches
php artisan optimize:clear
```

1. Clear config cache: `php artisan config:clear`
2. Check if service provider is registered
3. Verify config file syntax
### Class Not Found

### Class Not Found Errors
```bash
# Regenerate autoload files
composer dump-autoload

1. Run `composer dump-autoload`
2. Clear Laravel caches: `php artisan cache:clear`
3. Check namespace imports
# Clear compiled classes
php artisan clear-compiled
```

## Next Steps

- Continue to [Getting Started](/guide/getting-started) for basic usage
- Learn about [Conversations](/guide/conversations)
- Continue to [Setup](/guide/getting-started) to create your first conversation
- Learn about the [Conversation Model](/guide/conversations)
- Explore [Message Types](/guide/messages)
2 changes: 1 addition & 1 deletion docs/guide/what-is-converse.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,4 @@ All models support:

## Next Steps

Ready to get started? Continue to the [Getting Started](/guide/getting-started) guide to install Converse and create your first AI-powered conversation!
Ready to get started? Check out [Installation](/guide/installation) to install Converse, then continue to [Setup](/guide/getting-started) to create your first AI-powered conversation!
Loading