aurelio-labs/semantic-router

ValueError: No embeddings returned. Error: Connection error. - on ```AzureOpenAIEncoder```

Closed this issue · 0 comments

from semantic_router import Route

# we could use this as a guide for our chatbot to avoid political conversations
politics = Route(
    name="politics",
    utterances=[
        "isn't politics the best thing ever",
        "why don't you tell me about your political opinions",
        "don't you just love the president" "don't you just hate the president",
        "they're going to destroy this country!",
        "they will save the country!",
    ],
)

# this could be used as an indicator to our chatbot to switch to a more
# conversational prompt
chitchat = Route(
    name="chitchat",
    utterances=[
        "how's the weather today?",
        "how are things going?",
        "lovely weather today",
        "the weather is horrendous",
        "let's go to the chippy",
    ],
)

# we place both of our decisions together into single list
routes = [politics, chitchat]

from semantic_router.encoders import CohereEncoder, AzureOpenAIEncoder
import os

os.environ["AZURE_OPENAI_API_VERSION"] = "2024-02-15-preview"
os.environ["AZURE_OPENAI_ENDPOINT"] = "<ENDPOINT>"
os.environ["AZURE_OPENAI_API_KEY"] = "<API_KEY>"
os.environ ["AZURE_OPENAI_MODEL"] = "text-embedding-ada-002"

encoder = AzureOpenAIEncoder()

from semantic_router.layer import RouteLayer
rl = RouteLayer(encoder=encoder, routes=routes)

The encoder object is the following:
name='text-embedding-ada-002' score_threshold=0.82 type='azure' client=<openai.lib.azure.AzureOpenAI object at 0x00000214915E6CB0> api_key='<API_KEY>' deployment_name='text-embedding-ada-002' azure_endpoint='ENDPOINT' api_version='2024-02-15-preview' model='text-embedding-ada-002'

Most up-to-date version, api key and endpoints are valid. Same code works with cohere API key.


Returns the following:

