Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
development to staging(#109)
Browse files Browse the repository at this point in the history
Development to staging
  • Loading branch information
AriefLazuardi authored Dec 14, 2023
2 parents 188df18 + 2870017 commit d219987
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 11 deletions.
9 changes: 7 additions & 2 deletions handler/productHandler.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package handler

import (
"fmt"
"net/http"
"os"
"qbills/models/web"
Expand Down Expand Up @@ -308,19 +309,23 @@ func (c *ProductHandlerImpl) GetProductNames(ctx echo.Context) (map[uint]helpers
}

func (c *ProductHandlerImpl) ProductAIHandler(ctx echo.Context) error {
input := ctx.FormValue("input")
if input == "" {
return ctx.JSON(http.StatusBadRequest, helpers.ErrorResponse("input cannot be empty"))
}
openAIKey := os.Getenv("OPEN_AI_KEY")
productMap, err := c.GetProductNames(ctx)
if err != nil {
return ctx.JSON(http.StatusInternalServerError, helpers.ErrorResponse("Error getting product names"))
}

result, err := helpers.ProductAI(productMap, openAIKey)

result, err := helpers.ProductAI(productMap, openAIKey, input)
if err != nil {
log.Error("Error calling ProductAI:", err)
return ctx.JSON(http.StatusInternalServerError, helpers.ErrorResponse("Error getting product recommendation"))
}

log.Info("ProductAI Result:", result)

return ctx.JSON(http.StatusOK, helpers.SuccessResponse("success get product recommendation", result))
}
Expand Down
4 changes: 4 additions & 0 deletions models/web/productRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ type ProductUpdateRequest struct {
Ingredients string `json:"ingredients"`
Image string `json:"image"`
ProductDetail domain.ProductDetail `json:"productDetail"`
}

type ProductRecommendRequest struct {
Input string `json:"input" validate:"required"`
}
2 changes: 0 additions & 2 deletions repository/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ func (repository *TransactionRepositoryImpl) FindByInvoice(invoice string) (*dom
}
func (repository *TransactionRepositoryImpl) FindByStatus(invoice, status string) (*domain.Transaction, error) {
transaction := domain.Transaction{}
fmt.Println(invoice, status)
result := repository.DB.
Preload("Cashier").
Preload("Membership").
Expand All @@ -183,7 +182,6 @@ func (repository *TransactionRepositoryImpl) FindByStatus(invoice, status string
if result.Error != nil {
return nil, result.Error
}
fmt.Println("adada", transaction)
return &transaction, nil
}

Expand Down
2 changes: 1 addition & 1 deletion routes/productRoutes.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ func ProductRoutes(e *echo.Echo, db *gorm.DB, validate *validator.Validate) {
productGroup.GET("/category/:productTypeId", ProductHandler.GetProductByCategoryHandler)
productGroup.PUT("/:id", ProductHandler.UpdateProductHandler)
productGroup.DELETE("/:id", ProductHandler.DeleteProductHandler)
productGroup.GET("/recommendation", ProductHandler.ProductAIHandler)
productGroup.POST("/recommendation", ProductHandler.ProductAIHandler)
productGroup.GET("s/best", ProductHandler.GetBestProductsHandler)
}
1 change: 0 additions & 1 deletion services/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,6 @@ func (service *TransactionImpl) CreateInvoice(paymentMethod, paymentType uint) (
currentTimeString := strconv.FormatInt(currentTime, 10)
invoiceNumber := rand.Intn(999) + 1000
invoiceNumberString := strconv.Itoa(invoiceNumber)
fmt.Println(paymentType)
switch paymentType {
case 1:
method = "CASH"
Expand Down
13 changes: 8 additions & 5 deletions utils/helpers/productAI.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

type ProductsAI interface {
ProductAI(productMap, openAIKey string) (string, error)
ProductAI(productMap, openAIKey, userInput string) (string, error)
}

type ProductAIImpl struct {
Expand All @@ -22,22 +22,25 @@ type ProductDataAIRecommended struct {
Ingredients string `json:"ingredients"`
}

func ProductAI(productMap map[uint]ProductDataAIRecommended, openAIKey string) (string, error) {

func ProductAI(productMap map[uint]ProductDataAIRecommended, openAIKey, userInput string) (string, error) {
ctx := context.Background()
client := openai.NewClient(openAIKey)
model := openai.GPT3Dot5Turbo

productMapStr := convertMapToString(productMap)

if productMapStr == "" {
return "Product is Empty", nil
}
messages := []openai.ChatCompletionMessage{
{
Role: openai.ChatMessageRoleSystem,
Content: "Anda adalah asisten virtual dalam sistem rekomendasi kafe. Anda adalah orang yang sangat berpengalaman di bidang Anda. Anda akan diminta untuk memberikan rekomendasi terbaik Anda dari semua menu di cafe. Berikan lima rekomendasi terbaik anda jika input meminta makanan maka berikan rekomendasi makanan jika input meminta minuman maka berikan rekomendasi minuman",
Content: "Anda adalah asisten virtual dalam sistem rekomendasi kafe. Anda adalah orang yang sangat berpengalaman di bidang Anda. Anda akan diminta untuk memberikan rekomendasi terbaik Anda dari semua menu di cafe. Berikan lima rekomendasi terbaik anda jika input meminta makanan maka berikan rekomendasi makanan jika input meminta minuman maka berikan rekomendasi minuman berikut ini adalah product dari cafenya" +productMapStr+ "Jika sebelum prompt ini tidak terdapat product yang diberikan maka berikan response product tidak ditemukan",
},

{
Role: openai.ChatMessageRoleUser,
Content: productMapStr,
Content: userInput,
},
}

Expand Down

0 comments on commit d219987

Please sign in to comment.