Bjo53 commited on
Commit
88592af
·
verified ·
1 Parent(s): 8abe73d

Update RADISON.py

Browse files
Files changed (1) hide show
  1. RADISON.py +101 -0
RADISON.py CHANGED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ import requests
3
+ import os
4
+ import time
5
+ import uuid
6
+
7
+ app = Flask(__name__)
8
+
9
+ # --- CONFIGURATION ---
10
+ # We look for the secret key named "ONYX_SECRET" in the Space Settings.
11
+ # This way, Hiren can set it privately.
12
+ ONYX_URL = "https://cloud.onyx.app/api/chat/send-chat-message"
13
+ API_KEY = os.environ.get("ONYX_SECRET")
14
+
15
+ @app.route('/')
16
+ def home():
17
+ if not API_KEY:
18
+ return "Server is running, but waiting for Hiren to set the ONYX_SECRET in Settings."
19
+ return "Server is Online and Connected to Onyx!"
20
+
21
+ # This makes it compatible with OpenAI apps
22
+ @app.route('/v1/chat/completions', methods=['POST'])
23
+ def chat_proxy():
24
+ # 1. Get the message from the user
25
+ data = request.json
26
+
27
+ # If no message sent, error out
28
+ if not data or 'messages' not in data:
29
+ return jsonify({"error": "No messages provided"}), 400
30
+
31
+ # Get the last message the user typed
32
+ user_input = data['messages'][-1]['content']
33
+
34
+ # --- BELOW IS HIREN'S EXACT CODE LOGIC ---
35
+ # We just replaced "Hi" with user_input
36
+ payload = {
37
+ "message": user_input,
38
+ "llm_override": {
39
+ "model_provider": "OpenAI",
40
+ "model_version": "gpt-5.2",
41
+ "temperature": data.get('temperature', 0.7) # Use user's temperature or default
42
+ },
43
+ "allowed_tool_ids": [123],
44
+ "forced_tool_id": 123,
45
+ "file_descriptors": [],
46
+ "internal_search_filters": {
47
+ "source_type": ["ingestion_api"],
48
+ "document_set": ["<string>"],
49
+ "time_cutoff": "2023-11-07T05:31:56Z",
50
+ "tags": [{"tag_key": "<string>", "tag_value": "<string>"}]
51
+ },
52
+ "deep_research": False,
53
+ "origin": "unset",
54
+ "parent_message_id": -1,
55
+ "chat_session_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
56
+ "chat_session_info": {
57
+ "persona_id": 0,
58
+ "description": "<string>",
59
+ "project_id": 123
60
+ },
61
+ "stream": False,
62
+ "include_citations": True
63
+ }
64
+
65
+ headers = {
66
+ "Authorization": API_KEY, # This uses the key Hiren will set
67
+ "Content-Type": "application/json"
68
+ }
69
+
70
+ try:
71
+ # Send to Onyx
72
+ response = requests.post(ONYX_URL, json=payload, headers=headers)
73
+
74
+ # Check if Onyx worked
75
+ if response.status_code == 200:
76
+ # We assume Onyx returns the text directly in the body
77
+ bot_text = response.text
78
+
79
+ # Format it so it looks like OpenAI (Required for "OpenAI Compatible")
80
+ return jsonify({
81
+ "id": f"chatcmpl-{uuid.uuid4()}",
82
+ "object": "chat.completion",
83
+ "created": int(time.time()),
84
+ "model": "gpt-5.2",
85
+ "choices": [{
86
+ "index": 0,
87
+ "message": {
88
+ "role": "assistant",
89
+ "content": bot_text
90
+ },
91
+ "finish_reason": "stop"
92
+ }]
93
+ })
94
+ else:
95
+ return jsonify({"error": f"Onyx Error: {response.text}"}), response.status_code
96
+
97
+ except Exception as e:
98
+ return jsonify({"error": str(e)}), 500
99
+
100
+ if __name__ == '__main__':
101
+ app.run(host='0.0.0.0', port=7860)