Skip to content
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

Added API Proxy functionality to API LM #68

Merged
merged 4 commits into from
Sep 23, 2024
Merged
Changes from 2 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
6 changes: 6 additions & 0 deletions llments/lm/base/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def __init__(self, model_name: str) -> None:
def generate(
self,
message: str,
api_base: str | None,
condition: str | None,
do_sample: bool = False,
max_length: int | None = None,
Expand All @@ -61,6 +62,7 @@ def generate(

Args:
message (str): The prompt for generating a response.
api_base (str): The API endpoint to call the model.
condition (str): The conditioning sequence for the output.
If None, the output is not conditioned.
do_sample (bool): Whether to use sampling or greedy decoding.
Expand All @@ -86,6 +88,7 @@ def generate(
temperature = temperature,
max_tokens = max_new_tokens,
n = num_return_sequences,
api_base = api_base,
messages=[{"content": message, "role": "user"}]
)
for choice in response['choices']:
Expand All @@ -96,6 +99,7 @@ def generate(
def chat_generate(
self,
messages: list[str],
api_base: str | None,
condition: str | None,
do_sample: bool = False,
max_length: int | None = None,
Expand All @@ -110,6 +114,7 @@ def chat_generate(

Args:
messages (list): The list of prompts for generating responses.
api_base (str): The API endpoint to call the model.
condition (str): The conditioning sequence for the output.
If None, the output is not conditioned.
do_sample (bool): Whether to use sampling or greedy decoding.
Expand All @@ -134,6 +139,7 @@ def chat_generate(
temperature = temperature,
max_tokens = max_new_tokens,
n = num_return_sequences,
api_base = api_base,
messages=[[{"content": content, "role": "user"}] for content in messages]
)
return [response['choices'][0]['message']['content'] for response in responses]
Expand Down
Loading