Skip to content

Commit

Permalink
Check for model existence in text client (#2729)
Browse files Browse the repository at this point in the history
This implementation adds a new get_available_models() method to the
DebugClient class, which retrieves the list of available model
configurations from the API and returns a list of their names. The
send_message() method then calls this method and checks if the provided
model_config_name is in the list of available models. If it's not, a
ValueError is raised with an appropriate error message.
  • Loading branch information
mzamini92 committed Apr 21, 2023
1 parent 83c5598 commit f5ef9e5
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions inference/text-client/text_client_utils.py
Expand Up @@ -9,6 +9,7 @@ class DebugClient:
def __init__(self, backend_url, http_client=requests):
self.backend_url = backend_url
self.http_client = http_client
self.available_models = self.get_available_models()

def login(self, username):
auth_data = self.http_client.get(f"{self.backend_url}/auth/callback/debug", params={"code": username}).json()
Expand All @@ -28,7 +29,18 @@ def create_chat(self):
self.message_id = None
return self.chat_id

def get_available_models(self):
response = self.http_client.get(
f"{self.backend_url}/models",
headers=self.auth_headers,
)
response.raise_for_status()
return [model["name"] for model in response.json()]

def send_message(self, message, model_config_name):
available_models = self.get_available_models()
if model_config_name not in available_models:
raise ValueError(f"Invalid model config name: {model_config_name}")
response = self.http_client.post(
f"{self.backend_url}/chats/{self.chat_id}/prompter_message",
json={
Expand Down

0 comments on commit f5ef9e5

Please sign in to comment.