2024-04-20 23:19:57 +00:00
|
|
|
package routes
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gofiber/fiber/v2"
|
2024-06-23 08:24:36 +00:00
|
|
|
"github.com/mudler/LocalAI/core/config"
|
|
|
|
"github.com/mudler/LocalAI/core/http/endpoints/localai"
|
|
|
|
"github.com/mudler/LocalAI/core/http/endpoints/openai"
|
|
|
|
"github.com/mudler/LocalAI/pkg/model"
|
2024-04-20 23:19:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func RegisterOpenAIRoutes(app *fiber.App,
|
|
|
|
cl *config.BackendConfigLoader,
|
|
|
|
ml *model.ModelLoader,
|
2024-09-17 03:29:07 +00:00
|
|
|
appConfig *config.ApplicationConfig) {
|
2024-04-20 23:19:57 +00:00
|
|
|
// openAI compatible API endpoint
|
|
|
|
|
|
|
|
// chat
|
2024-09-17 03:29:07 +00:00
|
|
|
app.Post("/v1/chat/completions", openai.ChatEndpoint(cl, ml, appConfig))
|
|
|
|
app.Post("/chat/completions", openai.ChatEndpoint(cl, ml, appConfig))
|
2024-04-20 23:19:57 +00:00
|
|
|
|
|
|
|
// edit
|
2024-09-17 03:29:07 +00:00
|
|
|
app.Post("/v1/edits", openai.EditEndpoint(cl, ml, appConfig))
|
|
|
|
app.Post("/edits", openai.EditEndpoint(cl, ml, appConfig))
|
2024-04-20 23:19:57 +00:00
|
|
|
|
|
|
|
// assistant
|
2024-09-17 03:29:07 +00:00
|
|
|
app.Get("/v1/assistants", openai.ListAssistantsEndpoint(cl, ml, appConfig))
|
|
|
|
app.Get("/assistants", openai.ListAssistantsEndpoint(cl, ml, appConfig))
|
|
|
|
app.Post("/v1/assistants", openai.CreateAssistantEndpoint(cl, ml, appConfig))
|
|
|
|
app.Post("/assistants", openai.CreateAssistantEndpoint(cl, ml, appConfig))
|
|
|
|
app.Delete("/v1/assistants/:assistant_id", openai.DeleteAssistantEndpoint(cl, ml, appConfig))
|
|
|
|
app.Delete("/assistants/:assistant_id", openai.DeleteAssistantEndpoint(cl, ml, appConfig))
|
|
|
|
app.Get("/v1/assistants/:assistant_id", openai.GetAssistantEndpoint(cl, ml, appConfig))
|
|
|
|
app.Get("/assistants/:assistant_id", openai.GetAssistantEndpoint(cl, ml, appConfig))
|
|
|
|
app.Post("/v1/assistants/:assistant_id", openai.ModifyAssistantEndpoint(cl, ml, appConfig))
|
|
|
|
app.Post("/assistants/:assistant_id", openai.ModifyAssistantEndpoint(cl, ml, appConfig))
|
|
|
|
app.Get("/v1/assistants/:assistant_id/files", openai.ListAssistantFilesEndpoint(cl, ml, appConfig))
|
|
|
|
app.Get("/assistants/:assistant_id/files", openai.ListAssistantFilesEndpoint(cl, ml, appConfig))
|
|
|
|
app.Post("/v1/assistants/:assistant_id/files", openai.CreateAssistantFileEndpoint(cl, ml, appConfig))
|
|
|
|
app.Post("/assistants/:assistant_id/files", openai.CreateAssistantFileEndpoint(cl, ml, appConfig))
|
|
|
|
app.Delete("/v1/assistants/:assistant_id/files/:file_id", openai.DeleteAssistantFileEndpoint(cl, ml, appConfig))
|
|
|
|
app.Delete("/assistants/:assistant_id/files/:file_id", openai.DeleteAssistantFileEndpoint(cl, ml, appConfig))
|
|
|
|
app.Get("/v1/assistants/:assistant_id/files/:file_id", openai.GetAssistantFileEndpoint(cl, ml, appConfig))
|
|
|
|
app.Get("/assistants/:assistant_id/files/:file_id", openai.GetAssistantFileEndpoint(cl, ml, appConfig))
|
2024-04-20 23:19:57 +00:00
|
|
|
|
|
|
|
// files
|
2024-09-17 03:29:07 +00:00
|
|
|
app.Post("/v1/files", openai.UploadFilesEndpoint(cl, appConfig))
|
|
|
|
app.Post("/files", openai.UploadFilesEndpoint(cl, appConfig))
|
|
|
|
app.Get("/v1/files", openai.ListFilesEndpoint(cl, appConfig))
|
|
|
|
app.Get("/files", openai.ListFilesEndpoint(cl, appConfig))
|
|
|
|
app.Get("/v1/files/:file_id", openai.GetFilesEndpoint(cl, appConfig))
|
|
|
|
app.Get("/files/:file_id", openai.GetFilesEndpoint(cl, appConfig))
|
|
|
|
app.Delete("/v1/files/:file_id", openai.DeleteFilesEndpoint(cl, appConfig))
|
|
|
|
app.Delete("/files/:file_id", openai.DeleteFilesEndpoint(cl, appConfig))
|
|
|
|
app.Get("/v1/files/:file_id/content", openai.GetFilesContentsEndpoint(cl, appConfig))
|
|
|
|
app.Get("/files/:file_id/content", openai.GetFilesContentsEndpoint(cl, appConfig))
|
2024-04-20 23:19:57 +00:00
|
|
|
|
|
|
|
// completion
|
2024-09-17 03:29:07 +00:00
|
|
|
app.Post("/v1/completions", openai.CompletionEndpoint(cl, ml, appConfig))
|
|
|
|
app.Post("/completions", openai.CompletionEndpoint(cl, ml, appConfig))
|
|
|
|
app.Post("/v1/engines/:model/completions", openai.CompletionEndpoint(cl, ml, appConfig))
|
2024-04-20 23:19:57 +00:00
|
|
|
|
|
|
|
// embeddings
|
2024-09-17 03:29:07 +00:00
|
|
|
app.Post("/v1/embeddings", openai.EmbeddingsEndpoint(cl, ml, appConfig))
|
|
|
|
app.Post("/embeddings", openai.EmbeddingsEndpoint(cl, ml, appConfig))
|
|
|
|
app.Post("/v1/engines/:model/embeddings", openai.EmbeddingsEndpoint(cl, ml, appConfig))
|
2024-04-20 23:19:57 +00:00
|
|
|
|
|
|
|
// audio
|
2024-09-17 03:29:07 +00:00
|
|
|
app.Post("/v1/audio/transcriptions", openai.TranscriptEndpoint(cl, ml, appConfig))
|
|
|
|
app.Post("/v1/audio/speech", localai.TTSEndpoint(cl, ml, appConfig))
|
2024-04-20 23:19:57 +00:00
|
|
|
|
|
|
|
// images
|
2024-09-17 03:29:07 +00:00
|
|
|
app.Post("/v1/images/generations", openai.ImageEndpoint(cl, ml, appConfig))
|
2024-04-20 23:19:57 +00:00
|
|
|
|
|
|
|
if appConfig.ImageDir != "" {
|
|
|
|
app.Static("/generated-images", appConfig.ImageDir)
|
|
|
|
}
|
|
|
|
|
|
|
|
if appConfig.AudioDir != "" {
|
|
|
|
app.Static("/generated-audio", appConfig.AudioDir)
|
|
|
|
}
|
|
|
|
|
2024-07-10 13:28:39 +00:00
|
|
|
// List models
|
2024-09-17 03:29:07 +00:00
|
|
|
app.Get("/v1/models", openai.ListModelsEndpoint(cl, ml))
|
|
|
|
app.Get("/models", openai.ListModelsEndpoint(cl, ml))
|
2024-04-20 23:19:57 +00:00
|
|
|
}
|