Skip to content

Commit fe9bfde

Browse files
committed
feat(ai): add DeepSeek AI model
- Add DeepSeek PHP client to dependencies - Implement DeepSeek model in LLMFactory - Create DeepSeek class implementing LLMInterface - Update config file with DeepSeek settings - Modify InstallCommand to include DeepSeek API key setup
1 parent fb1af5a commit fe9bfde

File tree

8 files changed

+221
-75
lines changed

8 files changed

+221
-75
lines changed

.github/workflows/tests.yml

Lines changed: 0 additions & 61 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@
22

33
All notable changes to `laravel-mtn-momo-ai` will be documented in this file.
44

5+
# v1.2.0 - 2025-01-23
6+
7+
## New Features
8+
- Added support for DeepSeek AI model alongside existing ChatGPT, Claude, and Gemini models
9+
- Implemented DeepSeek class with full LLMInterface compatibility
10+
- Updated configuration to include DeepSeek API settings
11+
12+
## Changes
13+
- Modified LLMFactory to create DeepSeek instances
14+
- Enhanced InstallCommand to prompt for DeepSeek API key during setup
15+
16+
## Developer Notes
17+
- Requires DeepSeek PHP client: "deepseek-php/deepseek-php-client": "^1.0"
18+
- Update your .env file with DEEPSEEK_API_KEY for full functionality
19+
20+
521
## v1.1.0 - 2025-01-12
622

723
### Fixed

README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
# Laravel MTN MOMO AI
1+
<h1 align='center'> Laravel MTN MOMO AI </h1>
2+
3+
<div align="center">
24

