Deadmon commited on
Commit
51cbe57
·
verified ·
1 Parent(s): b0434cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -15
app.py CHANGED
@@ -162,27 +162,28 @@ class TextEditor:
162
 
163
  # OpenAIApi class
164
  class OpenAIApi:
165
- def __init__(self, preprompt="", endpoint="https://deadmon-copypasta.hf.space.openai.azure.com/", model="gpt-4o", api_key=None):
166
  # Validate endpoint format
167
- if "<your-resource-name>" in endpoint:
168
- logger.error("Invalid endpoint: Replace '<your-resource-name>' with your Azure OpenAI resource name")
169
- raise ValueError("Invalid endpoint: Replace '<your-resource-name>' with your Azure OpenAI resource name (e.g., https://my-resource.openai.azure.com/)")
170
- if not re.match(r"^https://[a-zA-Z0-9-]+\.openai\.azure\.com/?$", endpoint):
171
- logger.warning(f"Endpoint format may be incorrect: {endpoint}. Expected format: https://<resource-name>.openai.azure.com/")
172
 
173
  # Use a minimal httpx.Client to avoid proxies parameter
174
  http_client = httpx.Client()
175
- self.client = AzureOpenAI(
176
- azure_endpoint=endpoint,
177
- api_key=api_key or os.getenv("AZURE_OPENAI_API_KEY"),
178
- api_version="2024-02-15-preview",
179
- http_client=http_client
180
- )
 
 
 
 
181
  self.model = model
182
- self.preprompt = preprompt
183
  self.memory = ConversationMemory()
184
  self.editor = TextEditor(self.memory)
185
- logger.info(f"Initialized OpenAIApi with endpoint: {endpoint}, model: {model}, api_version: 2024-02-15-preview")
186
  self.functions = [
187
  {
188
  "type": "function",
@@ -386,7 +387,7 @@ async def edit_suffix(chunk_id, suffix):
386
  def create_ui():
387
  with gr.Blocks(title="Azure OpenAI Chat & Text Editor") as demo:
388
  gr.Markdown("# Azure OpenAI Chat with Text Editing")
389
- gr.Markdown("**Note**: Ensure the Azure OpenAI endpoint is set correctly in `app.py` (replace `<your-resource-name>` with your resource name).")
390
 
391
  with gr.Tab("Chat"):
392
  chatbot = gr.Chatbot(label="Conversation", type="messages")
 
162
 
163
  # OpenAIApi class
164
  class OpenAIApi:
165
+ def __init__(self, preprompt="", endpoint="https://T-App-GPT4o.openai.azure.com/", model="gpt-4o", api_key=None):
166
  # Validate endpoint format
167
+ if not re.match(r"^https://[a-zA-Z0-9-]+\.openai\.com/?$", endpoint):
168
+ logger.warning(f"Endpoint format may be incorrect: {endpoint}. Expected format: https://<resource>.openai.azure.com/")
 
 
 
169
 
170
  # Use a minimal httpx.Client to avoid proxies parameter
171
  http_client = httpx.Client()
172
+ try:
173
+ self.client = AzureOpenAI(
174
+ azure_endpoint=endpoint,
175
+ api_key=api_key or os.getenv("AZURE_OPENAI_API_KEY"),
176
+ api_version="2024-02-15-preview",
177
+ http_client=http_client
178
+ )
179
+ except Exception as e:
180
+ logger.error(f"Failed to initialize AzureOpenAI client: {str(e)}")
181
+ raise
182
  self.model = model
183
+ self.preprompt = prompt
184
  self.memory = ConversationMemory()
185
  self.editor = TextEditor(self.memory)
186
+ logger.info(f"Initialized OpenAIApi with: endpoint: {endpoint}, model: {model}, api_version: 2024-02-15-preview}")
187
  self.functions = [
188
  {
189
  "type": "function",
 
387
  def create_ui():
388
  with gr.Blocks(title="Azure OpenAI Chat & Text Editor") as demo:
389
  gr.Markdown("# Azure OpenAI Chat with Text Editing")
390
+ gr.Markdown("**Note**: Using Azure OpenAI endpoint: https://T-App-GPT4o.openai.azure.com/")
391
 
392
  with gr.Tab("Chat"):
393
  chatbot = gr.Chatbot(label="Conversation", type="messages")