Skip to content

Commit af6a8bb

Browse files
author
EliasPereirah
committed
Adding support for DeepSeek models
1 parent f0ffecb commit af6a8bb

File tree

4 files changed

+88
-150
lines changed

4 files changed

+88
-150
lines changed

README.md

+4-39
Original file line numberDiff line numberDiff line change
@@ -127,46 +127,11 @@ and the answer will be based on the context returning from the "rag endpoint"
127127
An advanced option for those using Google Gemini may be to use "Grounding with Google Search", this feature is not
128128
implemented here and has a cost of $35 / 1K grounding requests.
129129

130-
# Proxy
131-
To get around CORS errors when working with SambaNova a proxy may be necessary.
132-
133-
If you are using Orion via localhost or a hosting with PHP support, you can use the PHP proxy code available in this
134-
repository (`proxy.php` file) for this you will also need to add the following JavaScript code in plugins.
135-
136-
To do this, click on "Options" -> Plugins and paste the JavaScript code provided below:
137-
138-
139-
```javascript
140-
let proxy_url = window.location.origin + window.location.pathname + "/proxy.php";
141-
// ^^ This assumes the proxy URL is on the same host, otherwise enter it above. ^^
142-
if(chosen_platform === "sambanova" || chosen_platform === "nvidia"){
143-
endpoint = proxy_url+"?platform="+chosen_platform;
144-
}
145-
function setProxyEndpoint(event){
146-
if(chosen_platform === "sambanova" || chosen_platform === "nvidia"){
147-
let proxy_endpoint = proxy_url+"/proxy.php?platform="+chosen_platform;
148-
if(proxy_endpoint !== endpoint){
149-
endpoint = proxy_endpoint;
150-
removeLastMessage();
151-
}
152-
}
153-
}
154-
155-
156-
let button_send = document.querySelector("#send");
157-
chat_textarea.addEventListener('keyup', (event) => {
158-
if (event.key === 'Enter' && !event.shiftKey) {
159-
setProxyEndpoint();
160-
}
161-
});
162-
163-
button_send.addEventListener("click", ()=>{
164-
setProxyEndpoint()
165-
})
166-
```
130+
# Cors
131+
To get around CORS errors when working with SambaNova the API request will pass through `cors-proxy.php`
132+
which will forward the request to the desired platform. This will not hide your IP address, just forward the request.
167133

168-
Be careful when using any other proxy as sensitive data will be passed through it like your API key and messages.
169-
Use only trusted services.
134+
This is necessary because direct requests via JavaScript in the browser to these platform are not possible.
170135

171136
# YouTube Caption
172137
To enable AI responses based on YouTube video subtitles, set up an API endpoint to get them.

cors-proxy.php

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
## If you are going to make this file public on the internet, be sure to implement login restrictions.
4+
5+
//If you are using this script on a different host you will need to uncomment the lines below
6+
7+
/*
8+
header("Access-Control-Allow-Origin: *");
9+
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
10+
header("Access-Control-Allow-Headers: Content-Type, api-key, x-api-key, anthropic-version, anthropic-dangerous-direct-browser-access, Authorization");
11+
*/
12+
13+
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
14+
http_response_code(200);
15+
exit();
16+
}
17+
18+
// Note: This proxy code will use the IP address of where it is hosted, the purpose is not to mask or anonymize the user,
19+
// just to get rid of CORS errors.
20+
// GitHub Pages does not support PHP, so this proxy code will not work in such an environment.
21+
22+
/**
23+
* To get around CORS errors when working with SambaNova a proxy may be necessary.
24+
* This code is one of the possible solutions, for it to work you need to be running the code on localhost
25+
* or a hosting that supports PHP, this will not work on GitHub pages.
26+
*/
27+
28+
//ini_set('display_errors', 1);
29+
$endpoint = $_GET['endpoint'] ?? '';
30+
if (!filter_var($endpoint, FILTER_VALIDATE_URL)) {
31+
exit('Not a valid URL');
32+
}
33+
$post_data = file_get_contents('php://input');
34+
$ch = curl_init($endpoint);
35+
$received_headers = getallheaders();
36+
$headers_to_send = [];
37+
foreach ($received_headers as $key => $value) {
38+
if (strtolower($key) === "authorization") {
39+
$headers_to_send[] = "$key: $value";
40+
}
41+
}
42+
$headers_to_send[] = "Content-Type: application/json";
43+
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers_to_send);
44+
curl_setopt($ch, CURLOPT_POST, true);
45+
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
46+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
47+
$arr = json_decode($post_data);
48+
if (!empty($arr->stream)) {
49+
header('Content-Type: text/event-stream');
50+
}
51+
header('Cache-Control: no-cache');
52+
curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $data) {
53+
echo $data;
54+
ob_flush();
55+
flush();
56+
return strlen($data);
57+
});
58+
curl_exec($ch);
59+
curl_close($ch);
60+
exit();

