We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 97e6a6f + a9b392e commit 5f4aa39Copy full SHA for 5f4aa39
End_to_end_Solutions/InsightsGenerator/insights_generator/core/OAI_client.py
@@ -3,12 +3,17 @@
3
import os
4
import pdb
5
import tiktoken
6
+import urllib.parse
7
+
8
+def is_valid_url(url):
9
+ parsed_url = urllib.parse.urlparse(url)
10
+ return parsed_url.scheme in ["http", "https"] and parsed_url.netloc != ""
11
12
def make_prompt_request(prompt, max_tokens = 2048, timeout = 4):
13
# Whitelist of allowed URLs
14
allowed_urls = ["https://api.openai.com/v1/embeddings", "https://another-trusted-url.com"]
15
url = os.getenv("AOAI_ENDPOINT")
- if url not in allowed_urls:
16
+ if not is_valid_url(url) or url not in allowed_urls:
17
raise ValueError("The provided URL is not allowed.")
18
key = os.getenv("AOAI_KEY")
19
0 commit comments