Skip to content

Commit

Permalink
Custom OpenAI provider: Handshake failed with status: 400 #76 Append…
Browse files Browse the repository at this point in the history
… endpoint to custom url.path
  • Loading branch information
valentinfrlch committed Oct 31, 2024
1 parent 80dcdac commit c304a9a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion custom_components/llmvision/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,10 @@ async def custom_openai(self):
self.user_input[CONF_CUSTOM_OPENAI_ENDPOINT])
protocol = url.scheme
base_url = url.hostname
path = url.path if url.path else ""
port = ":" + str(url.port) if url.port else ""

endpoint = "/v1/models"
endpoint = path + "/v1/models"
header = {'Content-type': 'application/json',
'Authorization': 'Bearer ' + self.user_input[CONF_CUSTOM_OPENAI_API_KEY]} if CONF_CUSTOM_OPENAI_API_KEY in self.user_input else {}
except Exception as e:
Expand Down
6 changes: 3 additions & 3 deletions custom_components/llmvision/request_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def default_model(provider): return {

class RequestHandler:
"""class to handle requests to AI providers"""

def __init__(self, hass, message, max_tokens, temperature, detail):
self.session = async_get_clientsession(hass)
self.hass = hass
Expand Down Expand Up @@ -175,9 +176,8 @@ async def make_request(self, call):
api_key = self.hass.data.get(DOMAIN).get(
entry_id).get(
CONF_CUSTOM_OPENAI_API_KEY, "")
endpoint = self.hass.data.get(DOMAIN).get(
entry_id).get(
CONF_CUSTOM_OPENAI_ENDPOINT)
endpoint = self.hass.data.get(DOMAIN).get(entry_id).get(
CONF_CUSTOM_OPENAI_ENDPOINT) + "/v1/chat/completions"
self._validate_call(provider=provider,
api_key=api_key,
base64_images=self.base64_images)
Expand Down

0 comments on commit c304a9a

Please sign in to comment.