-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b842bd
commit be120cc
Showing
14 changed files
with
1,990 additions
and
728 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
CONSOLE_LOGGING=false # set to true to enable console logging | ||
HTTP_ENABLED=true # set to true to enable HTTP | ||
HTTP_PORT=88 # only used if HTTP_ENABLED=true | ||
MAX_REQUEST_BODY_SIZE=50mb # maximum size for request body (for handling base64 images) | ||
HTTPS_ENABLED=false # set to true to enable HTTPS | ||
HTTPS_PORT=443 # only used if HTTPS_ENABLED=true | ||
HTTPS_KEY_PATH=./some-path/mykey.key # or privkey.pem | ||
HTTPS_CERT_PATH=./some-path/mycert.pem # or fullchain.pem | ||
IP_RATE_LIMIT_ENABLED=true # enable rate limiting by IP | ||
IP_RATE_LIMIT_WINDOW_MS=60000 # window in milliseconds to limit requests | ||
IP_RATE_LIMIT_MAX_REQUESTS=100 # limit each IP to X requests per set window |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
/.vscode | ||
/node_modules | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
AWS_REGION=us-west-2 # AWS Region | ||
AWS_ACCESS_KEY_ID=AKIAWSxxxxxxxxxxxxxx # AWS Access Key ID | ||
AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxx # AWS Secret Access Key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import OpenAI from 'openai'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import dotenv from 'dotenv'; | ||
|
||
dotenv.config(); | ||
const { AWS_REGION, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY } = process.env; | ||
|
||
const __dirname = path.resolve(); | ||
const base64Image = fs.readFileSync(path.join(__dirname, 'lizard.jpg')).toString('base64'); | ||
const messages = [ | ||
{ | ||
role: "system", | ||
content: "You are a helpful AI assistant that follows instructions extremely well. Answer the user questions accurately.", | ||
}, | ||
{ | ||
role: "user", | ||
content: [ | ||
{ | ||
type: "text", | ||
text: "What's in this image? Please describe it in detail." | ||
}, | ||
{ | ||
type: "image_url", | ||
image_url: { | ||
url: `data:image/jpeg;base64,${base64Image}` | ||
// url: "/~https://github.com/jparkerweb/ref/blob/main/equill-labs/bedrock-proxy-endpoint/bedrock-proxy-endpoint.png?raw=true" | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
role: "assistant", | ||
content: "", | ||
}, | ||
]; | ||
|
||
const baseURL = "http://localhost:88"; // URL of the Bedrock Proxy Endpoint | ||
const apiKey = `${AWS_REGION}.${AWS_ACCESS_KEY_ID}.${AWS_SECRET_ACCESS_KEY}` // Your AWS Creds / API Key | ||
|
||
const openai = new OpenAI({ | ||
baseURL: baseURL, | ||
apiKey: apiKey, | ||
}); | ||
|
||
async function main() { | ||
try { | ||
const chatCompletion = await openai.chat.completions.create({ | ||
messages: messages, | ||
model: "Claude-3-7-Sonnet-Thinking", | ||
max_tokens: 2048, | ||
temperature: 0.4, | ||
top_p: 0.7, | ||
stream: true, | ||
}); | ||
|
||
if (chatCompletion) { | ||
for await (const chunk of chatCompletion) { | ||
const response = chunk.choices[0]?.delta?.content || ""; | ||
process.stdout.write(response); | ||
} | ||
// Add a newline at the end for cleaner output | ||
process.stdout.write('\n'); | ||
} | ||
} catch (error) { | ||
console.error('Error:', error); | ||
} finally { | ||
// Explicitly exit the process when done | ||
process.exit(0); | ||
} | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import OpenAI from 'openai'; | ||
import dotenv from 'dotenv'; | ||
|
||
dotenv.config(); | ||
const { AWS_REGION, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY } = process.env; | ||
|
||
const messages = [ | ||
{ | ||
role: "system", | ||
content: "You are a helpful AI assistant that follows instructions extremely well. Answer the user questions accurately.", | ||
}, | ||
{ | ||
role: "user", | ||
content: "Describe why the OpenAI API standard is so great. Limit your response to five sentences.", | ||
}, | ||
{ | ||
role: "assistant", | ||
content: "", | ||
}, | ||
]; | ||
|
||
const baseURL = "http://localhost:88"; // URL of the Bedrock Proxy Endpoint | ||
const apiKey = `${AWS_REGION}.${AWS_ACCESS_KEY_ID}.${AWS_SECRET_ACCESS_KEY}` // Your AWS Creds / API Key | ||
|
||
const openai = new OpenAI({ | ||
baseURL: baseURL, | ||
apiKey: apiKey, | ||
}); | ||
|
||
async function main() { | ||
try { | ||
const chatCompletion = await openai.chat.completions.create({ | ||
messages: messages, | ||
model: "Claude-3-7-Sonnet-Thinking", | ||
max_tokens: 2048, | ||
temperature: 0.4, | ||
top_p: 0.7, | ||
stream: true, | ||
include_thinking_data: true, | ||
}); | ||
|
||
if (chatCompletion) { | ||
for await (const chunk of chatCompletion) { | ||
const response = chunk.choices[0]?.delta?.content || ""; | ||
process.stdout.write(response); | ||
} | ||
// Add a newline at the end for cleaner output | ||
process.stdout.write('\n'); | ||
} | ||
} catch (error) { | ||
console.error('Error:', error); | ||
} finally { | ||
// Explicitly exit the process when done | ||
process.exit(0); | ||
} | ||
} | ||
|
||
main(); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.