Skip to content

Instantly share code, notes, and snippets.

@deividaspetraitis
Created July 19, 2023 08:28
Show Gist options
  • Save deividaspetraitis/cd856398b0ab3090811d895a4cb00158 to your computer and use it in GitHub Desktop.
Save deividaspetraitis/cd856398b0ab3090811d895a4cb00158 to your computer and use it in GitHub Desktop.
Path for madox2/vim-ai to work with Azure AI.
diff --git a/py/chat.py b/py/chat.py
index 93d31bf..1980681 100644
--- a/py/chat.py
+++ b/py/chat.py
@@ -69,7 +69,7 @@ try:
**openai_options
}
printDebug("[chat] request: {}", request)
- response = openai_request('https://api.openai.com/v1/chat/completions', request, http_options)
+ response = openai_request('https://engineering-ai.openai.azure.com/openai/deployments/engineering/chat/completions?api-version=2023-03-15-preview', request, http_options)
def map_chunk(resp):
printDebug("[chat] response: {}", resp)
return resp['choices'][0]['delta'].get('content', '')
diff --git a/py/complete.py b/py/complete.py
index c8d45fe..363544c 100644
--- a/py/complete.py
+++ b/py/complete.py
@@ -17,7 +17,7 @@ def complete_engine(prompt):
**openai_options
}
printDebug("[engine-complete] request: {}", request)
- response = openai_request('https://api.openai.com/v1/completions', request, http_options)
+ response = openai_request('https://engineering-ai.openai.azure.com/openai/deployments/engineering/completions?api-version=2022-12-01', request, http_options)
def map_chunk(resp):
printDebug("[engine-complete] response: {}", resp)
return resp['choices'][0].get('text', '')
@@ -35,7 +35,7 @@ def chat_engine(prompt):
**openai_options
}
printDebug("[engine-chat] request: {}", request)
- response = openai_request('https://api.openai.com/v1/chat/completions', request, http_options)
+ response = openai_request('https://engineering-ai.openai.azure.com/openai/deployments/engineering/chat/completions?api-version=2023-03-15-preview', request, http_options)
def map_chunk(resp):
printDebug("[engine-chat] response: {}", resp)
return resp['choices'][0]['delta'].get('content', '')
diff --git a/py/utils.py b/py/utils.py
index 76ae1e4..f815679 100644
--- a/py/utils.py
+++ b/py/utils.py
@@ -124,7 +124,7 @@ OPENAI_API_KEY = load_api_key()
def openai_request(url, data, options):
headers = {
"Content-Type": "application/json",
- "Authorization": f"Bearer {OPENAI_API_KEY}"
+ "api-key": f"{OPENAI_API_KEY}"
}
request_timeout=options['request_timeout']
req = urllib.request.Request(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment