Skip to content

Commit 8862d12

Browse files
committed
Make model argument mandatory
To be consistent with "ramalama run" experience. Inferencing servers that have implemented model-swapping require this. Signed-off-by: Eric Curtin <[email protected]>
1 parent aa29aa6 commit 8862d12

File tree

2 files changed

+2
-17
lines changed

2 files changed

+2
-17
lines changed

ramalama/chat.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,6 @@ def __init__(self, args):
7272

7373
self.url = f"{args.url}/v1/chat/completions"
7474
self.models_url = f"{args.url}/v1/models"
75-
self.models = []
76-
77-
def model(self, index=0):
78-
try:
79-
if len(self.models) == 0:
80-
self.models = self.get_models()
81-
return self.models[index]
82-
except urllib.error.URLError:
83-
return ""
84-
85-
def get_models(self):
86-
request = urllib.request.Request(self.models_url, method="GET")
87-
response = urllib.request.urlopen(request)
88-
for line in response:
89-
line = line.decode("utf-8").strip()
90-
return [d['id'] for d in json.loads(line)["data"]]
9175

9276
def handle_args(self):
9377
if self.args.ARGS:
@@ -117,7 +101,7 @@ def _make_request_data(self):
117101
data = {
118102
"stream": True,
119103
"messages": self.conversation_history,
120-
"model": self.model(),
104+
"model": self.args.MODEL,
121105
}
122106
json_data = json.dumps(data).encode("utf-8")
123107
headers = {

ramalama/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,7 @@ def chat_parser(subparsers):
921921
)
922922
parser.add_argument("--prefix", type=str, help="prefix for the user prompt", default=default_prefix())
923923
parser.add_argument("--url", type=str, default="http://127.0.0.1:8080", help="the host to send requests to")
924+
parser.add_argument("MODEL", completer=local_models) # positional argument
924925
parser.add_argument(
925926
"ARGS", nargs="*", help="overrides the default prompt, and the output is returned without entering the chatbot"
926927
)

0 commit comments

Comments
 (0)