clodflare and segmind fixed
Browse files
chat.py
CHANGED
@@ -39,15 +39,26 @@ def converse(conversation,provider,model,key,other:dict={}):
|
|
39 |
api_token = key.split('~')[1]
|
40 |
except:
|
41 |
raise Exception('Invalid Accound Id or api token')
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
elif(provider == 'openrouter'):
|
45 |
chat = ChatOpenAI(
|
46 |
base_url="https://openrouter.ai/api/v1",
|
47 |
api_key=key,
|
48 |
model=model
|
49 |
)
|
50 |
-
elif(provider == '
|
51 |
url = f"https://api.segmind.com/v1/{model}"
|
52 |
|
53 |
# Request payload
|
|
|
39 |
api_token = key.split('~')[1]
|
40 |
except:
|
41 |
raise Exception('Invalid Accound Id or api token')
|
42 |
+
import requests
|
43 |
+
API_BASE_URL = f"https://api.cloudflare.com/client/v4/accounts/{account_id}/ai/run/"
|
44 |
+
headers = {"Authorization": f"Bearer {api_token}"}
|
45 |
+
|
46 |
+
|
47 |
+
def run(model, inputs):
|
48 |
+
input = { "messages": inputs }
|
49 |
+
response = requests.post(f"{API_BASE_URL}{model}", headers=headers, json=input)
|
50 |
+
return response.json()
|
51 |
+
inputs = segmind_input_parser(conversation)
|
52 |
+
output = run("@cf/meta/llama-3-8b-instruct", inputs)
|
53 |
+
# print(output)
|
54 |
+
return {'content':output['result']['response']}
|
55 |
elif(provider == 'openrouter'):
|
56 |
chat = ChatOpenAI(
|
57 |
base_url="https://openrouter.ai/api/v1",
|
58 |
api_key=key,
|
59 |
model=model
|
60 |
)
|
61 |
+
elif(provider == 'segmind'):
|
62 |
url = f"https://api.segmind.com/v1/{model}"
|
63 |
|
64 |
# Request payload
|