Skip to content

Commit fbec474

Browse files
authored
Merge pull request #1706 from rhatdan/chat
Consolodate run and chat commands together also allow specification of prefix in ramalama.conf
2 parents 3af4c75 + 2abb464 commit fbec474

File tree

5 files changed

+49
-27
lines changed

5 files changed

+49
-27
lines changed

docs/ramalama.conf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@
7777
#
7878
#port = "8080"
7979

80+
# Specify default prefix for chat and run command. By default the prefix
81+
# is based on the container engine used.
82+
# Podman: "🦭 > "
83+
# Docker: "🐋 > "
84+
# No Engine: "🦙 > "
85+
# No IMOGI support: "> "
86+
#
87+
#
88+
#prefix = ""
89+
8090
# Specify default pull policy for OCI Images
8191
#
8292
# **always**: Always pull the image and throw an error if the pull fails.

docs/ramalama.conf.5.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,17 @@ In some cases this is needed to access the gpu from a rootless container
119119
number of gpu layers, 0 means CPU inferencing, 999 means use max layers (default: -1)
120120
The default -1, means use whatever is automatically deemed appropriate (0 or 999)
121121

122+
**prefix**=""
123+
Specify default prefix for chat and run command. By default the prefix
124+
is based on the container engine used.
125+
126+
| Container Engine| Prefix |
127+
| --------------- | ------- |
128+
| Podman | "🦭 > " |
129+
| Docker | "🐋 > " |
130+
| No Engine | "🦙 > " |
131+
| No EMOJI support| "> " |
132+
122133
**port**="8080"
123134

124135
Specify default port for services to listen on

ramalama/chat.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ def default_prefix():
5252
if not EMOJI:
5353
return "> "
5454

55+
if CONFIG.prefix:
56+
return CONFIG.prefix
57+
5558
engine = CONFIG.engine
5659

5760
if engine:

ramalama/cli.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ def runtime_options(parser, command):
852852
choices=["always", "missing", "never", "newer"],
853853
help='pull image policy',
854854
)
855-
if command in ["run", "serve"]:
855+
if command in ["serve"]:
856856
parser.add_argument(
857857
"--rag", help="RAG vector database or OCI Image to be served with the model", completer=local_models
858858
)
@@ -921,6 +921,18 @@ def default_threads():
921921
return CONFIG.threads
922922

923923

924+
def chat_run_options(parser):
925+
parser.add_argument(
926+
'--color',
927+
'--colour',
928+
default="auto",
929+
choices=get_args(COLOR_OPTIONS),
930+
help='possible values are "never", "always" and "auto".',
931+
)
932+
parser.add_argument("--prefix", type=str, help="prefix for the user prompt", default=default_prefix())
933+
parser.add_argument("--rag", type=str, help="a file or directory to use as context for the chat")
934+
935+
924936
def chat_parser(subparsers):
925937
parser = subparsers.add_parser("chat", help="OpenAI chat with the specified RESTAPI URL")
926938
parser.add_argument(
@@ -929,21 +941,13 @@ def chat_parser(subparsers):
929941
default=os.getenv("API_KEY"),
930942
help="OpenAI-compatible API key. Can also be set via the API_KEY environment variable.",
931943
)
932-
parser.add_argument(
933-
'--color',
934-
'--colour',
935-
default="auto",
936-
choices=get_args(COLOR_OPTIONS),
937-
help='possible values are "never", "always" and "auto".',
938-
)
944+
chat_run_options(parser)
939945
parser.add_argument(
940946
"--list",
941947
"--ls",
942948
action="store_true",
943949
help="list the available models at an endpoint",
944950
)
945-
parser.add_argument("--prefix", type=str, help="prefix for the user prompt", default=default_prefix())
946-
parser.add_argument("--rag", type=str, help="a file or directory to use as context for the chat")
947951
parser.add_argument("--url", type=str, default="http://127.0.0.1:8080/v1", help="the url to send requests to")
948952
parser.add_argument("--model", "-m", type=str, completer=local_models, help="model for inferencing")
949953
parser.add_argument(
@@ -955,14 +959,7 @@ def chat_parser(subparsers):
955959
def run_parser(subparsers):
956960
parser = subparsers.add_parser("run", help="run specified AI Model as a chatbot")
957961
runtime_options(parser, "run")
958-
parser.add_argument(
959-
'--color',
960-
'--colour',
961-
default="auto",
962-
choices=get_args(COLOR_OPTIONS),
963-
help='possible values are "never", "always" and "auto".',
964-
)
965-
parser.add_argument("--prefix", type=str, help="prefix for the user prompt", default=default_prefix())
962+
chat_run_options(parser)
966963
parser.add_argument("MODEL", completer=local_models) # positional argument
967964

968965
parser.add_argument(

ramalama/config.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,16 @@ class RamalamaSettings:
6565

6666
@dataclass
6767
class BaseConfig:
68-
container: bool = None # type: ignore
69-
image: str = None # type: ignore
68+
api: str = "none"
7069
carimage: str = "registry.access.redhat.com/ubi10-micro:latest"
70+
container: bool = None # type: ignore
7171
ctx_size: int = 2048
72+
default_image: str = DEFAULT_IMAGE
73+
dryrun: bool = False
7274
engine: SUPPORTED_ENGINES | None = field(default_factory=get_default_engine)
7375
env: list[str] = field(default_factory=list)
7476
host: str = "0.0.0.0"
77+
image: str = None # type: ignore
7578
images: dict[str, str] = field(
7679
default_factory=lambda: {
7780
"ASAHI_VISIBLE_DEVICES": "quay.io/ramalama/asahi",
@@ -83,23 +86,21 @@ class BaseConfig:
8386
"MUSA_VISIBLE_DEVICES": "quay.io/ramalama/musa",
8487
}
8588
)
86-
api: str = "none"
8789
keep_groups: bool = False
8890
ngl: int = -1
89-
threads: int = -1
91+
ocr: bool = False
9092
port: str = str(DEFAULT_PORT)
93+
prefix: str = None # type: ignore
9194
pull: str = "newer"
9295
rag_format: Literal["qdrant", "json", "markdown", "milvus"] = "qdrant"
9396
runtime: SUPPORTED_RUNTIMES = "llama.cpp"
97+
selinux: bool = False
98+
settings: RamalamaSettings = field(default_factory=RamalamaSettings)
9499
store: str = field(default_factory=get_default_store)
95100
temp: str = "0.8"
101+
threads: int = -1
96102
transport: str = "ollama"
97-
ocr: bool = False
98-
default_image: str = DEFAULT_IMAGE
99103
user: UserConfig = field(default_factory=UserConfig)
100-
selinux: bool = False
101-
dryrun: bool = False
102-
settings: RamalamaSettings = field(default_factory=RamalamaSettings)
103104

104105
def __post_init__(self):
105106
self.container = coerce_to_bool(self.container) if self.container is not None else self.engine is not None

0 commit comments

Comments
 (0)