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

Add VLLMChatModel support to chat API #220

Merged
merged 2 commits into from
Feb 20, 2025
Merged
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
31 changes: 31 additions & 0 deletions src/agentlab/llm/chat_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ def make_model(self):
max_new_tokens=self.max_new_tokens,
n_retry_server=self.n_retry_server,
)
elif self.backend == "vllm":
return VLLMChatModel(
model_name=self.model_name,
temperature=self.temperature,
max_tokens=self.max_new_tokens,
n_retry_server=self.n_retry_server,
)
else:
raise ValueError(f"Backend {self.backend} is not supported")

Expand Down Expand Up @@ -423,3 +430,27 @@ def __init__(

client = InferenceClient(model=model_url, token=token)
self.llm = partial(client.text_generation, max_new_tokens=max_new_tokens)


class VLLMChatModel(ChatModel):
def __init__(
self,
model_name,
api_key=None,
temperature=0.5,
max_tokens=100,
n_retry_server=4,
Copy link

Choose a reason for hiding this comment

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

Inconsistent Retry Parameter Naming category Readability

Tell me more
What is the issue?

The 'n_retry_server' parameter name in VLLMChatModel is inconsistent with the parent class's 'max_retry' parameter, while they serve the same purpose.

Why this matters

This inconsistency could cause confusion and maintenance issues as the parameter serves the same purpose but has a different name than its parent class.

Suggested change ∙ Feature Preview

Rename the parameter to match the parent class:

def __init__(
    self,
    model_name,
    api_key=None,
    temperature=0.5,
    max_tokens=100,
    max_retry=4,  # Changed from n_retry_server
    min_retry_wait_time=60,
):
    super().__init__(
        model_name=model_name,
        api_key=api_key,
        temperature=temperature,
        max_tokens=max_tokens,
        max_retry=max_retry,  # Use consistent parameter name
        min_retry_wait_time=min_retry_wait_time,
        api_key_env_var="VLLM_API_KEY",
        client_class=OpenAI,
        client_args={"base_url": base_url},
        pricing_func=None,
    )

Report a problem with this comment

💬 Chat with Korbit by mentioning @korbit-ai.

min_retry_wait_time=60,
):
super().__init__(
model_name=model_name,
api_key=api_key,
temperature=temperature,
max_tokens=max_tokens,
max_retry=n_retry_server,
min_retry_wait_time=min_retry_wait_time,
api_key_env_var="VLLM_API_KEY",
client_class=OpenAI,
client_args={"base_url": "http://0.0.0.0:8000/v1"},
pricing_func=None,
)
Loading