Update azure_openai.py
Browse files- azure_openai.py +7 -3
azure_openai.py
CHANGED
@@ -1,14 +1,18 @@
|
|
1 |
import httpx
|
2 |
import logging
|
|
|
3 |
from pipecat.frames.frames import TextFrame, LLMResponseFrame
|
4 |
from pipecat.processors.frame_processor import FrameProcessor, FrameDirection
|
5 |
|
6 |
logger = logging.getLogger(__name__)
|
7 |
|
8 |
class AzureOpenAILLMService(FrameProcessor):
|
9 |
-
def __init__(self,
|
10 |
super().__init__()
|
11 |
-
self.api_key =
|
|
|
|
|
|
|
12 |
self.preprompt = preprompt
|
13 |
self.endpoint = endpoint
|
14 |
self.client = httpx.AsyncClient()
|
@@ -18,7 +22,7 @@ class AzureOpenAILLMService(FrameProcessor):
|
|
18 |
try:
|
19 |
messages = []
|
20 |
if self.preprompt:
|
21 |
-
messages.append({"role": "system", "content": self.preprompt})
|
22 |
messages.append({"role": "user", "content": frame.text})
|
23 |
|
24 |
headers = {
|
|
|
1 |
import httpx
|
2 |
import logging
|
3 |
+
import os
|
4 |
from pipecat.frames.frames import TextFrame, LLMResponseFrame
|
5 |
from pipecat.processors.frame_processor import FrameProcessor, FrameDirection
|
6 |
|
7 |
logger = logging.getLogger(__name__)
|
8 |
|
9 |
class AzureOpenAILLMService(FrameProcessor):
|
10 |
+
def __init__(self, preprompt: str = "", endpoint: str = "https://designcntrl-azure-openai-server.openai.azure.com/openai/deployments/ottopilot/chat/completions?api-version=2023-03-15-preview"):
|
11 |
super().__init__()
|
12 |
+
self.api_key = os.environ.get("azure_openai")
|
13 |
+
if not self.api_key:
|
14 |
+
logger.error("Missing Hugging Face Secret: azure_openai")
|
15 |
+
raise ValueError("Azure OpenAI API key not found in environment variable 'azure_openai'")
|
16 |
self.preprompt = preprompt
|
17 |
self.endpoint = endpoint
|
18 |
self.client = httpx.AsyncClient()
|
|
|
22 |
try:
|
23 |
messages = []
|
24 |
if self.preprompt:
|
25 |
+
gever messages.append({"role": "system", "content": self.preprompt})
|
26 |
messages.append({"role": "user", "content": frame.text})
|
27 |
|
28 |
headers = {
|