瀏覽代碼

allow overriding default generate options

Bruce MacDonald 1 年之前
父節點
當前提交
f5e2e150b8
共有 2 個文件被更改,包括 9 次插入4 次删除
  1. 2 2
      api/types.go
  2. 7 2
      server/routes.go

+ 2 - 2
api/types.go

@@ -33,8 +33,8 @@ type GenerateRequest struct {
 	Model  string `json:"model"`
 	Prompt string `json:"prompt"`
 
-	ModelOptions   `json:"model_opts,omitempty"`
-	PredictOptions `json:"predict_opts,omitempty"`
+	ModelOptions   *ModelOptions   `json:"model_opts,omitempty"`
+	PredictOptions *PredictOptions `json:"predict_opts,omitempty"`
 }
 
 type ModelOptions struct {

+ 7 - 2
server/routes.go

@@ -38,8 +38,13 @@ func cacheDir() string {
 
 func generate(c *gin.Context) {
 	var req api.GenerateRequest
-	req.ModelOptions = api.DefaultModelOptions
-	req.PredictOptions = api.DefaultPredictOptions
+	if req.ModelOptions == nil {
+		req.ModelOptions = &api.DefaultModelOptions
+	}
+
+	if req.PredictOptions == nil {
+		req.PredictOptions = &api.DefaultPredictOptions
+	}
 	if err := c.ShouldBindJSON(&req); err != nil {
 		c.JSON(http.StatusBadRequest, gin.H{"message": err.Error()})
 		return