2024-03-06 11:44:08 WARNING semantic_router.utils.logger Retrying in 2 seconds...
Traceback (most recent call last):
  File "C:\Users\szele\anaconda3\envs\dev\lib\site-packages\httpx\_transports\default.py", line 66, in map_httpcore_exceptions
    yield
  File "C:\Users\szele\anaconda3\envs\dev\lib\site-packages\httpx\_transports\default.py", line 228, in handle_request
    resp = self._pool.handle_request(req)
  File "C:\Users\szele\AppData\Roaming\Python\Python310\site-packages\httpcore\_sync\connection_pool.py", line 167, in handle_request
    raise UnsupportedProtocol(
httpcore.UnsupportedProtocol: Request URL is missing an 'http://' or 'https://' protocol.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\szele\AppData\Roaming\Python\Python310\site-packages\openai\_base_client.py", line 918, in _request
    response = self._client.send(
  File "C:\Users\szele\anaconda3\envs\dev\lib\site-packages\httpx\_client.py", line 901, in send
    response = self._send_handling_auth(
  File "C:\Users\szele\anaconda3\envs\dev\lib\site-packages\httpx\_client.py", line 929, in _send_handling_auth
    response = self._send_handling_redirects(
  File "C:\Users\szele\anaconda3\envs\dev\lib\site-packages\httpx\_client.py", line 966, in _send_handling_redirects
    response = self._send_single_request(request)
  File "C:\Users\szele\anaconda3\envs\dev\lib\site-packages\httpx\_client.py", line 1002, in _send_single_request
    response = transport.handle_request(request)
  File "C:\Users\szele\anaconda3\envs\dev\lib\site-packages\httpx\_transports\default.py", line 227, in handle_request
    with map_httpcore_exceptions():
  File "C:\Users\szele\anaconda3\envs\dev\lib\contextlib.py", line 153, in __exit__
    self.gen.throw(typ, value, traceback)
  File "C:\Users\szele\anaconda3\envs\dev\lib\site-packages\httpx\_transports\default.py", line 83, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.UnsupportedProtocol: Request URL is missing an 'http://' or 'https://' protocol.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\szele\anaconda3\envs\dev\lib\site-packages\httpx\_transports\default.py", line 66, in map_httpcore_exceptions
    yield
  File "C:\Users\szele\anaconda3\envs\dev\lib\site-packages\httpx\_transports\default.py", line 228, in handle_request
    resp = self._pool.handle_request(req)
  File "C:\Users\szele\AppData\Roaming\Python\Python310\site-packages\httpcore\_sync\connection_pool.py", line 167, in handle_request
    raise UnsupportedProtocol(
httpcore.UnsupportedProtocol: Request URL is missing an 'http://' or 'https://' protocol.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\szele\AppData\Roaming\Python\Python310\site-packages\openai\_base_client.py", line 918, in _request
    response = self._client.send(
  File "C:\Users\szele\anaconda3\envs\dev\lib\site-packages\httpx\_client.py", line 901, in send
    response = self._send_handling_auth(
  File "C:\Users\szele\anaconda3\envs\dev\lib\site-packages\httpx\_client.py", line 929, in _send_handling_auth
    response = self._send_handling_redirects(
  File "C:\Users\szele\anaconda3\envs\dev\lib\site-packages\httpx\_client.py", line 966, in _send_handling_redirects
    response = self._send_single_request(request)
  File "C:\Users\szele\anaconda3\envs\dev\lib\site-packages\httpx\_client.py", line 1002, in _send_single_request
    response = transport.handle_request(request)
  File "C:\Users\szele\anaconda3\envs\dev\lib\site-packages\httpx\_transports\default.py", line 227, in handle_request
    with map_httpcore_exceptions():
  File "C:\Users\szele\anaconda3\envs\dev\lib\contextlib.py", line 153, in __exit__
    self.gen.throw(typ, value, traceback)
  File "C:\Users\szele\anaconda3\envs\dev\lib\site-packages\httpx\_transports\default.py", line 83, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.UnsupportedProtocol: Request URL is missing an 'http://' or 'https://' protocol.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\szele\anaconda3\envs\dev\lib\site-packages\httpx\_transports\default.py", line 66, in map_httpcore_exceptions
    yield
  File "C:\Users\szele\anaconda3\envs\dev\lib\site-packages\httpx\_transports\default.py", line 228, in handle_request
    resp = self._pool.handle_request(req)
  File "C:\Users\szele\AppData\Roaming\Python\Python310\site-packages\httpcore\_sync\connection_pool.py", line 167, in handle_request
    raise UnsupportedProtocol(
httpcore.UnsupportedProtocol: Request URL is missing an 'http://' or 'https://' protocol.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\szele\AppData\Roaming\Python\Python310\site-packages\openai\_base_client.py", line 918, in _request
    response = self._client.send(
  File "C:\Users\szele\anaconda3\envs\dev\lib\site-packages\httpx\_client.py", line 901, in send
    response = self._send_handling_auth(
  File "C:\Users\szele\anaconda3\envs\dev\lib\site-packages\httpx\_client.py", line 929, in _send_handling_auth
    response = self._send_handling_redirects(
  File "C:\Users\szele\anaconda3\envs\dev\lib\site-packages\httpx\_client.py", line 966, in _send_handling_redirects
    response = self._send_single_request(request)
  File "C:\Users\szele\anaconda3\envs\dev\lib\site-packages\httpx\_client.py", line 1002, in _send_single_request
    response = transport.handle_request(request)
  File "C:\Users\szele\anaconda3\envs\dev\lib\site-packages\httpx\_transports\default.py", line 227, in handle_request
    with map_httpcore_exceptions():
  File "C:\Users\szele\anaconda3\envs\dev\lib\contextlib.py", line 153, in __exit__
    self.gen.throw(typ, value, traceback)
  File "C:\Users\szele\anaconda3\envs\dev\lib\site-packages\httpx\_transports\default.py", line 83, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.UnsupportedProtocol: Request URL is missing an 'http://' or 'https://' protocol.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\szele\anaconda3\envs\dev\lib\site-packages\semantic_router\encoders\zure.py", line 89, in __call__
    embeds = self.client.embeddings.create(
  File "C:\Users\szele\AppData\Roaming\Python\Python310\site-packages\openai\resources\embeddings.py", line 113, in create
    return self._post(
  File "C:\Users\szele\AppData\Roaming\Python\Python310\site-packages\openai\_base_client.py", line 1200, in post
    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
  File "C:\Users\szele\AppData\Roaming\Python\Python310\site-packages\openai\_base_client.py", line 889, in request
    return self._request(
  File "C:\Users\szele\AppData\Roaming\Python\Python310\site-packages\openai\_base_client.py", line 942, in _request
    return self._retry_request(
  File "C:\Users\szele\AppData\Roaming\Python\Python310\site-packages\openai\_base_client.py", line 1013, in _retry_request
    return self._request(
  File "C:\Users\szele\AppData\Roaming\Python\Python310\site-packages\openai\_base_client.py", line 942, in _request
    return self._retry_request(
  File "C:\Users\szele\AppData\Roaming\Python\Python310\site-packages\openai\_base_client.py", line 1013, in _retry_request
    return self._request(
  File "C:\Users\szele\AppData\Roaming\Python\Python310\site-packages\openai\_base_client.py", line 952, in _request
    raise APIConnectionError(request=request) from err
openai.APIConnectionError: Connection error.
2024-03-06 11:44:15 WARNING semantic_router.utils.logger Retrying in 4 seconds...
Traceback (most recent call last):

  Cell In[11], line 52
    rl = RouteLayer(encoder=encoder, routes=routes)

  File ~\anaconda3\envs\dev\lib\site-packages\semantic_router\layer.py:207 in __init__
    self._add_routes(routes=self.routes)

  File ~\anaconda3\envs\dev\lib\site-packages\semantic_router\layer.py:349 in _add_routes
    embedded_utterances = self.encoder(all_utterances)

  File ~\anaconda3\envs\dev\lib\site-packages\semantic_router\encoders\zure.py:111 in __call__
    raise ValueError(f"No embeddings returned. Error: {error_message}")

ValueError: No embeddings returned. Error: Connection error.