Deadmon commited on
Commit
1eab316
·
verified ·
1 Parent(s): a561bb3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -171,7 +171,7 @@ class OpenAIApi:
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
@@ -278,7 +278,8 @@ class OpenAIApi:
278
  logger.info(f"Sending request to model: {self.model}, endpoint: {self.client._base_url}, messages: {json.dumps(messages, ensure_ascii=False)}")
279
 
280
  try:
281
- response = await self.client.chat.completions.create(
 
282
  model=self.model,
283
  messages=messages,
284
  temperature=0.5,
@@ -292,7 +293,9 @@ class OpenAIApi:
292
 
293
  full_response = ""
294
  tool_calls = []
 
295
  async for chunk in response:
 
296
  if chunk.choices and chunk.choices[0].delta.content:
297
  full_response += chunk.choices[0].delta.content
298
  if chunk.choices and chunk.choices[0].delta.tool_calls:
 
171
  http_client = httpx.Client()
172
  try:
173
  self.client = AzureOpenAI(
174
+ azure_endpoint=endpoint.rstrip('/'), # Ensure no trailing slash
175
  api_key=api_key or os.getenv("AZURE_OPENAI_API_KEY"),
176
  api_version="2024-02-15-preview",
177
  http_client=http_client
 
278
  logger.info(f"Sending request to model: {self.model}, endpoint: {self.client._base_url}, messages: {json.dumps(messages, ensure_ascii=False)}")
279
 
280
  try:
281
+ # Synchronous call to create stream
282
+ response = self.client.chat.completions.create(
283
  model=self.model,
284
  messages=messages,
285
  temperature=0.5,
 
293
 
294
  full_response = ""
295
  tool_calls = []
296
+ # Asynchronous iteration over stream
297
  async for chunk in response:
298
+ logger.debug(f"Received chunk: {chunk}")
299
  if chunk.choices and chunk.choices[0].delta.content:
300
  full_response += chunk.choices[0].delta.content
301
  if chunk.choices and chunk.choices[0].delta.tool_calls: