Skip to content

Commit

Permalink
enh: azure openai pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
tjbck committed Jun 2, 2024
1 parent f627142 commit c4b5f2b
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions examples/providers/azure_openai_pipeline.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
from typing import List, Union, Generator, Iterator
from schemas import OpenAIChatMessage
from pydantic import BaseModel
import requests


class Pipeline:
class Valves(BaseModel):
# You can add your custom valves here.
AZURE_OPENAI_API_KEY: str = "your-azure-openai-api-key-here"
AZURE_OPENAI_ENDPOINT: str = "your-azure-openai-endpoint-here"
DEPLOYMENT_NAME: str = "your-deployment-name-here"
API_VERSION: str = "2023-10-01-preview"
MODEL: str = "gpt-3.5-turbo"
pass

def __init__(self):
# Optionally, you can set the id and name of the pipeline.
# Assign a unique identifier to the pipeline.
# The identifier must be unique across all pipelines.
# The identifier must be an alphanumeric string that can include underscores or hyphens. It cannot contain spaces, special characters, slashes, or backslashes.
self.id = "azure_openai_pipeline"
self.name = "Azure OpenAI Pipeline"
self.valves = self.Valves()
pass

async def on_startup(self):
Expand All @@ -32,25 +43,22 @@ def pipe(
print(messages)
print(user_message)

AZURE_OPENAI_API_KEY = "your-azure-openai-api-key-here"
AZURE_OPENAI_ENDPOINT = "your-azure-openai-endpoint-here"
DEPLOYMENT_NAME = "your-deployment-name-here"
MODEL = "gpt-3.5-turbo"
headers = {
"api-key": self.valves.AZURE_OPENAI_API_KEY,
"Content-Type": "application/json",
}

headers = {"api-key": AZURE_OPENAI_API_KEY, "Content-Type": "application/json"}

url = f"{AZURE_OPENAI_ENDPOINT}/openai/deployments/{DEPLOYMENT_NAME}/chat/completions?api-version=2023-10-01-preview"
url = f"{self.valves.AZURE_OPENAI_ENDPOINT}/openai/deployments/{self.valves.DEPLOYMENT_NAME}/chat/completions?api-version={self.valves.API_VERSION}"

try:
r = requests.post(
url=url,
json={**body, "model": MODEL},
json={**body, "model": self.valves.MODEL},
headers=headers,
stream=True,
)

r.raise_for_status()

if body["stream"]:
return r.iter_lines()
else:
Expand Down

0 comments on commit c4b5f2b

Please sign in to comment.