Spaces:
Running
Running
basic function works great. failed to get response to AI. the api address and stuff is well here is an example back end: use whatever u think I'm. jot saying use this exactly im just adding reference. ;from flask import Flask, request, jsonify import requests app = Flask(__name__) # Replace with your actual Kindroid API Key and AI Endpoint KINDROID_API_KEY = "kn_7bc38d83-131f-42f4-bd09-25fe6652c159" KINDROID_AI_ID = "ckcUIfqAVX8kcsIj2tNH" # Add your AI ID here KINDROID_API_ENDPOINT = "https://api.kindroid.ai/v1/send-message" @app .route('/ask_kindroid', methods=['POST']) def ask_kindroid(): data = request.get_json() message = data.get('message') if not message: return jsonify({"error": "Message is required"}), 400 headers = { 'Authorization': f'Bearer {KINDROID_API_KEY}', 'Content-Type': 'application/json' } payload = { 'ai_id': KINDROID_AI_ID, 'message': message } try: response = requests.post(KINDROID_API_ENDPOINT, headers=headers, json=payload) response.raise_for_status() # Raise an exception for bad status codes kindroid_data = response.json() # The 'reply' field seems likely, but check Kindroid API documentation if different kindroid_reply = kindroid_data.get('reply', kindroid_data.get('response', 'No response received from Kindroid.')) return jsonify({"response": kindroid_reply}) except requests.exceptions.RequestException as e: return jsonify({"error": f"Error communicating with Kindroid AI: {e}"}), 500 if __name__ == '__main__': app.run(debug=True) - Follow Up Deployment
Browse files- index.html +20 -12
index.html
CHANGED
@@ -362,9 +362,8 @@
|
|
362 |
</div>
|
363 |
|
364 |
<script>
|
365 |
-
// Kindroid
|
366 |
-
const
|
367 |
-
const kindroidId = 'ckcUIfqAVX8kcsIj2tNH';
|
368 |
|
369 |
// Server credentials
|
370 |
const serverCreds = {
|
@@ -406,27 +405,36 @@
|
|
406 |
}
|
407 |
}
|
408 |
|
409 |
-
// Send message to Kindroid
|
410 |
async function sendToKindroid(message) {
|
411 |
try {
|
412 |
-
const response = await fetch('
|
413 |
method: 'POST',
|
414 |
headers: {
|
415 |
-
'Content-Type': 'application/json'
|
416 |
-
'Authorization': `Bearer ${kindroidApiKey}`
|
417 |
},
|
418 |
body: JSON.stringify({
|
419 |
-
|
420 |
-
message: message,
|
421 |
-
context: 'satanic_chat'
|
422 |
})
|
423 |
});
|
424 |
|
|
|
|
|
|
|
|
|
425 |
const data = await response.json();
|
426 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
427 |
} catch (error) {
|
428 |
console.error('Kindroid API error:', error);
|
429 |
-
return "
|
430 |
}
|
431 |
}
|
432 |
|
|
|
362 |
</div>
|
363 |
|
364 |
<script>
|
365 |
+
// Kindroid Endpoint (relative to our domain)
|
366 |
+
const kindroidEndpoint = '/ask_kindroid';
|
|
|
367 |
|
368 |
// Server credentials
|
369 |
const serverCreds = {
|
|
|
405 |
}
|
406 |
}
|
407 |
|
408 |
+
// Send message to Kindroid via proxy
|
409 |
async function sendToKindroid(message) {
|
410 |
try {
|
411 |
+
const response = await fetch('/ask_kindroid', {
|
412 |
method: 'POST',
|
413 |
headers: {
|
414 |
+
'Content-Type': 'application/json'
|
|
|
415 |
},
|
416 |
body: JSON.stringify({
|
417 |
+
message: message
|
|
|
|
|
418 |
})
|
419 |
});
|
420 |
|
421 |
+
if (!response.ok) {
|
422 |
+
throw new Error(`HTTP error! status: ${response.status}`);
|
423 |
+
}
|
424 |
+
|
425 |
const data = await response.json();
|
426 |
+
|
427 |
+
// Handle both direct API and proxy response formats
|
428 |
+
if (data.response) {
|
429 |
+
return data.response;
|
430 |
+
} else if (data.reply) {
|
431 |
+
return data.reply;
|
432 |
+
} else {
|
433 |
+
return "I received your message but couldn't generate a response.";
|
434 |
+
}
|
435 |
} catch (error) {
|
436 |
console.error('Kindroid API error:', error);
|
437 |
+
return "Sorry, I'm having trouble responding right now. Please try again later.";
|
438 |
}
|
439 |
}
|
440 |
|