mirror of
https://github.com/mudler/LocalAI.git
synced 2026-06-11 02:07:27 -04:00
Add an opt-in `local-ai chat` command for testing chat models directly from the terminal without manually sending curl requests. The command connects to a running LocalAI server, lists available models through the existing OpenAI-compatible API, streams chat completions, and supports interactive commands such as `/models`, `/model`, `/clear`, and `/exit`. Keep `local-ai run` focused on the server lifecycle so the web UI, API clients, and multiple chat terminals can coexist against the same server. Document the new command and terminal workflow in the README and CLI docs. Tests: - go test -count=1 ./core/cli/chat - go test -count=1 ./core/cli Assisted-by: Codex:GPT-5 Signed-off-by: Ching Kao <0980124jim@gmail.com>
26 lines
833 B
Go
26 lines
833 B
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
|
|
chatcli "github.com/mudler/LocalAI/core/cli/chat"
|
|
cliContext "github.com/mudler/LocalAI/core/cli/context"
|
|
)
|
|
|
|
type ChatCMD struct {
|
|
Model string `short:"m" help:"Model name to use. Defaults to the only model returned by the server when exactly one is available"`
|
|
Endpoint string `env:"LOCALAI_CHAT_ENDPOINT" default:"http://127.0.0.1:8080" help:"LocalAI server endpoint. The /v1 path is added automatically when omitted"`
|
|
APIKey string `env:"LOCALAI_API_KEY,API_KEY" help:"API key to use when the LocalAI server requires authentication"`
|
|
}
|
|
|
|
func (c *ChatCMD) Run(ctx *cliContext.Context) error {
|
|
return chatcli.Run(context.Background(), chatcli.Options{
|
|
Model: c.Model,
|
|
BaseURL: chatAPIBaseURL(c.Endpoint),
|
|
APIKey: c.APIKey,
|
|
In: os.Stdin,
|
|
Out: os.Stdout,
|
|
})
|
|
}
|