js/script.js

+24-16
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ let js_code_exec_output = '';
2020
let original_code = '';
2121
let temp_safe_mode = false;
2222
let pre_function_text = '';
23-
let azure_endpoint = localStorage.getItem('azure_endpoint');
2423
let all_chunks = [];
2524
let has_chunk_error = false;
25+
let proxy_url = window.location.origin + window.location.pathname + "/cors-proxy.php";
2626

2727
// Markdown to HTML
2828
showdown.setFlavor('github');
@@ -45,14 +45,21 @@ let PLATFORM_DATA = {
4545
models: [
4646
"gemini-2.0-flash-exp",
4747
"gemini-exp-1206",
48-
"learnlm-1.5-pro-experimental",
4948
"gemini-1.5-pro",
5049
"gemini-1.5-flash",
5150
"gemini-1.5-flash-8b"
5251
],
5352
name: "Google",
5453
endpoint: 'https://generativelanguage.googleapis.com/v1beta/models/{{model}}:{{gen_mode}}?key={{api_key}}'
5554
},
55+
deepseek: {
56+
models: [
57+
"deepseek-reasoner",
58+
"deepseek-chat"
59+
],
60+
name: "DeepSeek",
61+
endpoint: "https://api.deepseek.com/chat/completions"
62+
},
5663
anthropic: {
5764
models: [
5865
"claude-3-5-sonnet-20241022",
@@ -90,6 +97,7 @@ let PLATFORM_DATA = {
9097
"Meta-Llama-3.1-405B-Instruct",
9198
"Llama-3.2-90B-Vision-Instruct"
9299
],
100+
needProxy: true,
93101
name: "SambaNova",
94102
endpoint: "https://api.sambanova.ai/v1/chat/completions"
95103

@@ -148,15 +156,6 @@ let PLATFORM_DATA = {
148156
}
149157

150158

151-
if (azure_endpoint) {
152-
PLATFORM_DATA.azure = {
153-
models: [
154-
"gpt-4o-mini"
155-
],
156-
name: "Azure",
157-
endpoint: azure_endpoint
158-
};
159-
}
160159

161160
const language_extension = {
162161
"python": "py",
@@ -617,7 +616,6 @@ function toggleAiGenAnimation(do_animate = 'toggle') {
617616
function chat() {
618617
toggleAiGenAnimation(true);
619618
if (chosen_platform === 'google') {
620-
// endpoint = "https://generativelanguage.googleapis.com/v1beta/openai/chat/completions";
621619
return geminiChat();
622620
}
623621
return streamChat();
@@ -1988,15 +1986,13 @@ async function streamChat(can_use_tools = true) {
19881986
if (chosen_platform !== 'anthropic') {
19891987
if (!cmd) {
19901988
if (!base64String) {
1991-
// Groq vision accept no system prompt??
19921989
all_parts.push(system_prompt);
19931990
}
19941991
}
19951992
}
19961993
}
19971994

19981995
conversations.messages.forEach(part => {
1999-
//let role = part.role === 'assistant' ? 'model' : part.role;
20001996
let cnt = part.content;
20011997
last_role = part.role;
20021998
last_cnt = part.content;
@@ -2147,6 +2143,8 @@ async function streamChat(can_use_tools = true) {
21472143
return false;
21482144
}
21492145

2146+
endpoint = getEndpoint();
2147+
21502148
try {
21512149
const response = await fetch(endpoint, requestOptions);
21522150
if (!response.ok) {
@@ -3150,6 +3148,18 @@ function loadUserAddedPrompts(){
31503148
loadUserAddedPrompts()
31513149

31523150

3151+
//Checks if it is necessary to pass the request via cors-proxy.php to get rid of cors and
3152+
// if so returns a new endpoint address
3153+
function getEndpoint(){
3154+
let needProxy = PLATFORM_DATA[chosen_platform]?.needProxy ?? false;
3155+
let endpoint = PLATFORM_DATA[chosen_platform]?.endpoint;
3156+
if(needProxy){
3157+
return `${proxy_url}?endpoint=${endpoint}`;
3158+
}
3159+
return endpoint;
3160+
}
3161+
3162+
31533163
function deletePrompt(){
31543164
let sl_prompt = document.querySelector("select[name=prompt]");
31553165
let selectedOption = sl_prompt.options[sl_prompt.selectedIndex];
@@ -3176,8 +3186,6 @@ function deletePrompt(){
31763186
}
31773187
}
31783188

3179-
3180-
31813189
selectedOption.remove();
31823190
console.log(selectedOption)
31833191
document.querySelector("textarea.system_prompt").value = '';

proxy.php

-95
This file was deleted.

0 commit comments

Comments
 (0)