Skip to content
Merged
Show file tree
Hide file tree
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
28 changes: 4 additions & 24 deletions validmind/ai/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
# SPDX-License-Identifier: AGPL-3.0 AND ValidMind Commercial

import os
from urllib.parse import urljoin

from openai import AzureOpenAI, Client, OpenAI
from openai import AzureOpenAI, OpenAI

from ..logging import get_logger
from ..utils import md_to_html
Expand Down Expand Up @@ -83,28 +82,9 @@ def get_client_and_model():
logger.debug(f"Using Azure OpenAI {__model} for generating descriptions")

else:
try:
# TODO: fix circular import
from ..api_client import get_ai_key, get_api_host

response = get_ai_key()
__client = Client(
base_url=(
# TODO: improve this to be a bit more dynamic
"http://localhost:4000/genai"
if "localhost" in get_api_host()
else urljoin(get_api_host(), "/genai")
),
api_key=response["key"],
)
__model = "gpt-4o" # TODO: backend should tell us which model to use
logger.debug(f"Using ValidMind {__model} for generating descriptions")
except Exception as e:
logger.debug(f"Failed to get API key: {e}")
raise ValueError(
"OPENAI_API_KEY, AZURE_OPENAI_KEY must be set, or your account "
"must be setup to use ValidMind's LLM in order to use LLM features"
)
raise ValueError(
"OPENAI_API_KEY, AZURE_OPENAI_KEY must be setup to use LLM features"
)

return __client, __model

Expand Down
15 changes: 0 additions & 15 deletions validmind/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,21 +525,6 @@ def log_metric(
)


def get_ai_key() -> Dict[str, Any]:
"""Calls the API to get an API key for our LLM proxy."""
r = requests.get(
url=_get_url("ai/key"),
headers=_get_api_headers(),
)

if r.status_code != 200:
# TODO: improve error handling when there's no Open AI API or AI key available
# logger.error("Could not get AI key from ValidMind API")
raise_api_error(r.text)

return r.json()


def generate_test_result_description(test_result_data: Dict[str, Any]) -> str:
r = requests.post(
url=_get_url("ai/generate/test_result_description"),
Expand Down