Update main.py
Browse files
main.py
CHANGED
@@ -214,7 +214,6 @@ async def chat_completions(
|
|
214 |
request: ChatRequest,
|
215 |
app_secret: str = Depends(lambda: os.getenv("APP_SECRET"))
|
216 |
):
|
217 |
-
|
218 |
# Validate model
|
219 |
if request.model not in Blackbox.models:
|
220 |
raise HTTPException(
|
@@ -225,6 +224,13 @@ async def chat_completions(
|
|
225 |
# Generate a UUID for the conversation
|
226 |
conversation_id = str(uuid.uuid4()).replace("-", "")
|
227 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
228 |
json_data = {
|
229 |
"attachments": [],
|
230 |
"conversationId": conversation_id,
|
@@ -233,12 +239,10 @@ async def chat_completions(
|
|
233 |
),
|
234 |
}
|
235 |
|
236 |
-
headers["uniqueid"] = conversation_id
|
237 |
-
|
238 |
async def generate():
|
239 |
async with httpx.AsyncClient() as client:
|
240 |
try:
|
241 |
-
async with client.stream('POST',
|
242 |
response.raise_for_status()
|
243 |
async for line in response.aiter_lines():
|
244 |
if line and line != "[DONE]":
|
|
|
214 |
request: ChatRequest,
|
215 |
app_secret: str = Depends(lambda: os.getenv("APP_SECRET"))
|
216 |
):
|
|
|
217 |
# Validate model
|
218 |
if request.model not in Blackbox.models:
|
219 |
raise HTTPException(
|
|
|
224 |
# Generate a UUID for the conversation
|
225 |
conversation_id = str(uuid.uuid4()).replace("-", "")
|
226 |
|
227 |
+
# Define headers
|
228 |
+
headers = {
|
229 |
+
"Authorization": f"Bearer {app_secret}",
|
230 |
+
"Content-Type": "application/json",
|
231 |
+
"uniqueid": conversation_id,
|
232 |
+
}
|
233 |
+
|
234 |
json_data = {
|
235 |
"attachments": [],
|
236 |
"conversationId": conversation_id,
|
|
|
239 |
),
|
240 |
}
|
241 |
|
|
|
|
|
242 |
async def generate():
|
243 |
async with httpx.AsyncClient() as client:
|
244 |
try:
|
245 |
+
async with client.stream('POST', Blackbox.api_endpoint, headers=headers, json=json_data) as response:
|
246 |
response.raise_for_status()
|
247 |
async for line in response.aiter_lines():
|
248 |
if line and line != "[DONE]":
|