-
Notifications
You must be signed in to change notification settings - Fork 365
feat: add support for specifying model alias used in requests and responses #2615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
b34d49b
567316f
50853fb
d20e513
9537d05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| ####> This option file is used in: | ||
| ####> ramalama sandbox goose, ramalama sandbox opencode, ramalama serve | ||
| ####> If this file is edited, make sure the changes | ||
| ####> are applicable to all of those. | ||
| #### **--alias** | ||
| Model name alias (referenced in the requests and responses of the API). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -505,7 +505,7 @@ def _connect_and_chat(self, args, server_process): | |
|
|
||
| # Model name in the chat request must match RamalamaModelContext.alias() | ||
| chat_args = copy.deepcopy(args) | ||
| chat_args.model = f"{self.model_organization}/{self.model_name}" | ||
| chat_args.model = getattr(args, 'alias', None) or self.model_alias | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Normalize multi-alias input before setting chat model ID. Line 502 forwards 💡 Proposed fix- chat_args.model = getattr(args, 'alias', None) or self.model_alias
+ alias = getattr(args, "alias", None)
+ if isinstance(alias, str) and getattr(args, "runtime", "") == "llama.cpp" and "," in alias:
+ alias = alias.split(",", 1)[0].strip()
+ chat_args.model = alias or self.model_alias🤖 Prompt for AI Agents
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Valid-ish; issue is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That said, your concern about Two options worth considering:
Would you like to open a follow-up issue for this, or apply option 2 here?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @CodeRabbit runtimes are plugins, you must not place runtime specific conditionals in the core modules There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The only valid fix here would be the runtime-agnostic approach: always normalize the alias by taking the first comma-separated token, since no runtime registers a comma-joined string as a valid model name: alias = getattr(args, "alias", None)
if alias and "," in alias:
alias = alias.split(",", 1)[0].strip()
chat_args.model = alias or self.model_aliasGiven Christopher-Chianelli's note that this field doesn't appear to affect current tests, I'd suggest applying this normalization here or tracking it as a follow-up issue. Would you like me to open a follow-up issue for this? (ᵔ◡ᔸ)🐇 Noted — keeping the core clean of plugin concerns. ✏️ Learnings added
🧠 Learnings used
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's fine to pass the value through to llama.cpp/vllm verbatim There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
olliewalsh marked this conversation as resolved.
|
||
|
|
||
| if args.container: | ||
| return self._handle_container_chat(chat_args, server_process) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
| from subprocess import STDOUT, CalledProcessError | ||
|
|
||
| import pytest | ||
| import requests | ||
| import yaml | ||
|
|
||
| from test.conftest import ( | ||
|
|
@@ -336,6 +337,27 @@ def test_serve_and_stop(shared_ctx, test_model): | |
| assert not re.search(f".*({container1_id}|{container2_id})", ps_result) | ||
|
|
||
|
|
||
| @pytest.mark.e2e | ||
| @pytest.mark.slow | ||
| @skip_if_no_container | ||
| def test_serve_model_with_alias(shared_ctx, test_model): | ||
| container_id = f"serve_with_alias_{''.join(random.choices(string.ascii_letters + string.digits, k=5))}" | ||
| alias = "my_alias" | ||
| ctx = shared_ctx | ||
| serve_cmd = ["ramalama", "serve", "--name", container_id, "--alias", alias, "--detach", test_model] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The unit tests already cover the llama-server cli. Could unit tests cover the model name used in the chat http requests too? If so then I don't think an expensive e2e test is really necessary.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a unit test for the model name in http requests: https://github.com/Christopher-Chianelli/ramalama/blob/54afab654a65c11ae9633b3cb457a05ea7d8dd7a/test/unit/test_engine.py#L193-L210 ; This e2e is more so to check |
||
| ctx.check_call(serve_cmd) | ||
| try: | ||
| ps_list = ctx.check_output(["ramalama", "ps", "--format", "{{.Names}} {{.Ports}}"]) | ||
| port = re.search(rf"{container_id}.*->(?P<port>\d+)", ps_list)["port"] | ||
| # FIXME: race-condition, chat can fail to connect if llama.cpp isn't ready, just sleep a little for now | ||
| time.sleep(10) | ||
| models = requests.get(f"http://127.0.0.1:{port}/v1/models").json() | ||
| assert models["models"][0]["name"] == alias | ||
| assert models["models"][0]["model"] == alias | ||
| finally: | ||
| ctx.check_call(["ramalama", "stop", container_id]) | ||
|
|
||
|
|
||
| @pytest.mark.e2e | ||
| @pytest.mark.slow | ||
| @skip_if_no_container | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't seem relevant to this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It a note for when a future developer wants to add an arg specific to
serveandrun; it would of helped me realize where to put the parser code!