mirror of
https://github.com/open-webui/pipelines
synced 2025-05-10 23:50:45 +00:00
enh: azure openai pipeline
This commit is contained in:
parent
f627142ccb
commit
c4b5f2be47
@ -1,9 +1,19 @@
|
||||
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.
|
||||
@ -11,6 +21,7 @@ class Pipeline:
|
||||
# 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):
|
||||
@ -32,25 +43,22 @@ class Pipeline:
|
||||
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:
|
||||
|
Loading…
Reference in New Issue
Block a user