vim-ai
vim-ai copied to clipboard
Allow setting request "User Agent"
I configured GROQ as a custom endpoint, but then I was hitting 403 errors. Debugging, I figured that python's urllib's default user agent is blocked for some reason. Setting the User Agent to curl i.e. "curl/7.54.1" fixes the problem. Can you allow the user to configure the User Agent?
That is quite strange they reject the default user agent, what is the reason they do that? Anyway, I think it would be fine to add an option to the commands (e.g. options.request_user_agent
)
That is quite strange they reject the default user agent, what is the reason they do that? Anyway, I think it would be fine to add an option to the commands (e.g.
options.request_user_agent
)
Don't know the reason. I just monkey patched the request headers, since every other providers also accept curl, but an option would be fine.
Here's what I did:
diff --git a/py/utils.py b/py/utils.py
index 963377d..5fd0f90 100644
--- a/py/utils.py
+++ b/py/utils.py
@@ -203,6 +203,7 @@ def openai_request(url, data, options):
enable_auth=options['enable_auth']
headers = {
"Content-Type": "application/json",
+ "User-Agent": "curl/8.7.1",
}
if enable_auth:
(OPENAI_API_KEY, OPENAI_ORG_ID) = load_api_key()