mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-21 19:15:00 +00:00
Small fixups
This commit is contained in:
parent
78ef045bb3
commit
5ce57206e3
3 changed files with 14 additions and 10 deletions
|
@ -27,7 +27,7 @@ func readInput(c *fiber.Ctx, o *options.Option, randomModel bool) (string, *sche
|
||||||
input.Cancel = cancel
|
input.Cancel = cancel
|
||||||
// Get input data from the request body
|
// Get input data from the request body
|
||||||
if err := c.BodyParser(input); err != nil {
|
if err := c.BodyParser(input); err != nil {
|
||||||
return "", nil, err
|
return "", nil, fmt.Errorf("failed parsing request body: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
modelFile := input.Model
|
modelFile := input.Model
|
||||||
|
@ -165,7 +165,7 @@ func updateConfig(config *config.Config, input *schema.OpenAIRequest) {
|
||||||
|
|
||||||
// Decode each request's message content
|
// Decode each request's message content
|
||||||
index := 0
|
index := 0
|
||||||
for _, m := range input.Messages {
|
for i, m := range input.Messages {
|
||||||
switch content := m.Content.(type) {
|
switch content := m.Content.(type) {
|
||||||
case string:
|
case string:
|
||||||
m.StringContent = content
|
m.StringContent = content
|
||||||
|
@ -175,14 +175,14 @@ func updateConfig(config *config.Config, input *schema.OpenAIRequest) {
|
||||||
json.Unmarshal(dat, &c)
|
json.Unmarshal(dat, &c)
|
||||||
for _, pp := range c {
|
for _, pp := range c {
|
||||||
if pp.Type == "text" {
|
if pp.Type == "text" {
|
||||||
m.StringContent = pp.Text
|
input.Messages[i].StringContent = pp.Text
|
||||||
} else if pp.Type == "image_url" {
|
} else if pp.Type == "image_url" {
|
||||||
// Detect if pp.ImageURL is an URL, if it is download the image and encode it in base64:
|
// Detect if pp.ImageURL is an URL, if it is download the image and encode it in base64:
|
||||||
base64, err := getBase64Image(pp.ImageURL)
|
base64, err := getBase64Image(pp.ImageURL.URL)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
m.StringImages = append(m.StringImages, base64) // TODO: make sure that we only return base64 stuff
|
input.Messages[i].StringImages = append(input.Messages[i].StringImages, base64) // TODO: make sure that we only return base64 stuff
|
||||||
// set a placeholder for each image
|
// set a placeholder for each image
|
||||||
m.StringContent = m.StringContent + fmt.Sprintf("[img-%d]", index)
|
input.Messages[i].StringContent = input.Messages[i].StringContent + fmt.Sprintf("[img-%d]", index)
|
||||||
index++
|
index++
|
||||||
} else {
|
} else {
|
||||||
fmt.Print("Failed encoding image", err)
|
fmt.Print("Failed encoding image", err)
|
||||||
|
|
|
@ -56,9 +56,13 @@ type Choice struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Content struct {
|
type Content struct {
|
||||||
Type string `json:"type" yaml:"type"`
|
Type string `json:"type" yaml:"type"`
|
||||||
Text string `json:"text" yaml:"text"`
|
Text string `json:"text" yaml:"text"`
|
||||||
ImageURL string `json:"image_url" yaml:"image_url"`
|
ImageURL ContentURL `json:"image_url" yaml:"image_url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ContentURL struct {
|
||||||
|
URL string `json:"url" yaml:"url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Message struct {
|
type Message struct {
|
||||||
|
|
|
@ -1974,7 +1974,7 @@ static void params_parse(const backend::ModelOptions* request,
|
||||||
if (!request->mmproj().empty()) {
|
if (!request->mmproj().empty()) {
|
||||||
// get the directory of modelfile
|
// get the directory of modelfile
|
||||||
std::string model_dir = params.model.substr(0, params.model.find_last_of("/\\"));
|
std::string model_dir = params.model.substr(0, params.model.find_last_of("/\\"));
|
||||||
params.mmproj = model_dir + request->mmproj();
|
params.mmproj = model_dir + "/"+ request->mmproj();
|
||||||
}
|
}
|
||||||
// params.model_alias ??
|
// params.model_alias ??
|
||||||
params.model_alias = request->modelfile();
|
params.model_alias = request->modelfile();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue