-
Notifications
You must be signed in to change notification settings - Fork 6
add ModelzClient.create_completion classmethod #24
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
Open
tddschn
wants to merge
1
commit into
tensorchord:main
Choose a base branch
from
tddschn:openai-like-create-completion-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
||
|
|
@@ -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 | ||
| 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
Member
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. 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
Member
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. If so, why not use |
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Any reason to create the class method?