Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion modelz/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import annotations
from typing import Any, Generator
from typing import Any, Dict, Generator
from http import HTTPStatus
from urllib.parse import urljoin

Expand Down Expand Up @@ -131,3 +131,45 @@ def build(self, repo: str):

ModelzResponse(resp)
console.print(f"created the build job for repo [bold cyan]{repo}[/bold cyan]")

@classmethod
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to create the class method?

def create_completion(
cls,
deployment: str,
model: str,
prompt: str,
params: Dict[str, Any] | None = None,
serde: str = "json",
):
"""Create a completion using the model.

Args:
deployment: deployment ID
prompt: The prompt to use for the completion.
params: additional request params, will be serialized by `serde`
serde: serialize/deserialize method, choose from ("json", "msg", "raw")
"""
# Create an instance of the class.
client = cls(deployment=deployment)

try:
from llmspec import LLMSpec

# Instantiate LLMSpec and transform the prompt
llmspec = LLMSpec(prompt)
transformed_prompt = llmspec.to_model(model)
except ImportError as err:
raise ImportError(
"llmspec is required for LLM models"
"\nPlease install it with the command `pip install llmspec"
) from err
Comment on lines +155 to +165
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will publish it later.


# Prepare request params
request_params = {"prompt": transformed_prompt}
if params:
request_params.update(params)

# Get the inference result
response = client.inference(request_params, deployment, serde)

return response
Comment on lines +167 to +175
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If so, why not use client.inference directly? Why do we need a new function?