Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,7 +11,6 @@ app = FastAPI()
|
|
| 11 |
|
| 12 |
class RequestBody(BaseModel):
|
| 13 |
model: str
|
| 14 |
-
key_body: str
|
| 15 |
text: str
|
| 16 |
|
| 17 |
|
|
@@ -19,40 +18,13 @@ class RequestBody(BaseModel):
|
|
| 19 |
async def generate_response(request_body: RequestBody):
|
| 20 |
input_text = request_body.text
|
| 21 |
model = request_body.model
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
all_chunk = response.json()['candidates'][0]['content']['parts'][0]['text']
|
| 32 |
-
|
| 33 |
-
if model == 'groq':
|
| 34 |
-
key_groq = os.environ['key_groq']
|
| 35 |
-
headers = {'Authorization': f'Bearer {key_groq}','Content-Type': 'application/json'}
|
| 36 |
-
json_data = {'messages': [{'role': 'user','content': input_text}],'model': 'llama-3.1-70b-versatile',}
|
| 37 |
-
response = requests.post('https://api.groq.com/openai/v1/chat/completions', headers=headers, json=json_data)
|
| 38 |
-
all_chunk = response.json()["choices"][0]["message"]["content"]
|
| 39 |
-
|
| 40 |
-
if model == "cohere":
|
| 41 |
-
key_cohere = os.environ['key_cohere']
|
| 42 |
-
headers = {'accept': 'application/json','content-type': 'application/json','Authorization': f'Bearer {key_cohere}',}
|
| 43 |
-
data = {"model":"command-r-plus","messages":[{ "role": "user", "content": input_text}]}
|
| 44 |
-
response = requests.post('https://api.cohere.com/v2/chat', headers=headers, json=data)
|
| 45 |
-
all_chunk = response.json()['message']['content'][0]['text']
|
| 46 |
-
|
| 47 |
-
if model == 'blackbox':
|
| 48 |
-
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36","Accept": "*/*","Accept-Language": "en-US,en;q=0.5","Accept-Encoding": "gzip, deflate, br","Referer": "https://www.blackbox.ai","Content-Type": "application/json","Origin": "https://www.blackbox.ai","DNT": "1","Sec-GPC": "1","Alt-Used": "www.blackbox.ai","Connection": "keep-alive",}
|
| 49 |
-
json_data = {'messages': [{'id': uuid.uuid4().hex,'content': input_text,'role': 'user',},],'id': uuid.uuid4().hex,'previewToken': None,'userId': None,'codeModelMode': True,'agentMode': { 'mode': True, 'id': 'ImageGenerationLV45LJp', 'name': 'Image Generation',},'trendingAgentMode': {},'isMicMode': False,'maxTokens': 1024,'playgroundTopP': None,'playgroundTemperature': None,'isChromeExt': False,'githubToken': None,'clickedAnswer2': False,'clickedAnswer3': False,'clickedForceWebSearch': False,'visitFromDelta': False,'mobileClient': False,'userSelectedModel': None,'validated': '00f37b34-a166-4efb-bce5-1312d87f2f94',}
|
| 50 |
-
response = requests.post('https://www.blackbox.ai/api/chat', headers=headers, json=json_data)
|
| 51 |
-
decoded_string = ''.join(char for char in response.text if char != '\x00' and char != '\x08')
|
| 52 |
-
pattern = r'https?://\S+\.(?:jpg|jpeg|png|gif)'
|
| 53 |
-
match2 = re.search(pattern, decoded_string)
|
| 54 |
-
all_chunk = match2.group()
|
| 55 |
-
|
| 56 |
-
if key_body != key_true:
|
| 57 |
-
all_chunk = "How's the hack going?"
|
| 58 |
return {"response": all_chunk}
|
|
|
|
| 11 |
|
| 12 |
class RequestBody(BaseModel):
|
| 13 |
model: str
|
|
|
|
| 14 |
text: str
|
| 15 |
|
| 16 |
|
|
|
|
| 18 |
async def generate_response(request_body: RequestBody):
|
| 19 |
input_text = request_body.text
|
| 20 |
model = request_body.model
|
| 21 |
+
if model == 'blackbox':
|
| 22 |
+
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36","Accept": "*/*","Accept-Language": "en-US,en;q=0.5","Accept-Encoding": "gzip, deflate, br","Referer": "https://www.blackbox.ai","Content-Type": "application/json","Origin": "https://www.blackbox.ai","DNT": "1","Sec-GPC": "1","Alt-Used": "www.blackbox.ai","Connection": "keep-alive",}
|
| 23 |
+
json_data = {'messages': [{'id': uuid.uuid4().hex,'content': input_text,'role': 'user',},],'id': uuid.uuid4().hex,'previewToken': None,'userId': None,'codeModelMode': True,'agentMode': { 'mode': True, 'id': 'ImageGenerationLV45LJp', 'name': 'Image Generation',},'trendingAgentMode': {},'isMicMode': False,'maxTokens': 1024,'playgroundTopP': None,'playgroundTemperature': None,'isChromeExt': False,'githubToken': None,'clickedAnswer2': False,'clickedAnswer3': False,'clickedForceWebSearch': False,'visitFromDelta': False,'mobileClient': False,'userSelectedModel': None,'validated': '00f37b34-a166-4efb-bce5-1312d87f2f94',}
|
| 24 |
+
response = requests.post('https://www.blackbox.ai/api/chat', headers=headers, json=json_data)
|
| 25 |
+
decoded_string = ''.join(char for char in response.text if char != '\x00' and char != '\x08')
|
| 26 |
+
pattern = r'https?://\S+\.(?:jpg|jpeg|png|gif)'
|
| 27 |
+
match2 = re.search(pattern, decoded_string)
|
| 28 |
+
all_chunk = match2.group()
|
| 29 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
return {"response": all_chunk}
|