35
[![Latest Version on Packagist](https://img.shields.io/packagist/v/alvincoded/laravel-mtn-momo-ai.svg?style=flat-square)](https://packagist.org/packages/alvincoded/laravel-mtn-momo-ai)
4-
[![Tests](https://github.com/alvincoded/laravel-mtn-momo-ai/actions/workflows/tests.yml/badge.svg)](https://github.com/alvincoded/laravel-mtn-momo-ai/actions/workflows/tests.yml)
56
[![Code Style](https://github.com/alvincoded/laravel-mtn-momo-ai/actions/workflows/php-cs-fixer.yml/badge.svg)](https://github.com/alvincoded/laravel-mtn-momo-ai/actions/workflows/php-cs-fixer.yml)
67
[![Security](https://github.com/alvincoded/laravel-mtn-momo-ai/actions/workflows/security.yml/badge.svg)](https://github.com/alvincoded/laravel-mtn-momo-ai/actions/workflows/security.yml)
8+
<!-- [![Tests](https://github.com/alvincoded/laravel-mtn-momo-ai/actions/workflows/tests.yml/badge.svg)](https://github.com/alvincoded/laravel-mtn-momo-ai/actions/workflows/tests.yml) -->
79
<!-- [![codecov](https://codecov.io/gh/alvincoded/laravel-mtn-momo-ai/graph/badge.svg?token=D0X6XJZCQR)](https://codecov.io/gh/alvincoded/laravel-mtn-momo-ai) -->
810
<!-- [![Total Downloads](https://img.shields.io/packagist/dt/alvincoded/laravel-mtn-momo-ai.svg?style=flat-square)](https://packagist.org/packages/alvincoded/laravel-mtn-momo-ai) -->
911
<!-- [![Sponsor](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=ff69b4)](https://github.com/sponsors/AlvinCoded) -->
1012

13+
</div>
14+
1115
A powerful Laravel package that integrates [MTN Mobile Money API](https://momodeveloper.mtn.com/) with AI capabilities, providing intelligent transaction analysis, fraud detection, and more!
1216

1317
## Features 🌟
@@ -45,6 +49,7 @@ You'll need at least one of these API keys:
4549
- OpenAI API Key (for ChatGPT)
4650
- Anthropic API Key (for Claude)
4751
- Google Gemini API Key (for Gemini)
52+
- Deepseek API Key (for Deepseek)
4853

4954
### System Requirements
5055
- PHP 8.1 or higher
@@ -80,13 +85,6 @@ This command will guide you through the setup process, including publishing the
8085

8186
The package configuration file will be published to `config/mtn-momo-ai.php`. You can modify the settings there or use environment variables in your `.env` file.
8287

83-
Key configurations include:
84-
85-
- MTN MOMO API credentials
86-
- AI model settings (ChatGPT, Claude, Gemini)
87-
- Default LLM selection
88-
- Alerting settings
89-
9088
### Environment Variables
9189

9290
```bash
@@ -103,6 +101,7 @@ MTN_MOMO_DEFAULT_CURRENCY=EUR
103101
OPENAI_API_KEY=your_openai_key
104102
ANTHROPIC_API_KEY=your_anthropic_key
105103
GEMINI_API_KEY=your_gemini_key
104+
DEEPSEEK_API_KEY=your_deepseek_key
106105

107106
# Default LLM Configuration
108107
DEFAULT_LLM=ChatGPT

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@
2323
}
2424
],
2525
"require": {
26-
"php": "^8.1|^8.2",
26+
"php": ">=8.1",
27+
"deepseek-php/deepseek-php-client": "^1.0",
28+
"google-gemini-php/laravel": "^1.0",
29+
"guzzlehttp/guzzle": "^7.9",
2730
"illuminate/support": "^9.0|^10.0|^11.0",
2831
"laravel/framework": "^9.46.0|^10.34.2|^11.23.5",
29-
"guzzlehttp/guzzle": "^7.9",
3032
"mozex/anthropic-laravel": "^1.1",
31-
"openai-php/client": "^0.10.3",
32-
"google-gemini-php/laravel": "^1.0"
33+
"openai-php/client": "^0.10.3"
3334
},
3435
"require-dev": {
3536
"mockery/mockery": "^1.6",
@@ -39,7 +40,6 @@
3940
"phpstan/phpstan": "^1.10",
4041
"nunomaduro/larastan": "^2.0",
4142
"symfony/var-dumper": "^6.0|^7.0",
42-
"vimeo/psalm": "^5.26",
4343
"rector/rector": "^0.19"
4444
},
4545
"autoload": {

config/mtn-momo-ai.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,15 @@
133133
'model' => env('GEMINI_MODEL', 'gemini-pro'),
134134
],
135135

136+
/**
137+
* DeepSeek Configuration
138+
*/
139+
'deepseek' => [
140+
'api_key' => env('DEEPSEEK_API_KEY'),
141+
'model' => env('DEEPSEEK_MODEL', 'deepseek-chat'),
142+
],
143+
144+
136145
/*
137146
|--------------------------------------------------------------------------
138147
| AI Feature Configuration

src/AI/LLMFactory.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use AlvinCoded\MtnMomoAi\AI\Models\ChatGPT;
66
use AlvinCoded\MtnMomoAi\AI\Models\Claude;
77
use AlvinCoded\MtnMomoAi\AI\Models\Gemini;
8+
use AlvinCoded\MtnMomoAi\AI\Models\DeepSeek;
89
use AlvinCoded\MtnMomoAi\AI\Interfaces\LLMInterface;
910
use InvalidArgumentException;
1011

@@ -63,6 +64,8 @@ public function create(string $model): LLMInterface
6364
return new Claude($this->config['claude']);
6465
case 'Gemini':
6566
return new Gemini($this->config['gemini']);
67+
case 'DeepSeek':
68+
return new DeepSeek($this->config['deepseek']);
6669
default:
6770
throw new InvalidArgumentException("Unsupported LLM model: {$model}");
6871
}

src/AI/Models/DeepSeek.php

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
<?php
2+
3+
namespace AlvinCoded\MtnMomoAi\AI\Models;
4+
5+
use AlvinCoded\MtnMomoAi\AI\Interfaces\LLMInterface;
6+
use DeepseekPhp\Enums\Queries\QueryRoles;
7+
use DeepseekPhp\Enums\Models;
8+
use DeepseekPhp\DeepseekClient;
9+
10+
/**
11+
* DeepSeek AI Model Implementation for MTN MOMO API
12+
*
13+
* This class implements the LLMInterface to provide AI-powered analysis and insights
14+
* for MTN Mobile Money transactions using OpenAI's GPT models.
15+
*/
16+
class DeepSeek implements LLMInterface
17+
{
18+
/** @var \DeepseekPhp\DeepseekClient DeepSeek API client instance */
19+
protected $client;
20+
21+
/** @var array Configuration settings for the Deepseek model */
22+
protected $config;
23+
24+
/**
25+
* Initialize DeepSeek client with configuration
26+
*
27+
* @param array $config Configuration array containing api_key
28+
*/
29+
public function __construct(array $config)
30+
{
31+
$this->client = DeepseekClient::build($config['api_key']);
32+
}
33+
34+
/**
35+
* Analyze transaction data across all MOMO services
36+
*
37+
* @param array $data Transaction data including status, amounts, and patterns
38+
* @return string Analysis results and insights
39+
*/
40+
public function analyze($data)
41+
{
42+
$prompt = "Analyze this MTN MOMO transaction data across collections, disbursements, and remittances. Consider transaction status, amounts, and patterns:\n\n" . json_encode($data);
43+
return $this->generateResponse($prompt);
44+
}
45+
46+
/**
47+
* Detect potential fraud in transaction data
48+
*
49+
* @param array $data Transaction data to evaluate for fraud indicators
50+
* @return string Fraud analysis results and risk assessment
51+
*/
52+
public function detectFraud($data)
53+
{
54+
$prompt = "Evaluate this MTN MOMO transaction for potential fraud indicators. Consider transaction type (collection/disbursement/remittance), amount patterns, and account holder behavior:\n\n" . json_encode($data);
55+
return $this->generateResponse($prompt);
56+
}
57+
58+
/**
59+
* Suggest retry strategy for failed transactions
60+
*
61+
* @param array $data Failed transaction data including error codes and history
62+
* @return string Recommended retry strategy
63+
*/
64+
public function suggestRetryStrategy($data)
65+
{
66+
$prompt = "Based on this failed MTN MOMO transaction data, suggest an optimal retry strategy considering the transaction type, error codes, and historical success patterns:\n\n" . json_encode($data);
67+
return $this->generateResponse($prompt);
68+
}
69+
70+
/**
71+
* Forecast cash flow based on historical data
72+
*
73+
* @param array $data Historical transaction data
74+
* @return string Cash flow forecast and trends analysis
75+
*/
76+
public function forecastCashFlow($data)
77+
{
78+
$prompt = "Analyze this MTN MOMO historical transaction data across collections, disbursements, and remittances to forecast future cash flow patterns and trends:\n\n" . json_encode($data);
79+
return $this->generateResponse($prompt);
80+
}
81+
82+
/**
83+
* Parse natural language commands into API requests
84+
*
85+
* @param string $command Natural language command to parse
86+
* @return array|string Structured API request parameters
87+
*/
88+
public function parseCommand($command)
89+
{
90+
$prompt = "Parse this natural language command into a structured MTN MOMO API request format. Consider valid transaction types (collection/disbursement/remittance) and required parameters:\n\n" . $command;
91+
return $this->generateResponse($prompt);
92+
}
93+
94+
/**
95+
* Generate comprehensive transaction report
96+
*
97+
* @param array $data Transaction data to analyze
98+
* @return string Detailed transaction report
99+
*/
100+
public function generateReport($data)
101+
{
102+
$prompt = "Generate a comprehensive MTN MOMO transaction report analyzing patterns across collections, disbursements, and remittances. Include transaction volumes, success rates, and notable trends:\n\n" . json_encode($data);
103+
return $this->generateResponse($prompt);
104+
}
105+
106+
/**
107+
* Suggest optimal disbursement timing
108+
*
109+
* @param float $amount Amount to disburse
110+
* @param string $recipient Recipient identifier
111+
* @return string Suggested optimal disbursement time
112+
*/
113+
public function suggestDisbursementTime($amount, $recipient)
114+
{
115+
$prompt = "Suggest an optimal disbursement time for this MTN MOMO transfer considering amount: $amount, recipient: $recipient. Consider historical transaction patterns and success rates.";
116+
return $this->generateResponse($prompt);
117+
}
118+
119+
/**
120+
* Detect transaction anomalies
121+
*
122+
* @param array $data Transaction data to analyze for anomalies
123+
* @return array|string Detected anomalies and their details
124+
*/
125+
public function detectAnomalies($data)
126+
{
127+
$prompt = "Analyze this MTN MOMO transaction data to detect anomalies across collections, disbursements, and remittances. Consider unusual patterns, amounts, frequencies, and account behaviors:\n\n" . json_encode($data);
128+
return $this->generateResponse($prompt);
129+
}
130+
131+
/**
132+
* Suggest optimal API call timing
133+
*
134+
* @param array $data API usage data and patterns
135+
* @return string Suggested optimal call times
136+
*/
137+
public function suggestOptimalCallTimes($data)
138+
{
139+
$prompt = "Based on this MTN MOMO API usage data, suggest optimal times for API calls considering success rates, response times, and error patterns:\n\n" . json_encode($data);
140+
return $this->generateResponse($prompt);
141+
}
142+
143+
/**
144+
* Explain API errors with context
145+
*
146+
* @param string $errorCode The error code to explain
147+
* @param array $context Additional context about the error
148+
* @return string Detailed error explanation and resolution steps
149+
*/
150+
public function explainError($errorCode, $context)
151+
{
152+
$prompt = "Explain this MTN MOMO API error in context of the transaction. Provide potential causes and resolution steps:\nError Code: $errorCode\nContext: " . json_encode($context);
153+
return $this->generateResponse($prompt);
154+
}
155+
156+
/**
157+
* Generate AI response using DeepSeek's chat completion
158+
*
159+
* @param string $prompt The prompt to send to the AI model
160+
* @return string Generated response from the AI model
161+
* @throws \Exception If the API request fails
162+
*/
163+
protected function generateResponse($prompt)
164+
{
165+
try {
166+
$response = $this->client
167+
->query('You are an AI assistant specialized in MTN Mobile Money API operations, including collections, disbursements, and remittances. Provide detailed analysis and actionable insights.', QueryRoles::SYSTEM->value)
168+
->query($prompt, QueryRoles::USER->value)
169+
->withModel($this->config['model'])
170+
->setTemperature(0.7)
171+
->run();
172+
173+
return $response;
174+
} catch (\Exception $e) {
175+
throw new \Exception("DeepSeek API request failed: " . $e->getMessage());
176+
}
177+
}
178+
}

src/Console/InstallCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ private function setupEnvironment()
104104
'OPENAI_API_KEY' => $this->secret('🔑 What is your OpenAI API Key? (Leave blank if not using)'),
105105
'ANTHROPIC_API_KEY' => $this->secret('🔑 What is your Anthropic API Key? (Leave blank if not using)'),
106106
'GEMINI_API_KEY' => $this->secret('🔑 What is your Gemini API Key? (Leave blank if not using)'),
107+
'DEEPSEEK_API_KEY' => $this->secret('🔑 What is your DeepSeek API Key? (Leave blank if not using)'),
107108
'MTN_MOMO_ALERT_EMAIL' => $this->ask('📧 What email should receive alerts?'),
108109
'MTN_MOMO_API_USER' => $apiUserId,
109110
];
@@ -259,6 +260,7 @@ private function addPlaceholders()
259260
'OPENAI_API_KEY=' => '# Get this from OpenAI dashboard if using ChatGPT',
260261
'ANTHROPIC_API_KEY=' => '# Get this from Anthropic dashboard if using Claude',
261262
'GEMINI_API_KEY=' => '# Get this from Google Cloud Console if using Gemini',
263+
'DEEPSEEK_API_KEY=' => '# Get this from DeepSeek dashboard if using DeepSeek',
262264
'MTN_MOMO_ALERT_EMAIL=' => '# Optional: Email for receiving alerts',
263265
'MTN_MOMO_API_USER=' => '# Auto-generated during setup. For manual input, see https://momodeveloper.mtn.com/api-documentation/api-description',
264266
'MTN_MOMO_API_KEY=' => '# Auto-generated during setup. For manual input, see https://momodeveloper.mtn.com/api-documentation/api-description'

0 commit comments

Comments
 (0)