api-LL3Hack / api /handler.go
Ashad001's picture
try 2.2
59a46e8
raw
history blame contribute delete
563 Bytes
package api
import (
"log"
"net/http"
"os"
"github.com/gin-gonic/gin"
)
func ChatHandler(c *gin.Context) {
var inputData ChatInput
if err := c.ShouldBindJSON(&inputData); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
apiKey := os.Getenv("GROQ_API_KEY")
log.Println("API Key: ", apiKey)
response, err := InvokeChain(apiKey, inputData.UserQuery)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
// response := "Hello, World!"
c.JSON(http.StatusOK, response)
}