lifedebugger commited on
Commit
cfc49b1
·
1 Parent(s): 3e862f6

Deploy files from GitHub repository

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. controller/prediction_controller.go +1 -2
  2. logs/error_log.txt +7 -0
  3. repositories/account_repository.go +1 -1
  4. repositories/chat_history_repository.go +2 -3
  5. repositories/repository.go +21 -23
  6. router/prediction_route.go +4 -2
  7. services/authentication_service.go +11 -0
  8. services/openai_service.go +5 -1
  9. services/prediction_service.go +5 -7
  10. services/service.go +16 -8
  11. space/repositories/chat_history_repository.go +3 -1
  12. space/repositories/repository.go +7 -8
  13. space/space/Dockerfile +8 -7
  14. space/space/space/factory/prediction_factory.go +4 -5
  15. space/space/space/repositories/chat_history_repository.go +7 -0
  16. space/space/space/services/prediction_service.go +4 -2
  17. space/space/space/space/space/Dockerfile +5 -3
  18. space/space/space/space/space/space/space/Dockerfile +8 -0
  19. space/space/space/space/space/space/space/space/space/Dockerfile +3 -2
  20. space/space/space/space/space/space/space/space/space/space/space/Dockerfile +3 -4
  21. space/space/space/space/space/space/space/space/space/space/space/space/space/.env.example +11 -0
  22. space/space/space/space/space/space/space/space/space/space/space/space/space/.github/workflows/deploy.yml +52 -0
  23. space/space/space/space/space/space/space/space/space/space/space/space/space/.github/workflows/go.yml +28 -0
  24. space/space/space/space/space/space/space/space/space/space/space/space/space/.gitignore +5 -0
  25. space/space/space/space/space/space/space/space/space/space/space/space/space/Dockerfile +40 -0
  26. space/space/space/space/space/space/space/space/space/space/space/space/space/LICENSE +201 -0
  27. space/space/space/space/space/space/space/space/space/space/space/space/space/audio/20250616_235223.mp3 +0 -0
  28. space/space/space/space/space/space/space/space/space/space/space/space/space/config/config.go +27 -0
  29. space/space/space/space/space/space/space/space/space/space/space/space/space/config/database_connection_config.go +61 -0
  30. space/space/space/space/space/space/space/space/space/space/space/space/space/config/openai_client_config.go +11 -0
  31. space/space/space/space/space/space/space/space/space/space/space/space/space/config/replicate_client_config.go +14 -0
  32. space/space/space/space/space/space/space/space/space/space/space/space/space/controller/controller.go +64 -0
  33. space/space/space/space/space/space/space/space/space/space/space/space/space/controller/home_controller.go +9 -0
  34. space/space/space/space/space/space/space/space/space/space/space/space/space/controller/prediction_controller.go +95 -0
  35. space/space/space/space/space/space/space/space/space/space/space/space/space/docker-compose.yaml +0 -0
  36. space/space/space/space/space/space/space/space/space/space/space/space/space/factory/factory.go +1 -0
  37. space/space/space/space/space/space/space/space/space/space/space/space/space/factory/prediction_factory.go +19 -0
  38. space/space/space/space/space/space/space/space/space/space/space/space/space/go.mod +53 -0
  39. space/space/space/space/space/space/space/space/space/space/space/space/space/go.sum +126 -0
  40. space/space/space/space/space/space/space/space/space/space/space/space/space/logs/error_log.txt +19 -0
  41. space/space/space/space/space/space/space/space/space/space/space/space/space/logs/security_log.txt +0 -0
  42. space/space/space/space/space/space/space/space/space/space/space/space/space/main.go +14 -0
  43. space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/authentication_middleware.go +70 -0
  44. space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/middleware.go +30 -0
  45. space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/response_middleware.go +45 -0
  46. space/space/space/space/space/space/space/space/space/space/space/space/space/models/authentication_dto.go +5 -0
  47. space/space/space/space/space/space/space/space/space/space/space/space/space/models/authentication_payload_model.go +7 -0
  48. space/space/space/space/space/space/space/space/space/space/space/space/space/models/entities_model.go +27 -0
  49. space/space/space/space/space/space/space/space/space/space/space/space/space/models/exception_model.go +16 -0
  50. space/space/space/space/space/space/space/space/space/space/space/space/space/models/http_response_dto_model.go +15 -0
