-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from SpellcraftAI/dev
feat: add Azure support
- Loading branch information
Showing
11 changed files
with
193 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from .Batch import Batch | ||
from .Auto import Auto | ||
from .config import AzureConfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from os import environ | ||
from types import SimpleNamespace | ||
|
||
|
||
class AzureConfig(SimpleNamespace): | ||
def __init__( | ||
self, | ||
azure_endpoint: str or None = environ.get("AZURE_OPENAI_ENDPOINT"), | ||
api_version: str or None = environ.get("AZURE_OPENAI_VERSION"), | ||
api_key: str or None = environ.get("AZURE_OPENAI_KEY"), | ||
): | ||
super().__init__( | ||
azure_endpoint=azure_endpoint, | ||
api_version=api_version, | ||
api_key=api_key | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import os | ||
import pytest | ||
from oaib import Auto, Batch, AzureConfig | ||
|
||
azure = AzureConfig() | ||
|
||
|
||
async def test_azure(): | ||
batch = Batch(workers=8, azure=azure, loglevel=2) | ||
|
||
n = 20 | ||
for i in range(n): | ||
await batch.add( | ||
"chat.completions.create", | ||
model="Research", | ||
messages=[{"role": "user", "content": "say hello"}] | ||
) | ||
|
||
chats = await batch.run() | ||
assert len(chats) == n, f"Chat batch should return {n} results" | ||
print(chats) | ||
|
||
chat = chats.iloc[0].get("result") | ||
assert chat['choices'], "Should get valid chat completions" | ||
|
||
|
||
async def test_azure_auto(): | ||
with pytest.raises(ValueError, match="Auto does not support Azure"): | ||
auto_with_azure = Auto(azure=azure) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters