fix
This commit is contained in:
@@ -6,7 +6,7 @@ COPY go.mod go.sum ./
|
|||||||
RUN go env -w GO111MODULE=on
|
RUN go env -w GO111MODULE=on
|
||||||
RUN go env -w GOPROXY=https://goproxy.cn,direct
|
RUN go env -w GOPROXY=https://goproxy.cn,direct
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
COPY main.go .env ./
|
COPY main.go ./
|
||||||
|
|
||||||
RUN go build -o api
|
RUN go build -o api
|
||||||
|
|
||||||
|
|||||||
11
main.go
11
main.go
@@ -12,7 +12,6 @@ import (
|
|||||||
"github.com/gin-contrib/cors"
|
"github.com/gin-contrib/cors"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/glebarez/sqlite"
|
"github.com/glebarez/sqlite"
|
||||||
"github.com/joho/godotenv"
|
|
||||||
"github.com/openai/openai-go/v2"
|
"github.com/openai/openai-go/v2"
|
||||||
"github.com/openai/openai-go/v2/option"
|
"github.com/openai/openai-go/v2/option"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
@@ -31,11 +30,6 @@ type PresetCodeInput struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := godotenv.Load()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
db, err := gorm.Open(sqlite.Open("database.db"), &gorm.Config{})
|
db, err := gorm.Open(sqlite.Open("database.db"), &gorm.Config{})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -113,9 +107,8 @@ func main() {
|
|||||||
systemPrompt := "你是编程老师,擅长分析代码和错误信息,一般出错在语法和格式,请指出错误在第几行,并给出中文的、简要的解决方法。用 markdown 格式返回。"
|
systemPrompt := "你是编程老师,擅长分析代码和错误信息,一般出错在语法和格式,请指出错误在第几行,并给出中文的、简要的解决方法。用 markdown 格式返回。"
|
||||||
userPrompt := fmt.Sprintf("编程语言:%s\n代码:\n```%s\n```\n错误信息:\n```%s\n```", payload.Language, payload.Code, payload.ErrorInfo)
|
userPrompt := fmt.Sprintf("编程语言:%s\n代码:\n```%s\n```\n错误信息:\n```%s\n```", payload.Language, payload.Code, payload.ErrorInfo)
|
||||||
|
|
||||||
apiKey := os.Getenv("API_KEY")
|
apiKey, ok := os.LookupEnv("API_KEY")
|
||||||
|
if !ok || apiKey == "" {
|
||||||
if apiKey == "" {
|
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": "API_KEY is not set"})
|
c.JSON(http.StatusBadRequest, gin.H{"error": "API_KEY is not set"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user