controller/prediction_controller.go CHANGED
@@ -80,7 +80,7 @@ func (c *predictionController) Predict(ctx *gin.Context) {
80
  requestImage(ctx, &predictionRequest.ImageFile, &predictionRequest.ImageFileName)
81
  requestAudio(ctx, &predictionRequest.AudioQuestionFile, &predictionRequest.AudioQuestionFilename)
82
 
83
- predictionResult, text_output := c.service.Predict(ctx, predictionRequest)
84
 
85
  if c.service.Error() != nil {
86
  c.Response(ctx, nil)
@@ -91,5 +91,4 @@ func (c *predictionController) Predict(ctx *gin.Context) {
91
  ctx.Header("Content-Disposition", "inline; filename=response.mp3")
92
  ctx.Header("X-Response-Text", text_output)
93
  ctx.Data(200, "audio/mpeg", predictionResult)
94
-
95
  }
 
80
  requestImage(ctx, &predictionRequest.ImageFile, &predictionRequest.ImageFileName)
81
  requestAudio(ctx, &predictionRequest.AudioQuestionFile, &predictionRequest.AudioQuestionFilename)
82
 
83
+ predictionResult, text_output := c.service.Predict(ctx.Request.Context(), predictionRequest)
84
 
85
  if c.service.Error() != nil {
86
  c.Response(ctx, nil)
 
91
  ctx.Header("Content-Disposition", "inline; filename=response.mp3")
92
  ctx.Header("X-Response-Text", text_output)
93
  ctx.Data(200, "audio/mpeg", predictionResult)
 
94
  }
logs/error_log.txt CHANGED
@@ -17,3 +17,10 @@ open audio: is a directory
17
  2025/06/17 00:30:56 Error Log : error, status code: 400, status: 400 Bad Request, message: [{'type': 'string_too_short', 'loc': ('body', 'input'), 'msg': 'String should have at least 1 character', 'input': '', 'ctx': {'min_length': 1}}]
18
  2025/06/17 00:32:14 Error Log : error, status code: 400, status: 400 Bad Request, message: [{'type': 'string_too_short', 'loc': ('body', 'input'), 'msg': 'String should have at least 1 character', 'input': '', 'ctx': {'min_length': 1}}]
19
  2025/06/17 00:33:03 Error Log : error, status code: 400, status: 400 Bad Request, message: [{'type': 'string_too_short', 'loc': ('body', 'input'), 'msg': 'String should have at least 1 character', 'input': '', 'ctx': {'min_length': 1}}]
 
 
 
 
 
 
 
 
17
  2025/06/17 00:30:56 Error Log : error, status code: 400, status: 400 Bad Request, message: [{'type': 'string_too_short', 'loc': ('body', 'input'), 'msg': 'String should have at least 1 character', 'input': '', 'ctx': {'min_length': 1}}]
18
  2025/06/17 00:32:14 Error Log : error, status code: 400, status: 400 Bad Request, message: [{'type': 'string_too_short', 'loc': ('body', 'input'), 'msg': 'String should have at least 1 character', 'input': '', 'ctx': {'min_length': 1}}]
19
  2025/06/17 00:33:03 Error Log : error, status code: 400, status: 400 Bad Request, message: [{'type': 'string_too_short', 'loc': ('body', 'input'), 'msg': 'String should have at least 1 character', 'input': '', 'ctx': {'min_length': 1}}]
20
+ 2025/06/21 20:30:08 Error Log : remove audio\20250616_235223.mp3: The process cannot access the file because it is being used by another process.
21
+ 2025/06/21 21:21:08 Error Log : duplicated key not allowed; invalid transaction
22
+ 2025/06/21 21:23:54 Error Log : duplicated key not allowed; invalid transaction
23
+ duplicated key not allowed; invalid transaction; invalid transaction; invalid transaction
24
+ 2025/06/21 21:27:10 Error Log : duplicated key not allowed; invalid transaction
25
+ 2025/06/21 21:48:34 Error Log : duplicated key not allowed; invalid transaction
26
+ duplicated key not allowed; invalid transaction; invalid transaction; invalid transaction
repositories/account_repository.go CHANGED
@@ -13,7 +13,7 @@ type AccountRepository interface {
13
  }
14
 
15
  type accountRepository struct {
16
- *repository[models.Account]
17
  }
18
 
19
  func (r *accountRepository) CreateAccount(ctx context.Context, fingerPrint string) (res models.Account) {
 
13
  }
14
 
15
  type accountRepository struct {
16
+ repository[models.Account]
17
  }
18
 
19
  func (r *accountRepository) CreateAccount(ctx context.Context, fingerPrint string) (res models.Account) {
repositories/chat_history_repository.go CHANGED
@@ -13,14 +13,13 @@ type ChatHistoryRepository interface {
13
  }
14
 
15
  type chatHistoryRepository struct {
16
- *repository[models.ChatHistory]
17
  }
18
 
19
  func NewChatHistoryRepository() ChatHistoryRepository {
20
  return &chatHistoryRepository{
21
- repository: &repository[models.ChatHistory]{
22
  transaction: config.DB.Begin(),
23
- entity: models.ChatHistory{},
24
  },
25
  }
26
  }
 
13
  }
14
 
15
  type chatHistoryRepository struct {
16
+ repository[models.ChatHistory]
17
  }
18
 
19
  func NewChatHistoryRepository() ChatHistoryRepository {
20
  return &chatHistoryRepository{
21
+ repository: repository[models.ChatHistory]{
22
  transaction: config.DB.Begin(),
 
23
  },
24
  }
25
  }
repositories/repository.go CHANGED
@@ -2,7 +2,6 @@ package repositories
2
 
3
  import (
4
  "context"
5
- "sync"
6
 
7
  "gorm.io/gorm"
8
  )
@@ -32,7 +31,6 @@ type CustomQueryConstructor struct {
32
  }
33
 
34
  type repository[TEntity any] struct {
35
- sync.Mutex
36
  entity TEntity
37
  pagination PaginationConstructor
38
  customQuery CustomQueryConstructor
@@ -49,37 +47,37 @@ func (repo *repository[T1]) RowsCount() int {
49
  return repo.rowsCount
50
  }
51
  func (repo *repository[T1]) IsNoRecord() bool {
52
- repo.Lock()
53
  repo.noRecord = repo.transaction.RowsAffected == 0
54
- repo.Unlock()
55
  return repo.noRecord
56
  }
57
  func (repo *repository[T1]) Transactions(ctx context.Context, act func(ctx context.Context, tx *gorm.DB)) {
58
- repo.Lock()
59
  act(ctx, repo.transaction)
60
- repo.Unlock()
61
  }
62
  func (repo *repository[T1]) Where(ctx context.Context) {
63
  tx := repo.transaction
64
  tx.WithContext(ctx).Where(&repo.entity)
65
- repo.Lock()
66
  repo.rowsCount = int(tx.RowsAffected)
67
  repo.noRecord = repo.rowsCount == 0
68
  repo.rowsError = tx.Error
69
- repo.Unlock()
70
  }
71
  func (repo *repository[T1]) Find(ctx context.Context, res any) {
72
- repo.Lock()
73
  tx := repo.transaction
74
  tx.WithContext(ctx).Find(&res)
75
  if tx.Error != nil {
76
  tx.Rollback()
77
  }
78
- repo.Lock()
79
  repo.rowsCount = int(tx.RowsAffected)
80
  repo.noRecord = repo.rowsCount == 0
81
  repo.rowsError = tx.Error
82
- repo.Unlock()
83
  }
84
 
85
  func (repo *repository[T1]) FindAllPaginate(ctx context.Context, res any) {
@@ -89,25 +87,25 @@ func (repo *repository[T1]) FindAllPaginate(ctx context.Context, res any) {
89
  if tx.Error != nil {
90
  tx.Rollback()
91
  }
92
- repo.Lock()
93
  repo.rowsCount = int(tx.RowsAffected)
94
  repo.noRecord = repo.rowsCount == 0
95
  repo.rowsError = tx.Error
96
- repo.Unlock()
 
 
97
  }
98
 
99
  func (repo *repository[T1]) Create(ctx context.Context) {
100
 
101
- tx := repo.transaction
102
- tx.Create(&repo.entity).Find(&repo.entity)
103
  if tx.Error != nil {
104
  tx.Rollback()
105
  }
106
- repo.Lock()
107
  repo.rowsCount = int(tx.RowsAffected)
108
  repo.noRecord = repo.rowsCount == 0
109
  repo.rowsError = tx.Error
110
- repo.Unlock()
111
  }
112
 
113
  func (repo *repository[T1]) Update(ctx context.Context) {
@@ -117,11 +115,11 @@ func (repo *repository[T1]) Update(ctx context.Context) {
117
  if tx.Error != nil {
118
  tx.Rollback()
119
  }
120
- repo.Lock()
121
  repo.rowsCount = int(tx.RowsAffected)
122
  repo.noRecord = repo.rowsCount == 0
123
  repo.rowsError = tx.Error
124
- repo.Unlock()
125
  }
126
 
127
  func (repo *repository[T1]) Delete(ctx context.Context) {
@@ -131,11 +129,11 @@ func (repo *repository[T1]) Delete(ctx context.Context) {
131
  if tx.Error != nil {
132
  tx.Rollback()
133
  }
134
- repo.Lock()
135
  repo.rowsCount = int(tx.RowsAffected)
136
  repo.noRecord = repo.rowsCount == 0
137
  repo.rowsError = tx.Error
138
- repo.Unlock()
139
  }
140
 
141
  func (repo *repository[T1]) Query(ctx context.Context, res any) {
@@ -145,9 +143,9 @@ func (repo *repository[T1]) Query(ctx context.Context, res any) {
145
  if tx.Error != nil {
146
  tx.Rollback()
147
  }
148
- repo.Lock()
149
  repo.rowsCount = int(tx.RowsAffected)
150
  repo.noRecord = repo.rowsCount == 0
151
  repo.rowsError = tx.Error
152
- repo.Unlock()
153
  }
 
2
 
3
  import (
4
  "context"
 
5
 
6
  "gorm.io/gorm"
7
  )
 
31
  }
32
 
33
  type repository[TEntity any] struct {
 
34
  entity TEntity
35
  pagination PaginationConstructor
36
  customQuery CustomQueryConstructor
 
47
  return repo.rowsCount
48
  }
49
  func (repo *repository[T1]) IsNoRecord() bool {
50
+
51
  repo.noRecord = repo.transaction.RowsAffected == 0
52
+
53
  return repo.noRecord
54
  }
55
  func (repo *repository[T1]) Transactions(ctx context.Context, act func(ctx context.Context, tx *gorm.DB)) {
56
+
57
  act(ctx, repo.transaction)
58
+
59
  }
60
  func (repo *repository[T1]) Where(ctx context.Context) {
61
  tx := repo.transaction
62
  tx.WithContext(ctx).Where(&repo.entity)
63
+
64
  repo.rowsCount = int(tx.RowsAffected)
65
  repo.noRecord = repo.rowsCount == 0
66
  repo.rowsError = tx.Error
67
+
68
  }
69
  func (repo *repository[T1]) Find(ctx context.Context, res any) {
70
+
71
  tx := repo.transaction
72
  tx.WithContext(ctx).Find(&res)
73
  if tx.Error != nil {
74
  tx.Rollback()
75
  }
76
+
77
  repo.rowsCount = int(tx.RowsAffected)
78
  repo.noRecord = repo.rowsCount == 0
79
  repo.rowsError = tx.Error
80
+
81
  }
82
 
83
  func (repo *repository[T1]) FindAllPaginate(ctx context.Context, res any) {
 
87
  if tx.Error != nil {
88
  tx.Rollback()
89
  }
90
+
91
  repo.rowsCount = int(tx.RowsAffected)
92
  repo.noRecord = repo.rowsCount == 0
93
  repo.rowsError = tx.Error
94
+
95
+ return
96
+
97
  }
98
 
99
  func (repo *repository[T1]) Create(ctx context.Context) {
100
 
101
+ tx := repo.transaction.Create(&repo.entity)
 
102
  if tx.Error != nil {
103
  tx.Rollback()
104
  }
 
105
  repo.rowsCount = int(tx.RowsAffected)
106
  repo.noRecord = repo.rowsCount == 0
107
  repo.rowsError = tx.Error
108
+ return
109
  }
110
 
111
  func (repo *repository[T1]) Update(ctx context.Context) {
 
115
  if tx.Error != nil {
116
  tx.Rollback()
117
  }
118
+
119
  repo.rowsCount = int(tx.RowsAffected)
120
  repo.noRecord = repo.rowsCount == 0
121
  repo.rowsError = tx.Error
122
+
123
  }
124
 
125
  func (repo *repository[T1]) Delete(ctx context.Context) {
 
129
  if tx.Error != nil {
130
  tx.Rollback()
131
  }
132
+
133
  repo.rowsCount = int(tx.RowsAffected)
134
  repo.noRecord = repo.rowsCount == 0
135
  repo.rowsError = tx.Error
136
+
137
  }
138
 
139
  func (repo *repository[T1]) Query(ctx context.Context, res any) {
 
143
  if tx.Error != nil {
144
  tx.Rollback()
145
  }
146
+
147
  repo.rowsCount = int(tx.RowsAffected)
148
  repo.noRecord = repo.rowsCount == 0
149
  repo.rowsError = tx.Error
150
+
151
  }
router/prediction_route.go CHANGED
@@ -6,9 +6,11 @@ import (
6
  )
7
 
8
  func PredictionRoute(router *gin.Engine) {
9
- predictionModule := factory.NewPredictionModule()
10
  routerGroup := router.Group("/api/v1")
11
  {
12
- routerGroup.POST("/predict", predictionModule.Predict)
 
 
 
13
  }
14
  }
 
6
  )
7
 
8
  func PredictionRoute(router *gin.Engine) {
 
9
  routerGroup := router.Group("/api/v1")
10
  {
11
+ routerGroup.POST("/predict", func(c *gin.Context) {
12
+ predictionModule := factory.NewPredictionModule()
13
+ predictionModule.Predict(c)
14
+ })
15
  }
16
  }
services/authentication_service.go ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package services
2
+
3
+ import "context"
4
+
5
+ type AuthenticationService interface {
6
+ Register(ctx context.Context, fingerPrint string)
7
+ Login(ctx context.Context, fingerPrint string)
8
+ }
9
+
10
+ type authenticationService interface {
11
+ }
services/openai_service.go CHANGED
@@ -72,8 +72,12 @@ func (s *openAIService) SpeechToText(ctx context.Context, audioFile multipart.Fi
72
  s.ThrowsError(err)
73
  return "Failed to create transcription!"
74
  }
 
 
 
 
 
75
 
76
- // // Privacy Consideration bro!
77
  // if err := os.Remove(savedPath); err != nil {
78
  // s.ThrowsError(err)
79
  // }
 
72
  s.ThrowsError(err)
73
  return "Failed to create transcription!"
74
  }
75
+ // if resp.Text != "" {
76
+ // outFile.Close()
77
+ // } else {
78
+ // s.ThrowsException(&s.exception.FailedTranscripting, "Failed to create transcription! [Nil text]")
79
+ // }
80
 
 
81
  // if err := os.Remove(savedPath); err != nil {
82
  // s.ThrowsError(err)
83
  // }
services/prediction_service.go CHANGED
@@ -51,11 +51,9 @@ func (s *predictionService) Predict(ctx context.Context, req models.PredictionRe
51
  s.ThrowsError(s.openAIService.Error())
52
  return nil, ""
53
  }
54
-
55
- savePrediction := s.repository.SaveChatHistory(ctx, req.ImageFileName, sttOutput, replicateOutput)
56
- if s.ThrowsRepoException() {
57
- return nil, ""
58
- }
59
-
60
- return ttsOutput, savePrediction.Answer
61
  }
 
51
  s.ThrowsError(s.openAIService.Error())
52
  return nil, ""
53
  }
54
+ // savePrediction := s.repository.SaveChatHistory(ctx, req.ImageFileName, sttOutput, replicateOutput)
55
+ // if s.ThrowsRepoException() {
56
+ // return nil, ""
57
+ // }
58
+ return ttsOutput, replicateOutput
 
 
59
  }
services/service.go CHANGED
@@ -2,16 +2,15 @@ package services
2
 
3
  import (
4
  "errors"
5
- "sync"
6
  "time"
7
 
8
  models "github.com/abdanhafidz/ai-visual-multi-modal-backend/models"
9
  repositories "github.com/abdanhafidz/ai-visual-multi-modal-backend/repositories"
 
10
  )
11
 
12
  type (
13
  service[TRepo repositories.Repository] struct {
14
- sync.Mutex
15
  repository TRepo
16
  exception models.Exception
17
  errors error
@@ -26,16 +25,16 @@ type (
26
  )
27
 
28
  func (s *service[TRepo]) ThrowsException(status *bool, message string) {
29
- s.Lock()
30
  *status = true
31
  s.exception.Message = message
32
- s.Unlock()
33
  }
34
 
35
  func (s *service[TRepo]) ThrowsError(err error) {
36
- s.Lock()
37
  s.errors = errors.Join(s.errors, err)
38
- s.Unlock()
39
  }
40
 
41
  func (s *service[TRepo]) Exception() models.Exception {
@@ -49,15 +48,24 @@ func CalculateDueTime(duration time.Duration) time.Time {
49
  }
50
 
51
  func (s *service[TRepo]) ThrowsRepoException() bool {
52
- s.Lock()
53
  if s.repository.RowsError() != nil {
 
 
54
  s.ThrowsError(s.repository.RowsError())
 
 
 
 
 
 
55
  return true
56
  }
57
  if s.repository.IsNoRecord() {
 
58
  s.ThrowsException(&s.exception.DataNotFound, "No record found")
59
  return true
60
  }
61
- s.Unlock()
62
  return false
63
  }
 
2
 
3
  import (
4
  "errors"
 
5
  "time"
6
 
7
  models "github.com/abdanhafidz/ai-visual-multi-modal-backend/models"
8
  repositories "github.com/abdanhafidz/ai-visual-multi-modal-backend/repositories"
9
+ "gorm.io/gorm"
10
  )
11
 
12
  type (
13
  service[TRepo repositories.Repository] struct {
 
14
  repository TRepo
15
  exception models.Exception
16
  errors error
 
25
  )
26
 
27
  func (s *service[TRepo]) ThrowsException(status *bool, message string) {
28
+
29
  *status = true
30
  s.exception.Message = message
31
+
32
  }
33
 
34
  func (s *service[TRepo]) ThrowsError(err error) {
35
+
36
  s.errors = errors.Join(s.errors, err)
37
+
38
  }
39
 
40
  func (s *service[TRepo]) Exception() models.Exception {
 
48
  }
49
 
50
  func (s *service[TRepo]) ThrowsRepoException() bool {
51
+
52
  if s.repository.RowsError() != nil {
53
+
54
+ s.ThrowsException(&s.exception.QueryError, "Database error!")
55
  s.ThrowsError(s.repository.RowsError())
56
+
57
+ return true
58
+ }
59
+ if errors.Is(s.repository.RowsError(), gorm.ErrDuplicatedKey) {
60
+ s.ThrowsException(&s.exception.DataDuplicate, "Duplicated data!")
61
+
62
  return true
63
  }
64
  if s.repository.IsNoRecord() {
65
+
66
  s.ThrowsException(&s.exception.DataNotFound, "No record found")
67
  return true
68
  }
69
+
70
  return false
71
  }
space/repositories/chat_history_repository.go CHANGED
@@ -3,6 +3,7 @@ package repositories
3
  import (
4
  "context"
5
 
 
6
  "github.com/abdanhafidz/ai-visual-multi-modal-backend/models"
7
  )
8
 
@@ -18,7 +19,8 @@ type chatHistoryRepository struct {
18
  func NewChatHistoryRepository() ChatHistoryRepository {
19
  return &chatHistoryRepository{
20
  repository: &repository[models.ChatHistory]{
21
- entity: models.ChatHistory{},
 
22
  },
23
  }
24
  }
 
3
  import (
4
  "context"
5
 
6
+ "github.com/abdanhafidz/ai-visual-multi-modal-backend/config"
7
  "github.com/abdanhafidz/ai-visual-multi-modal-backend/models"
8
  )
9
 
 
19
  func NewChatHistoryRepository() ChatHistoryRepository {
20
  return &chatHistoryRepository{
21
  repository: &repository[models.ChatHistory]{
22
+ transaction: config.DB.Begin(),
23
+ entity: models.ChatHistory{},
24
  },
25
  }
26
  }
space/repositories/repository.go CHANGED
@@ -60,8 +60,7 @@ func (repo *repository[T1]) Transactions(ctx context.Context, act func(ctx conte
60
  repo.Unlock()
61
  }
62
  func (repo *repository[T1]) Where(ctx context.Context) {
63
-
64
- tx := repo.transaction.Begin()
65
  tx.WithContext(ctx).Where(&repo.entity)
66
  repo.Lock()
67
  repo.rowsCount = int(tx.RowsAffected)
@@ -71,7 +70,7 @@ func (repo *repository[T1]) Where(ctx context.Context) {
71
  }
72
  func (repo *repository[T1]) Find(ctx context.Context, res any) {
73
  repo.Lock()
74
- tx := repo.transaction.Begin()
75
  tx.WithContext(ctx).Find(&res)
76
  if tx.Error != nil {
77
  tx.Rollback()
@@ -85,7 +84,7 @@ func (repo *repository[T1]) Find(ctx context.Context, res any) {
85
 
86
  func (repo *repository[T1]) FindAllPaginate(ctx context.Context, res any) {
87
 
88
- tx := repo.transaction.Begin()
89
  tx.WithContext(ctx).Limit(repo.pagination.limit).Offset(repo.pagination.offset).Find(&res)
90
  if tx.Error != nil {
91
  tx.Rollback()
@@ -99,7 +98,7 @@ func (repo *repository[T1]) FindAllPaginate(ctx context.Context, res any) {
99
 
100
  func (repo *repository[T1]) Create(ctx context.Context) {
101
 
102
- tx := repo.transaction.Begin()
103
  tx.Create(&repo.entity).Find(&repo.entity)
104
  if tx.Error != nil {
105
  tx.Rollback()
@@ -113,7 +112,7 @@ func (repo *repository[T1]) Create(ctx context.Context) {
113
 
114
  func (repo *repository[T1]) Update(ctx context.Context) {
115
 
116
- tx := repo.transaction.Begin()
117
  tx.WithContext(ctx).Save(&repo.entity).Find(&repo.entity)
118
  if tx.Error != nil {
119
  tx.Rollback()
@@ -127,7 +126,7 @@ func (repo *repository[T1]) Update(ctx context.Context) {
127
 
128
  func (repo *repository[T1]) Delete(ctx context.Context) {
129
 
130
- tx := repo.transaction.Begin()
131
  tx.WithContext(ctx).Delete(&repo.entity)
132
  if tx.Error != nil {
133
  tx.Rollback()
@@ -141,7 +140,7 @@ func (repo *repository[T1]) Delete(ctx context.Context) {
141
 
142
  func (repo *repository[T1]) Query(ctx context.Context, res any) {
143
 
144
- tx := repo.transaction.Begin()
145
  tx.WithContext(ctx).Model(&repo.entity).Raw(repo.customQuery.sql, repo.customQuery.values).Scan(&res)
146
  if tx.Error != nil {
147
  tx.Rollback()
 
60
  repo.Unlock()
61
  }
62
  func (repo *repository[T1]) Where(ctx context.Context) {
63
+ tx := repo.transaction
 
64
  tx.WithContext(ctx).Where(&repo.entity)
65
  repo.Lock()
66
  repo.rowsCount = int(tx.RowsAffected)
 
70
  }
71
  func (repo *repository[T1]) Find(ctx context.Context, res any) {
72
  repo.Lock()
73
+ tx := repo.transaction
74
  tx.WithContext(ctx).Find(&res)
75
  if tx.Error != nil {
76
  tx.Rollback()
 
84
 
85
  func (repo *repository[T1]) FindAllPaginate(ctx context.Context, res any) {
86
 
87
+ tx := repo.transaction
88
  tx.WithContext(ctx).Limit(repo.pagination.limit).Offset(repo.pagination.offset).Find(&res)
89
  if tx.Error != nil {
90
  tx.Rollback()
 
98
 
99
  func (repo *repository[T1]) Create(ctx context.Context) {
100
 
101
+ tx := repo.transaction
102
  tx.Create(&repo.entity).Find(&repo.entity)
103
  if tx.Error != nil {
104
  tx.Rollback()
 
112
 
113
  func (repo *repository[T1]) Update(ctx context.Context) {
114
 
115
+ tx := repo.transaction
116
  tx.WithContext(ctx).Save(&repo.entity).Find(&repo.entity)
117
  if tx.Error != nil {
118
  tx.Rollback()
 
126
 
127
  func (repo *repository[T1]) Delete(ctx context.Context) {
128
 
129
+ tx := repo.transaction
130
  tx.WithContext(ctx).Delete(&repo.entity)
131
  if tx.Error != nil {
132
  tx.Rollback()
 
140
 
141
  func (repo *repository[T1]) Query(ctx context.Context, res any) {
142
 
143
+ tx := repo.transaction
144
  tx.WithContext(ctx).Model(&repo.entity).Raw(repo.customQuery.sql, repo.customQuery.values).Scan(&res)
145
  if tx.Error != nil {
146
  tx.Rollback()
space/space/Dockerfile CHANGED
@@ -1,6 +1,9 @@
1
  # Gunakan image dasar Golang versi 1.24.1
2
  FROM golang:1.24.1
3
 
 
 
 
4
  # Set working directory
5
  WORKDIR /app
6
 
@@ -29,18 +32,16 @@ RUN --mount=type=secret,id=DB_PASSWORD,mode=0444,required=false \
29
  echo "EMAIL_VERIFICATION_DURATION=2" >> .env && \
30
  echo "OPEN_AI_API_KEY=$(cat /run/secrets/OPENAI_API_KEY 2>/dev/null)" >> .env && \
31
  echo "REPLICATE_API_TOKEN=$(cat /run/secrets/REPLICATE_API_TOKEN 2>/dev/null)" >> .env
32
-
33
- RUN mkdir -p /app/audio && \
34
- chmod 777 /app/audio && \
35
- chown -R /app/audio/*
36
 
37
- RUN mkdir -p /app/logs && \
38
- chmod -R 777 /app/logs && \
39
- chown -R /app/logs/*
 
40
 
41
  # Build aplikasi
42
  RUN go build -o main .
43
 
 
44
  USER appuser
45
 
46
  # Expose port untuk Hugging Face Spaces
 
1
  # Gunakan image dasar Golang versi 1.24.1
2
  FROM golang:1.24.1
3
 
4
+ # Tambahkan user non-root untuk keamanan (optional tapi best practice)
5
+ RUN useradd -m -u 1001 appuser
6
+
7
  # Set working directory
8
  WORKDIR /app
9
 
 
32
  echo "EMAIL_VERIFICATION_DURATION=2" >> .env && \
33
  echo "OPEN_AI_API_KEY=$(cat /run/secrets/OPENAI_API_KEY 2>/dev/null)" >> .env && \
34
  echo "REPLICATE_API_TOKEN=$(cat /run/secrets/REPLICATE_API_TOKEN 2>/dev/null)" >> .env
 
 
 
 
35
 
36
+ # Buat direktori audio dan logs, beri izin dan kepemilikan ke appuser
37
+ RUN mkdir -p /app/audio /app/logs && \
38
+ chmod -R 777 /app/audio /app/logs && \
39
+ chown -R appuser:appuser /app/audio /app/logs
40
 
41
  # Build aplikasi
42
  RUN go build -o main .
43
 
44
+ # Beralih ke user non-root
45
  USER appuser
46
 
47
  # Expose port untuk Hugging Face Spaces
space/space/space/factory/prediction_factory.go CHANGED
@@ -8,11 +8,10 @@ import (
8
  )
9
 
10
  func NewPredictionModule() controller.PredictionController {
11
- var repo repositories.Repository
12
-
13
- openAIService := services.NewOpenAIService(repo, config.OpenAIClient)
14
- replicateService := services.NewReplicateService(repo, config.ReplicateClient, "lucataco/moondream2:72ccb656353c348c1385df54b237eeb7bfa874bf11486cf0b9473e691b662d31")
15
- predictionService := services.NewPredictionService(replicateService, openAIService)
16
  predictionController := controller.NewPredictionController(predictionService)
17
 
18
  return predictionController
 
8
  )
9
 
10
  func NewPredictionModule() controller.PredictionController {
11
+ chatHistoryRepository := repositories.NewChatHistoryRepository()
12
+ openAIService := services.NewOpenAIService(chatHistoryRepository, config.OpenAIClient)
13
+ replicateService := services.NewReplicateService(chatHistoryRepository, config.ReplicateClient, "lucataco/moondream2:72ccb656353c348c1385df54b237eeb7bfa874bf11486cf0b9473e691b662d31")
14
+ predictionService := services.NewPredictionService(chatHistoryRepository, replicateService, openAIService)
 
15
  predictionController := controller.NewPredictionController(predictionService)
16
 
17
  return predictionController
space/space/space/repositories/chat_history_repository.go CHANGED
@@ -15,6 +15,13 @@ type chatHistoryRepository struct {
15
  *repository[models.ChatHistory]
16
  }
17
 
 
 
 
 
 
 
 
18
  func (r *chatHistoryRepository) SaveChatHistory(ctx context.Context, imagePath string, question string, answer string) (res models.ChatHistory) {
19
  r.entity.ImagePath = imagePath
20
  r.entity.Question = question
 
15
  *repository[models.ChatHistory]
16
  }
17
 
18
+ func NewChatHistoryRepository() ChatHistoryRepository {
19
+ return &chatHistoryRepository{
20
+ repository: &repository[models.ChatHistory]{
21
+ entity: models.ChatHistory{},
22
+ },
23
+ }
24
+ }
25
  func (r *chatHistoryRepository) SaveChatHistory(ctx context.Context, imagePath string, question string, answer string) (res models.ChatHistory) {
26
  r.entity.ImagePath = imagePath
27
  r.entity.Question = question
space/space/space/services/prediction_service.go CHANGED
@@ -20,9 +20,11 @@ type (
20
  }
21
  )
22
 
23
- func NewPredictionService(replicateService ReplicateService, openAIService OpenAIService) PredictionService {
24
  return &predictionService{
25
- service: &service[repositories.ChatHistoryRepository]{},
 
 
26
  replicateService: replicateService,
27
  openAIService: openAIService,
28
  }
 
20
  }
21
  )
22
 
23
+ func NewPredictionService(chatHistoryRepository repositories.ChatHistoryRepository, replicateService ReplicateService, openAIService OpenAIService) PredictionService {
24
  return &predictionService{
25
+ service: &service[repositories.ChatHistoryRepository]{
26
+ repository: chatHistoryRepository,
27
+ },
28
  replicateService: replicateService,
29
  openAIService: openAIService,
30
  }
space/space/space/space/space/Dockerfile CHANGED
@@ -32,15 +32,17 @@ RUN --mount=type=secret,id=DB_PASSWORD,mode=0444,required=false \
32
 
33
  RUN mkdir -p /app/audio && \
34
  chmod 777 /app/audio && \
35
- chown -R $(whoami):$(whoami) /app/audio
36
 
37
  RUN mkdir -p /app/logs && \
38
- chmod 777 /app/logs && \
39
- chown -R $(whoami):$(whoami) /app/logs
40
 
41
  # Build aplikasi
42
  RUN go build -o main .
43
 
 
 
44
  # Expose port untuk Hugging Face Spaces
45
  EXPOSE 7860
46
 
 
32
 
33
  RUN mkdir -p /app/audio && \
34
  chmod 777 /app/audio && \
35
+ chown -R /app/audio/*
36
 
37
  RUN mkdir -p /app/logs && \
38
+ chmod -R 777 /app/logs && \
39
+ chown -R /app/logs/*
40
 
41
  # Build aplikasi
42
  RUN go build -o main .
43
 
44
+ USER appuser
45
+
46
  # Expose port untuk Hugging Face Spaces
47
  EXPOSE 7860
48
 
space/space/space/space/space/space/space/Dockerfile CHANGED
@@ -30,6 +30,14 @@ RUN --mount=type=secret,id=DB_PASSWORD,mode=0444,required=false \
30
  echo "OPEN_AI_API_KEY=$(cat /run/secrets/OPENAI_API_KEY 2>/dev/null)" >> .env && \
31
  echo "REPLICATE_API_TOKEN=$(cat /run/secrets/REPLICATE_API_TOKEN 2>/dev/null)" >> .env
32
 
 
 
 
 
 
 
 
 
33
  # Build aplikasi
34
  RUN go build -o main .
35
 
 
30
  echo "OPEN_AI_API_KEY=$(cat /run/secrets/OPENAI_API_KEY 2>/dev/null)" >> .env && \
31
  echo "REPLICATE_API_TOKEN=$(cat /run/secrets/REPLICATE_API_TOKEN 2>/dev/null)" >> .env
32
 
33
+ RUN mkdir -p /app/audio && \
34
+ chmod 777 /app/audio && \
35
+ chown -R $(whoami):$(whoami) /app/audio
36
+
37
+ RUN mkdir -p /app/logs && \
38
+ chmod 777 /app/logs && \
39
+ chown -R $(whoami):$(whoami) /app/logs
40
+
41
  # Build aplikasi
42
  RUN go build -o main .
43
 
space/space/space/space/space/space/space/space/space/Dockerfile CHANGED
@@ -21,14 +21,15 @@ RUN --mount=type=secret,id=DB_PASSWORD,mode=0444,required=false \
21
  echo "DB_USER=postgres.iuwuiuoisqnfdzlgwurl" >> .env && \
22
  echo "DB_PASSWORD=$(cat /run/secrets/DB_PASSWORD 2>/dev/null)" >> .env && \
23
  echo "DB_PORT=5432" >> .env && \
24
- echo "DB_NAME=kpppl" >> .env && \
25
  echo "SALT=NZNZtY7dNPz8l0dWINJZLKafWaJrql1s" >> .env && \
26
  echo "HOST_ADDRESS=0.0.0.0" >> .env && \
27
  echo "HOST_PORT=7860" >> .env && \
28
  echo "LOG_PATH=logs" >> .env && \
29
  echo "EMAIL_VERIFICATION_DURATION=2" >> .env && \
30
  echo "OPEN_AI_API_KEY=$(cat /run/secrets/OPENAI_API_KEY 2>/dev/null)" >> .env && \
31
- echo "REPLICATE_API_TOKEN=$(cat /run/secrets/REPLICATE_API_TOKEN 2>/dev/null)" >> .env && \
 
32
  # Build aplikasi
33
  RUN go build -o main .
34
 
 
21
  echo "DB_USER=postgres.iuwuiuoisqnfdzlgwurl" >> .env && \
22
  echo "DB_PASSWORD=$(cat /run/secrets/DB_PASSWORD 2>/dev/null)" >> .env && \
23
  echo "DB_PORT=5432" >> .env && \
24
+ echo "DB_NAME=postgres" >> .env && \
25
  echo "SALT=NZNZtY7dNPz8l0dWINJZLKafWaJrql1s" >> .env && \
26
  echo "HOST_ADDRESS=0.0.0.0" >> .env && \
27
  echo "HOST_PORT=7860" >> .env && \
28
  echo "LOG_PATH=logs" >> .env && \
29
  echo "EMAIL_VERIFICATION_DURATION=2" >> .env && \
30
  echo "OPEN_AI_API_KEY=$(cat /run/secrets/OPENAI_API_KEY 2>/dev/null)" >> .env && \
31
+ echo "REPLICATE_API_TOKEN=$(cat /run/secrets/REPLICATE_API_TOKEN 2>/dev/null)" >> .env
32
+
33
  # Build aplikasi
34
  RUN go build -o main .
35
 
space/space/space/space/space/space/space/space/space/space/space/Dockerfile CHANGED
@@ -14,13 +14,12 @@ RUN go mod download
14
  COPY . .
15
 
16
  # Buat file .env dengan variabel environment menggunakan Hugging Face secrets
17
- RUN --mount=type=secret,id=HF_TOKEN,mode=0444,required=true \
18
- --mount=type=secret,id=DB_PASSWORD,mode=0444,required=false \
19
  --mount=type=secret,id=OPENAI_API_KEY,mode=0444,required=false \
20
  --mount=type=secret,id=REPLICATE_API_TOKEN,mode=0444,required=false \
21
  echo "DB_HOST=aws-0-ap-southeast-1.pooler.supabase.com" >> .env && \
22
  echo "DB_USER=postgres.iuwuiuoisqnfdzlgwurl" >> .env && \
23
- echo "DB_PASSWORD=$(cat /run/secrets/DB_PASSWORD 2>/dev/null')" >> .env && \
24
  echo "DB_PORT=5432" >> .env && \
25
  echo "DB_NAME=kpppl" >> .env && \
26
  echo "SALT=NZNZtY7dNPz8l0dWINJZLKafWaJrql1s" >> .env && \
@@ -37,4 +36,4 @@ RUN go build -o main .
37
  EXPOSE 7860
38
 
39
  # Jalankan aplikasi
40
- CMD ["./main"]
 
14
  COPY . .
15
 
16
  # Buat file .env dengan variabel environment menggunakan Hugging Face secrets
17
+ RUN --mount=type=secret,id=DB_PASSWORD,mode=0444,required=false \
 
18
  --mount=type=secret,id=OPENAI_API_KEY,mode=0444,required=false \
19
  --mount=type=secret,id=REPLICATE_API_TOKEN,mode=0444,required=false \
20
  echo "DB_HOST=aws-0-ap-southeast-1.pooler.supabase.com" >> .env && \
21
  echo "DB_USER=postgres.iuwuiuoisqnfdzlgwurl" >> .env && \
22
+ echo "DB_PASSWORD=$(cat /run/secrets/DB_PASSWORD 2>/dev/null)" >> .env && \
23
  echo "DB_PORT=5432" >> .env && \
24
  echo "DB_NAME=kpppl" >> .env && \
25
  echo "SALT=NZNZtY7dNPz8l0dWINJZLKafWaJrql1s" >> .env && \
 
36
  EXPOSE 7860
37
 
38
  # Jalankan aplikasi
39
+ CMD ["./main"]
space/space/space/space/space/space/space/space/space/space/space/space/space/.env.example ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ DB_HOST =
2
+ DB_USER =
3
+ DB_PASSWORD =
4
+ DB_PORT =
5
+ DB_NAME =
6
+ SALT =
7
+ HOST_ADDRESS =
8
+ HOST_PORT =
9
+ LOG_PATH = logs
10
+ OPEN_AI_API_KEY =
11
+ REPLICATE_API_TOKEN =
space/space/space/space/space/space/space/space/space/space/space/space/space/.github/workflows/deploy.yml ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Deploy to Huggingface
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ jobs:
9
+ deploy-to-huggingface:
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ # Checkout repository
14
+ - name: Checkout Repository
15
+ uses: actions/checkout@v3
16
+
17
+ # Setup Git
18
+ - name: Setup Git for Huggingface
19
+ run: |
20
+ git config --global user.email "abdan.hafidz@gmail.com"
21
+ git config --global user.name "abdanhafidz"
22
+
23
+ # Clone Huggingface Space Repository
24
+ - name: Clone Huggingface Space
25
+ env:
26
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
27
+ run: |
28
+ git clone https://huggingface.co/spaces/lifedebugger/urna-backend space
29
+
30
+ # Update Git Remote URL and Pull Latest Changes
31
+ - name: Update Remote and Pull Changes
32
+ env:
33
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
34
+ run: |
35
+ cd space
36
+ git remote set-url origin https://lifedebugger:$HF_TOKEN@huggingface.co/spaces/lifedebugger/urna-backend
37
+ git pull origin main || echo "No changes to pull"
38
+
39
+ # Copy Files to Huggingface Space
40
+ - name: Copy Files to Space
41
+ run: |
42
+ rsync -av --exclude='.git' ./ space/
43
+
44
+ # Commit and Push to Huggingface Space
45
+ - name: Commit and Push to Huggingface
46
+ env:
47
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
48
+ run: |
49
+ cd space
50
+ git add .
51
+ git commit -m "Deploy files from GitHub repository" || echo "No changes to commit"
52
+ git push origin main || echo "No changes to push"
space/space/space/space/space/space/space/space/space/space/space/space/space/.github/workflows/go.yml ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This workflow will build a golang project
2
+ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
3
+
4
+ name: Go
5
+
6
+ on:
7
+ push:
8
+ branches: [ "main" ]
9
+ pull_request:
10
+ branches: [ "main" ]
11
+
12
+ jobs:
13
+
14
+ build:
15
+ runs-on: ubuntu-latest
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - name: Set up Go
20
+ uses: actions/setup-go@v4
21
+ with:
22
+ go-version: '1.20'
23
+
24
+ - name: Build
25
+ run: go build -v ./...
26
+
27
+ - name: Test
28
+ run: go test -v ./...
space/space/space/space/space/space/space/space/space/space/space/space/space/.gitignore ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ .env
2
+ vendor/
3
+ quzuu-be.exe
4
+ README.md
5
+ .qodo
space/space/space/space/space/space/space/space/space/space/space/space/space/Dockerfile ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Gunakan image dasar Golang versi 1.24.1
2
+ FROM golang:1.24.1
3
+
4
+ # Set working directory
5
+ WORKDIR /app
6
+
7
+ # Copy go.mod dan go.sum
8
+ COPY go.mod go.sum ./
9
+
10
+ # Download dependencies
11
+ RUN go mod download
12
+
13
+ # Copy seluruh kode
14
+ COPY . .
15
+
16
+ # Buat file .env dengan variabel environment menggunakan Hugging Face secrets
17
+ RUN --mount=type=secret,id=HF_TOKEN,mode=0444,required=true \
18
+ --mount=type=secret,id=DB_PASSWORD,mode=0444,required=false \
19
+ --mount=type=secret,id=OPENAI_API_KEY,mode=0444,required=false \
20
+ --mount=type=secret,id=REPLICATE_API_TOKEN,mode=0444,required=false \
21
+ echo "DB_HOST=aws-0-ap-southeast-1.pooler.supabase.com" >> .env && \
22
+ echo "DB_USER=postgres.iuwuiuoisqnfdzlgwurl" >> .env && \
23
+ echo "DB_PASSWORD=$(cat /run/secrets/DB_PASSWORD 2>/dev/null')" >> .env && \
24
+ echo "DB_PORT=5432" >> .env && \
25
+ echo "DB_NAME=kpppl" >> .env && \
26
+ echo "SALT=NZNZtY7dNPz8l0dWINJZLKafWaJrql1s" >> .env && \
27
+ echo "HOST_ADDRESS=0.0.0.0" >> .env && \
28
+ echo "HOST_PORT=7860" >> .env && \
29
+ echo "LOG_PATH=logs" >> .env && \
30
+ echo "EMAIL_VERIFICATION_DURATION=2" >> .env && \
31
+ echo "OPEN_AI_API_KEY=$(cat /run/secrets/OPENAI_API_KEY 2>/dev/null)" >> .env && \
32
+ echo "REPLICATE_API_TOKEN=$(cat /run/secrets/REPLICATE_API_TOKEN 2>/dev/null)" >> .env && \
33
+ # Build aplikasi
34
+ RUN go build -o main .
35
+
36
+ # Expose port untuk Hugging Face Spaces
37
+ EXPOSE 7860
38
+
39
+ # Jalankan aplikasi
40
+ CMD ["./main"]
space/space/space/space/space/space/space/space/space/space/space/space/space/LICENSE ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 Abdan Hafidz
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
space/space/space/space/space/space/space/space/space/space/space/space/space/audio/20250616_235223.mp3 ADDED
Binary file (78.5 kB). View file
 
space/space/space/space/space/space/space/space/space/space/space/space/space/config/config.go ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package config
2
+
3
+ import (
4
+ "os"
5
+ "strconv"
6
+
7
+ "github.com/joho/godotenv"
8
+ )
9
+
10
+ var TCP_ADDRESS string
11
+ var LOG_PATH string
12
+ var HOST_ADDRESS string
13
+ var HOST_PORT string
14
+ var EMAIL_VERIFICATION_DURATION int
15
+ var OPEN_AI_API_KEY string
16
+ var REPLICATE_API_KEY string
17
+
18
+ func init() {
19
+ godotenv.Load()
20
+ HOST_ADDRESS = os.Getenv("HOST_ADDRESS")
21
+ HOST_PORT = os.Getenv("HOST_PORT")
22
+ TCP_ADDRESS = HOST_ADDRESS + ":" + HOST_PORT
23
+ LOG_PATH = os.Getenv("LOG_PATH")
24
+ EMAIL_VERIFICATION_DURATION, _ = strconv.Atoi(os.Getenv("EMAIL_VERIFICATION_DURATION"))
25
+ OPEN_AI_API_KEY = os.Getenv("OPEN_AI_API_KEY")
26
+ REPLICATE_API_KEY = os.Getenv("REPLICATE_API_KEY")
27
+ }
space/space/space/space/space/space/space/space/space/space/space/space/space/config/database_connection_config.go ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package config
2
+
3
+ import (
4
+ "fmt"
5
+ "log"
6
+ "os"
7
+
8
+ "gorm.io/driver/postgres"
9
+ "gorm.io/gorm"
10
+ "gorm.io/gorm/logger"
11
+
12
+ models "github.com/abdanhafidz/ai-visual-multi-modal-backend/models"
13
+ "github.com/joho/godotenv"
14
+ )
15
+
16
+ var DB *gorm.DB
17
+ var err error
18
+ var Salt string
19
+
20
+ func init() {
21
+ godotenv.Load()
22
+ if err != nil {
23
+ fmt.Println("Gagal membaca file .env")
24
+ return
25
+ }
26
+ os.Setenv("TZ", "Asia/Jakarta")
27
+ dbHost := os.Getenv("DB_HOST")
28
+ dbPort := os.Getenv("DB_PORT")
29
+ dbUser := os.Getenv("DB_USER")
30
+ dbPassword := os.Getenv("DB_PASSWORD")
31
+ dbName := os.Getenv("DB_NAME")
32
+ Salt := os.Getenv("SALT")
33
+ dsn := "host=" + dbHost + " user=" + dbUser + " password=" + dbPassword + " dbname=" + dbName + " port=" + dbPort + " sslmode=disable TimeZone=Asia/Jakarta"
34
+ DB, err = gorm.Open(postgres.Open(dsn), &gorm.Config{TranslateError: true})
35
+ if err != nil {
36
+ panic(err)
37
+ }
38
+ if Salt == "" {
39
+ Salt = "D3f4u|t"
40
+ }
41
+
42
+ // Call AutoMigrateAll to perform auto-migration
43
+ AutoMigrateAll(DB)
44
+ }
45
+
46
+ func AutoMigrateAll(db *gorm.DB) {
47
+ // Enable logger to see SQL logs
48
+ db.Logger.LogMode(logger.Info)
49
+
50
+ // Auto-migrate all models
51
+ err := db.AutoMigrate(
52
+ &models.Account{},
53
+ &models.ChatHistory{},
54
+ )
55
+
56
+ if err != nil {
57
+ log.Fatal(err)
58
+ }
59
+
60
+ fmt.Println("Migration completed successfully.")
61
+ }
space/space/space/space/space/space/space/space/space/space/space/space/space/config/openai_client_config.go ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package config
2
+
3
+ import (
4
+ "github.com/sashabaranov/go-openai"
5
+ )
6
+
7
+ var OpenAIClient *openai.Client
8
+
9
+ func init() {
10
+ OpenAIClient = openai.NewClient(OPEN_AI_API_KEY)
11
+ }
space/space/space/space/space/space/space/space/space/space/space/space/space/config/replicate_client_config.go ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package config
2
+
3
+ import (
4
+ "github.com/replicate/replicate-go"
5
+ )
6
+
7
+ var ReplicateClient *replicate.Client
8
+
9
+ func init() {
10
+ ReplicateClient, err = replicate.NewClient(replicate.WithTokenFromEnv())
11
+ if err != nil {
12
+ panic(err)
13
+ }
14
+ }
space/space/space/space/space/space/space/space/space/space/space/space/space/controller/controller.go ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package controller
2
+
3
+ import (
4
+ models "github.com/abdanhafidz/ai-visual-multi-modal-backend/models"
5
+ services "github.com/abdanhafidz/ai-visual-multi-modal-backend/services"
6
+ utils "github.com/abdanhafidz/ai-visual-multi-modal-backend/utils"
7
+ "github.com/gin-gonic/gin"
8
+ )
9
+
10
+ type (
11
+ Controller interface {
12
+ HeaderParse(ctx *gin.Context)
13
+ RequestJSON(ctx *gin.Context, request any)
14
+ Response(ctx *gin.Context, res any)
15
+ }
16
+ controller[TService services.Service] struct {
17
+ accountData models.AccountData
18
+ service TService
19
+ }
20
+ )
21
+
22
+ func (c *controller[TService]) HeaderParse(ctx *gin.Context) {
23
+ cParam, _ := ctx.Get("account_data")
24
+ if cParam != nil {
25
+ c.accountData = cParam.(models.AccountData)
26
+ }
27
+ }
28
+
29
+ func (c *controller[TService]) RequestJSON(ctx *gin.Context, request any) {
30
+ cParam, _ := ctx.Get("AccountData")
31
+ if cParam != nil {
32
+ c.accountData = cParam.(models.AccountData)
33
+ }
34
+
35
+ errBinding := ctx.ShouldBindJSON(&request)
36
+ if errBinding != nil {
37
+ utils.ResponseFAIL(ctx, 400, models.Exception{
38
+ BadRequest: true,
39
+ Message: "Invalid Request!, recheck your request, there's must be some problem about required parameter or type parameter",
40
+ })
41
+ return
42
+ }
43
+ }
44
+
45
+ func (c *controller[TService]) Response(ctx *gin.Context, res any) {
46
+ switch {
47
+ case c.service.Error() != nil:
48
+ utils.ResponseFAIL(ctx, 500, models.Exception{
49
+ InternalServerError: true,
50
+ Message: "Internal Server Error",
51
+ })
52
+ utils.LogError(c.service.Error())
53
+ case c.service.Exception().DataDuplicate:
54
+ utils.ResponseFAIL(ctx, 400, c.service.Exception())
55
+ case c.service.Exception().Unauthorized:
56
+ utils.ResponseFAIL(ctx, 401, c.service.Exception())
57
+ case c.service.Exception().DataNotFound:
58
+ utils.ResponseFAIL(ctx, 404, c.service.Exception())
59
+ case c.service.Exception().Message != "":
60
+ utils.ResponseFAIL(ctx, 400, c.service.Exception())
61
+ default:
62
+ utils.ResponseOK(ctx, res)
63
+ }
64
+ }
space/space/space/space/space/space/space/space/space/space/space/space/space/controller/home_controller.go ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ package controller
2
+
3
+ import "github.com/gin-gonic/gin"
4
+
5
+ func HomeController(c *gin.Context) {
6
+ c.JSON(200, gin.H{
7
+ "message": "API Is Running Gladly!",
8
+ })
9
+ }
space/space/space/space/space/space/space/space/space/space/space/space/space/controller/prediction_controller.go ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package controller
2
+
3
+ import (
4
+ "fmt"
5
+ "mime/multipart"
6
+
7
+ models "github.com/abdanhafidz/ai-visual-multi-modal-backend/models"
8
+ services "github.com/abdanhafidz/ai-visual-multi-modal-backend/services"
9
+ utils "github.com/abdanhafidz/ai-visual-multi-modal-backend/utils"
10
+ "github.com/gin-gonic/gin"
11
+ )
12
+
13
+ type (
14
+ PredictionController interface {
15
+ Controller
16
+ Predict(ctx *gin.Context)
17
+ }
18
+
19
+ predictionController struct {
20
+ *controller[services.PredictionService]
21
+ }
22
+ )
23
+
24
+ func requestImage(ctx *gin.Context, image *multipart.File, imageFilename *string) {
25
+ imageHeader, err := ctx.FormFile("image_file")
26
+ if err != nil {
27
+ utils.ResponseFAIL(ctx, 400, models.Exception{
28
+ BadRequest: true,
29
+ Message: "Image file is required",
30
+ })
31
+ return
32
+ }
33
+ imageFile, err := imageHeader.Open()
34
+ if err != nil {
35
+ utils.ResponseFAIL(ctx, 400, models.Exception{
36
+ BadRequest: true,
37
+ Message: "Failed to open image file",
38
+ })
39
+ return
40
+ }
41
+ *image = imageFile
42
+ *imageFilename = imageHeader.Filename
43
+ defer imageFile.Close()
44
+ }
45
+
46
+ func requestAudio(ctx *gin.Context, audio *multipart.File, audioFilename *string) {
47
+ audioHeader, err := ctx.FormFile("audio_file")
48
+ fmt.Println(audioHeader.Filename)
49
+ if err != nil {
50
+ utils.ResponseFAIL(ctx, 400, models.Exception{
51
+ BadRequest: true,
52
+ Message: "Audio file is required",
53
+ })
54
+ return
55
+ }
56
+ audioFile, err := audioHeader.Open()
57
+ if err != nil {
58
+ utils.ResponseFAIL(ctx, 400, models.Exception{
59
+ BadRequest: true,
60
+ Message: "Failed to open audio file",
61
+ })
62
+ return
63
+ }
64
+ *audio = audioFile
65
+ *audioFilename = audioHeader.Filename
66
+ defer audioFile.Close()
67
+ }
68
+
69
+ func NewPredictionController(predictionService services.PredictionService) PredictionController {
70
+ return &predictionController{
71
+ controller: &controller[services.PredictionService]{
72
+ service: predictionService,
73
+ },
74
+ }
75
+ }
76
+ func (c *predictionController) Predict(ctx *gin.Context) {
77
+
78
+ var predictionRequest models.PredictionRequest
79
+
80
+ requestImage(ctx, &predictionRequest.ImageFile, &predictionRequest.ImageFileName)
81
+ requestAudio(ctx, &predictionRequest.AudioQuestionFile, &predictionRequest.AudioQuestionFilename)
82
+
83
+ predictionResult, text_output := c.service.Predict(ctx, predictionRequest)
84
+
85
+ if c.service.Error() != nil {
86
+ c.Response(ctx, nil)
87
+ return
88
+ }
89
+
90
+ ctx.Header("Content-Type", "audio/mpeg")
91
+ ctx.Header("Content-Disposition", "inline; filename=response.mp3")
92
+ ctx.Header("X-Response-Text", text_output)
93
+ ctx.Data(200, "audio/mpeg", predictionResult)
94
+
95
+ }
space/space/space/space/space/space/space/space/space/space/space/space/space/docker-compose.yaml ADDED
File without changes
space/space/space/space/space/space/space/space/space/space/space/space/space/factory/factory.go ADDED
@@ -0,0 +1 @@
 
 
1
+ package factory
space/space/space/space/space/space/space/space/space/space/space/space/space/factory/prediction_factory.go ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package factory
2
+
3
+ import (
4
+ "github.com/abdanhafidz/ai-visual-multi-modal-backend/config"
5
+ "github.com/abdanhafidz/ai-visual-multi-modal-backend/controller"
6
+ repositories "github.com/abdanhafidz/ai-visual-multi-modal-backend/repositories"
7
+ "github.com/abdanhafidz/ai-visual-multi-modal-backend/services"
8
+ )
9
+
10
+ func NewPredictionModule() controller.PredictionController {
11
+ var repo repositories.Repository
12
+
13
+ openAIService := services.NewOpenAIService(repo, config.OpenAIClient)
14
+ replicateService := services.NewReplicateService(repo, config.ReplicateClient, "lucataco/moondream2:72ccb656353c348c1385df54b237eeb7bfa874bf11486cf0b9473e691b662d31")
15
+ predictionService := services.NewPredictionService(replicateService, openAIService)
16
+ predictionController := controller.NewPredictionController(predictionService)
17
+
18
+ return predictionController
19
+ }
space/space/space/space/space/space/space/space/space/space/space/space/space/go.mod ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module github.com/abdanhafidz/ai-visual-multi-modal-backend
2
+
3
+ go 1.24.0
4
+
5
+ require (
6
+ github.com/dgrijalva/jwt-go v3.2.0+incompatible
7
+ github.com/gin-gonic/gin v1.10.0
8
+ github.com/golang-jwt/jwt/v5 v5.2.1
9
+ github.com/joho/godotenv v1.5.1
10
+ github.com/satori/go.uuid v1.2.0
11
+ golang.org/x/crypto v0.36.0
12
+ gorm.io/driver/postgres v1.5.11
13
+ gorm.io/gorm v1.25.12
14
+ )
15
+
16
+ require (
17
+ github.com/bytedance/sonic v1.13.1 // indirect
18
+ github.com/bytedance/sonic/loader v0.2.4 // indirect
19
+ github.com/cloudwego/base64x v0.1.5 // indirect
20
+ github.com/gabriel-vasile/mimetype v1.4.8 // indirect
21
+ github.com/gin-contrib/sse v1.0.0 // indirect
22
+ github.com/go-playground/locales v0.14.1 // indirect
23
+ github.com/go-playground/universal-translator v0.18.1 // indirect
24
+ github.com/go-playground/validator/v10 v10.25.0 // indirect
25
+ github.com/goccy/go-json v0.10.5 // indirect
26
+ github.com/jackc/pgpassfile v1.0.0 // indirect
27
+ github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
28
+ github.com/jackc/pgx/v5 v5.7.2 // indirect
29
+ github.com/jackc/puddle/v2 v2.2.2 // indirect
30
+ github.com/jinzhu/inflection v1.0.0 // indirect
31
+ github.com/jinzhu/now v1.1.5 // indirect
32
+ github.com/json-iterator/go v1.1.12 // indirect
33
+ github.com/klauspost/cpuid/v2 v2.2.10 // indirect
34
+ github.com/kr/text v0.2.0 // indirect
35
+ github.com/leodido/go-urn v1.4.0 // indirect
36
+ github.com/mattn/go-isatty v0.0.20 // indirect
37
+ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
38
+ github.com/modern-go/reflect2 v1.0.2 // indirect
39
+ github.com/pelletier/go-toml/v2 v2.2.3 // indirect
40
+ github.com/replicate/replicate-go v0.26.0 // indirect
41
+ github.com/rogpeppe/go-internal v1.11.0 // indirect
42
+ github.com/sashabaranov/go-openai v1.40.1 // indirect
43
+ github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
44
+ github.com/ugorji/go/codec v1.2.12 // indirect
45
+ github.com/vincent-petithory/dataurl v1.0.0 // indirect
46
+ golang.org/x/arch v0.15.0 // indirect
47
+ golang.org/x/net v0.37.0 // indirect
48
+ golang.org/x/sync v0.12.0 // indirect
49
+ golang.org/x/sys v0.31.0 // indirect
50
+ golang.org/x/text v0.23.0 // indirect
51
+ google.golang.org/protobuf v1.36.5 // indirect
52
+ gopkg.in/yaml.v3 v3.0.1 // indirect
53
+ )
space/space/space/space/space/space/space/space/space/space/space/space/space/go.sum ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ github.com/bytedance/sonic v1.13.1 h1:Jyd5CIvdFnkOWuKXr+wm4Nyk2h0yAFsr8ucJgEasO3g=
2
+ github.com/bytedance/sonic v1.13.1/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4=
3
+ github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
4
+ github.com/bytedance/sonic/loader v0.2.4 h1:ZWCw4stuXUsn1/+zQDqeE7JKP+QO47tz7QCNan80NzY=
5
+ github.com/bytedance/sonic/loader v0.2.4/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI=
6
+ github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCyP4=
7
+ github.com/cloudwego/base64x v0.1.5/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
8
+ github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
9
+ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
10
+ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
11
+ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
12
+ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
13
+ github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
14
+ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
15
+ github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
16
+ github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
17
+ github.com/gin-contrib/sse v1.0.0 h1:y3bT1mUWUxDpW4JLQg/HnTqV4rozuW4tC9eFKTxYI9E=
18
+ github.com/gin-contrib/sse v1.0.0/go.mod h1:zNuFdwarAygJBht0NTKiSi3jRf6RbqeILZ9Sp6Slhe0=
19
+ github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
20
+ github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
21
+ github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
22
+ github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
23
+ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
24
+ github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
25
+ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
26
+ github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
27
+ github.com/go-playground/validator/v10 v10.25.0 h1:5Dh7cjvzR7BRZadnsVOzPhWsrwUr0nmsZJxEAnFLNO8=
28
+ github.com/go-playground/validator/v10 v10.25.0/go.mod h1:GGzBIJMuE98Ic/kJsBXbz1x/7cByt++cQ+YOuDM5wus=
29
+ github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=
30
+ github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
31
+ github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
32
+ github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
33
+ github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
34
+ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
35
+ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
36
+ github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
37
+ github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
38
+ github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
39
+ github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
40
+ github.com/jackc/pgx/v5 v5.7.2 h1:mLoDLV6sonKlvjIEsV56SkWNCnuNv531l94GaIzO+XI=
41
+ github.com/jackc/pgx/v5 v5.7.2/go.mod h1:ncY89UGWxg82EykZUwSpUKEfccBGGYq1xjrOpsbsfGQ=
42
+ github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
43
+ github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
44
+ github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
45
+ github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
46
+ github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
47
+ github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
48
+ github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
49
+ github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
50
+ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
51
+ github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
52
+ github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
53
+ github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=
54
+ github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
55
+ github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
56
+ github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
57
+ github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
58
+ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
59
+ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
60
+ github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
61
+ github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
62
+ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
63
+ github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
64
+ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
65
+ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
66
+ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
67
+ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
68
+ github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
69
+ github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
70
+ github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
71
+ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
72
+ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
73
+ github.com/replicate/replicate-go v0.26.0 h1:F6XceIkO0x2ft08mc9MdNJSNbkXDqEtOK9GsgjqHQeQ=
74
+ github.com/replicate/replicate-go v0.26.0/go.mod h1:mnRw0hsQuVrgWKMm/kP29pY6Ldn//79b4C2Nw9sYn5M=
75
+ github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
76
+ github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
77
+ github.com/sashabaranov/go-openai v1.40.1 h1:bJ08Iwct5mHBVkuvG6FEcb9MDTfsXdTYPGjYLRdeTEU=
78
+ github.com/sashabaranov/go-openai v1.40.1/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=
79
+ github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
80
+ github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
81
+ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
82
+ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
83
+ github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
84
+ github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
85
+ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
86
+ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
87
+ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
88
+ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
89
+ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
90
+ github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
91
+ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
92
+ github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
93
+ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
94
+ github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
95
+ github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
96
+ github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
97
+ github.com/vincent-petithory/dataurl v1.0.0 h1:cXw+kPto8NLuJtlMsI152irrVw9fRDX8AbShPRpg2CI=
98
+ github.com/vincent-petithory/dataurl v1.0.0/go.mod h1:FHafX5vmDzyP+1CQATJn7WFKc9CvnvxyvZy6I1MrG/U=
99
+ golang.org/x/arch v0.15.0 h1:QtOrQd0bTUnhNVNndMpLHNWrDmYzZ2KDqSrEymqInZw=
100
+ golang.org/x/arch v0.15.0/go.mod h1:JmwW7aLIoRUKgaTzhkiEFxvcEiQGyOg9BMonBJUS7EE=
101
+ golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
102
+ golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
103
+ golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c=
104
+ golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
105
+ golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw=
106
+ golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
107
+ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
108
+ golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
109
+ golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
110
+ golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
111
+ golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
112
+ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
113
+ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
114
+ google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
115
+ google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
116
+ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
117
+ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
118
+ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
119
+ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
120
+ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
121
+ gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
122
+ gorm.io/driver/postgres v1.5.11 h1:ubBVAfbKEUld/twyKZ0IYn9rSQh448EdelLYk9Mv314=
123
+ gorm.io/driver/postgres v1.5.11/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI=
124
+ gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8=
125
+ gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
126
+ nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
space/space/space/space/space/space/space/space/space/space/space/space/space/logs/error_log.txt ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 2025/06/16 23:53:52 Error Log : open audio: is a directory
2
+ 2025/06/16 23:54:20 Error Log : open audio: is a directory
3
+ open audio: is a directory
4
+ open audio: is a directory
5
+ 2025/06/16 23:54:37 Error Log : open audio: is a directory
6
+ open audio: is a directory
7
+ open audio: is a directory
8
+ open audio: is a directory
9
+ open audio: is a directory
10
+ open audio: is a directory
11
+ 2025/06/16 23:56:46 Error Log : open audio: is a directory
12
+ 2025/06/16 23:57:43 Error Log : open audio: is a directory
13
+ 2025/06/17 00:00:14 Error Log : open audio: is a directory
14
+ 2025/06/17 00:01:06 Error Log : error, status code: 429, status: 429 Too Many Requests, message: You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.
15
+ 2025/06/17 00:16:55 Error Log : remove audio\20250616_235223.mp3: The process cannot access the file because it is being used by another process.
16
+ 2025/06/17 00:29:21 Error Log : error, status code: 400, status: 400 Bad Request, message: [{'type': 'string_too_short', 'loc': ('body', 'input'), 'msg': 'String should have at least 1 character', 'input': '', 'ctx': {'min_length': 1}}]
17
+ 2025/06/17 00:30:56 Error Log : error, status code: 400, status: 400 Bad Request, message: [{'type': 'string_too_short', 'loc': ('body', 'input'), 'msg': 'String should have at least 1 character', 'input': '', 'ctx': {'min_length': 1}}]
18
+ 2025/06/17 00:32:14 Error Log : error, status code: 400, status: 400 Bad Request, message: [{'type': 'string_too_short', 'loc': ('body', 'input'), 'msg': 'String should have at least 1 character', 'input': '', 'ctx': {'min_length': 1}}]
19
+ 2025/06/17 00:33:03 Error Log : error, status code: 400, status: 400 Bad Request, message: [{'type': 'string_too_short', 'loc': ('body', 'input'), 'msg': 'String should have at least 1 character', 'input': '', 'ctx': {'min_length': 1}}]
space/space/space/space/space/space/space/space/space/space/space/space/space/logs/security_log.txt ADDED
File without changes
space/space/space/space/space/space/space/space/space/space/space/space/space/main.go ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package main
2
+
3
+ import (
4
+ "fmt"
5
+
6
+ config "github.com/abdanhafidz/ai-visual-multi-modal-backend/config"
7
+ router "github.com/abdanhafidz/ai-visual-multi-modal-backend/router"
8
+ )
9
+
10
+ func main() {
11
+ fmt.Println("Server started on ", config.TCP_ADDRESS, ", port :", config.HOST_PORT)
12
+ router.StartService()
13
+
14
+ }
space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/authentication_middleware.go ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // auth/auth.go
2
+
3
+ package middleware
4
+
5
+ import (
6
+ "time"
7
+
8
+ config "github.com/abdanhafidz/ai-visual-multi-modal-backend/config"
9
+ models "github.com/abdanhafidz/ai-visual-multi-modal-backend/models"
10
+ utils "github.com/abdanhafidz/ai-visual-multi-modal-backend/utils"
11
+ "github.com/gin-gonic/gin"
12
+ "github.com/golang-jwt/jwt/v5"
13
+ )
14
+
15
+ var salt = config.Salt
16
+ var secretKey = []byte(salt)
17
+
18
+ // VerifyPassword verifies if the provided password matches the hashed password
19
+
20
+ type CustomClaims struct {
21
+ jwt.RegisteredClaims
22
+ UserID int `json:"id"`
23
+ }
24
+
25
+ func VerifyToken(bearer_token string) (int, string, error) {
26
+ // fmt.Println(bearer_token)
27
+ token, err := jwt.ParseWithClaims(bearer_token, &CustomClaims{}, func(token *jwt.Token) (interface{}, error) {
28
+ return secretKey, nil
29
+ })
30
+ if err != nil {
31
+ return 0, "invalid-token", err
32
+ }
33
+
34
+ // Extract the claims
35
+ claims, ok := token.Claims.(*CustomClaims)
36
+ if !ok || !token.Valid {
37
+ return 0, "invalid-token", err
38
+ }
39
+ if claims.ExpiresAt != nil && claims.ExpiresAt.Time.Before(time.Now()) {
40
+ return 0, "expired", err
41
+ }
42
+
43
+ return claims.UserID, "valid", err
44
+ }
45
+
46
+ func AuthUser(c *gin.Context) {
47
+ var currAccData models.AccountData
48
+ if c.Request.Header["Auth-Bearer-Token"] != nil {
49
+ token := c.Request.Header["Auth-Bearer-Token"]
50
+ currAccData.UserID, currAccData.VerifyStatus, currAccData.ErrVerif = VerifyToken(token[0])
51
+ // fmt.Println("Verify Status :", currAccData.verifyStatus)
52
+ if currAccData.VerifyStatus == "invalid-token" || currAccData.VerifyStatus == "expired" {
53
+ currAccData.UserID = 0
54
+ utils.ResponseFAIL(c, 401, models.Exception{Unauthorized: true, Message: "Your session is expired, Please re-Login!"})
55
+ c.Abort()
56
+ return
57
+ } else {
58
+ c.Set("accountData", currAccData)
59
+ c.Next()
60
+ }
61
+ } else {
62
+ currAccData.UserID = 0
63
+ currAccData.VerifyStatus = "no-token"
64
+ currAccData.ErrVerif = nil
65
+ utils.ResponseFAIL(c, 401, models.Exception{Unauthorized: true, Message: "You have to login first!"})
66
+ c.Abort()
67
+ return
68
+ }
69
+
70
+ }
space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/middleware.go ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package middleware
2
+
3
+ import (
4
+ "math"
5
+ "time"
6
+
7
+ "gorm.io/gorm"
8
+ )
9
+
10
+ func RecordCheck(rows *gorm.DB) (string, error) {
11
+ count := rows.RowsAffected
12
+ err := rows.Error
13
+
14
+ if count == 0 {
15
+ return "no-record", err
16
+ } else if err != nil {
17
+ return "query-error", err
18
+ } else {
19
+ return "ok", err
20
+ }
21
+ }
22
+
23
+ func DiffTime(t1 time.Time, t2 time.Time) (int, int, int) {
24
+ hs := t1.Sub(t2).Hours()
25
+ hs, mf := math.Modf(hs)
26
+ ms := mf * 60
27
+ ms, sf := math.Modf(ms)
28
+ ss := sf * 60
29
+ return int(hs), int(ms), int(ss)
30
+ }
space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/response_middleware.go ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package middleware
2
+
3
+ import (
4
+ "net/http"
5
+
6
+ "github.com/gin-gonic/gin"
7
+ )
8
+
9
+ // SendJSON200 sends a JSON response with HTTP status code 200
10
+ func SendJSON200(c *gin.Context, data interface{}) {
11
+ c.JSON(http.StatusOK, gin.H{"status": "success", "data": data})
12
+ return
13
+ }
14
+
15
+ // SendJSON400 sends a JSON response with HTTP status code 400
16
+ func SendJSON400(c *gin.Context, error_status *string, message *string) {
17
+ c.JSON(http.StatusBadRequest, gin.H{"status": "error", "error-status": error_status, "message": message})
18
+ return
19
+ }
20
+
21
+ // SendJSON401 sends a JSON response with HTTP status code 401
22
+ func SendJSON401(c *gin.Context, error_status *string, message *string) {
23
+ c.JSON(http.StatusUnauthorized, gin.H{"status": "error", "error-status": error_status, "message": message})
24
+ return
25
+ }
26
+
27
+ // SendJSON403 sends a JSON response with HTTP status code 403
28
+ func SendJSON403(c *gin.Context, message *string) {
29
+ c.JSON(http.StatusForbidden, gin.H{"status": "error", "message": message})
30
+ return
31
+ }
32
+
33
+ // SendJSON404 sends a JSON response with HTTP status code 404
34
+ func SendJSON404(c *gin.Context, message *string) {
35
+ c.JSON(http.StatusNotFound, gin.H{"status": "error", "message": message})
36
+ return
37
+ }
38
+
39
+ // SendJSON500 sends a JSON response with HTTP status code 500
40
+ func SendJSON500(c *gin.Context, error_status *string, message *string) {
41
+ c.JSON(http.StatusInternalServerError, gin.H{"status": "error", "error-status": error_status, "message": message})
42
+ return
43
+ }
44
+
45
+ // JSONResponseMiddleware is a middleware that provides functions for sending JSON responses
space/space/space/space/space/space/space/space/space/space/space/space/space/models/authentication_dto.go ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ package models
2
+
3
+ type LoginRequest struct {
4
+ FingerPrintToken string `json:"email" binding:"required"`
5
+ }
space/space/space/space/space/space/space/space/space/space/space/space/space/models/authentication_payload_model.go ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ package models
2
+
3
+ type AccountData struct {
4
+ UserID int
5
+ VerifyStatus string
6
+ ErrVerif error
7
+ }
space/space/space/space/space/space/space/space/space/space/space/space/space/models/entities_model.go ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package models
2
+
3
+ import (
4
+ "time"
5
+
6
+ uuid "github.com/satori/go.uuid"
7
+ )
8
+
9
+ type Account struct {
10
+ ID uuid.UUID `gorm:"type:uuid;default:uuid_generate_v4();primaryKey"`
11
+ Fingerprint string `gorm:"not null;"`
12
+ CreatedAt time.Time
13
+ DeletedAt *time.Time `gorm:"column:deleted_at"` // perhatikan penamaan kolom
14
+ }
15
+
16
+ type ChatHistory struct {
17
+ ID uuid.UUID `gorm:"type:uuid;default:uuid_generate_v4();primaryKey"`
18
+ ImagePath string `gorm:"type:text"`
19
+ Question string `gorm:"type:text"`
20
+ Answer string `gorm:"type:text"`
21
+ CreatedAt time.Time `gorm:"column:created_at"`
22
+ DeletedAt *time.Time `gorm:"column:deleted_at"`
23
+ }
24
+
25
+ // Gorm table name settings
26
+ func (Account) TableName() string { return "account" }
27
+ func (ChatHistory) TableName() string { return "chat_history" }
space/space/space/space/space/space/space/space/space/space/space/space/space/models/exception_model.go ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package models
2
+
3
+ type Exception struct {
4
+ Unauthorized bool `json:"unauthorized,omitempty"`
5
+ BadRequest bool `json:"bad_request,omitempty"`
6
+ DataNotFound bool `json:"data_not_found,omitempty"`
7
+ InternalServerError bool `json:"internal_server_error,omitempty"`
8
+ DataDuplicate bool `json:"data_duplicate,omitempty"`
9
+ QueryError bool `json:"query_error,omitempty"`
10
+ InvalidPasswordLength bool `json:"invalid_password_length,omitempty"`
11
+ FailedTranscripting bool `json:"failed_transcripting,omitempty"`
12
+ ReplicateConnectionRefused bool `json:"replicated_connection_refused,omitempty"`
13
+ AudioFileError bool `json:"audio_file_error,omitempty"`
14
+ FailedGenerateAudio bool `json:"audio_generation_failed,omitempty"`
15
+ Message string `json:"message"`
16
+ }
space/space/space/space/space/space/space/space/space/space/space/space/space/models/http_response_dto_model.go ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package models
2
+
3
+ type SuccessResponse struct {
4
+ Status string `json:"status"`
5
+ Message string `json:"message"`
6
+ Data any `json:"data"`
7
+ MetaData any `json:"meta_data"`
8
+ }
9
+
10
+ type ErrorResponse struct {
11
+ Status string `json:"status"`
12
+ Message string `json:"message"`
13
+ Errors Exception `json:"errors"`
14
+ MetaData any `json:"meta_data"`
15
+ }