fix(openai): Populate ID and Created fields in OpenAI compatible responses (#1164)

Adding the extra ID and Created fields to any request to the OpenAI
Compatible API to improve the compatibility.

This PR fixes #1103
This commit is contained in:
Jesús Espino 2023-10-12 04:00:08 +02:00 committed by GitHub
parent 528b9d9206
commit 81a5ed9f31
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 50 additions and 8 deletions

View file

@ -5,11 +5,14 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"github.com/go-skynet/LocalAI/api/schema"
"os"
"path/filepath"
"strconv"
"strings"
"time"
"github.com/go-skynet/LocalAI/api/schema"
"github.com/google/uuid"
"github.com/go-skynet/LocalAI/api/backend"
config "github.com/go-skynet/LocalAI/api/config"
@ -174,8 +177,12 @@ func ImageEndpoint(cm *config.ConfigLoader, o *options.Option) func(c *fiber.Ctx
}
}
id := uuid.New().String()
created := int(time.Now().Unix())
resp := &schema.OpenAIResponse{
Data: result,
ID: id,
Created: created,
Data: result,
}
jsonResult, _ := json.Marshal(resp)