-
-
Notifications
You must be signed in to change notification settings - Fork 401
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Packaged prism. * More exports, code cleanup to address eslint issues. * Refactoring. * Production with optimizations disabled. * Refactored some logic. * Refactoring. * Added vega. * More imports. * Updated.
- Loading branch information
1 parent
5f9ace4
commit 526fba1
Showing
16 changed files
with
2,911 additions
and
1,605 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
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,64 @@ | ||
import { | ||
BedrockRuntimeClient, | ||
InvokeModelCommand, | ||
} from "@aws-sdk/client-bedrock-runtime"; | ||
|
||
export async function sendPromptToAmazon(prompt) { | ||
const accessKeyId = | ||
document.getElementById("aws-access-key").value || | ||
localStorage.getItem("aws-access-key"); | ||
const secretAccessKey = | ||
document.getElementById("aws-secret-key").value || | ||
localStorage.getItem("aws-secret-key"); | ||
const region = | ||
document.getElementById("aws-region").value || | ||
localStorage.getItem("aws-region") || | ||
"us-east-1"; | ||
|
||
// Configure AWS Credentials | ||
const credentials = { | ||
accessKeyId: accessKeyId, | ||
secretAccessKey: secretAccessKey, | ||
}; | ||
|
||
// Initialize the Bedrock Runtime Client | ||
const client = new BedrockRuntimeClient({ | ||
region: region, | ||
credentials: credentials, | ||
}); | ||
|
||
const params = { | ||
"modelId": "us.anthropic.claude-3-5-sonnet-20241022-v2:0", | ||
"body": JSON.stringify({ | ||
"anthropic_version": "bedrock-2023-05-31", | ||
"max_tokens": 65536, // arbitrary large number | ||
"messages": [ | ||
{ | ||
"role": "user", | ||
"content": [ | ||
{ | ||
"type": "text", | ||
"text": prompt | ||
} | ||
] | ||
} | ||
] | ||
}) | ||
} | ||
|
||
try { | ||
const command = new InvokeModelCommand(params); | ||
const response = await client.send(command); | ||
|
||
// Convert the response body to text | ||
const responseBlob = new Blob([response.body]); | ||
const responseText = await responseBlob.text(); | ||
const parsedResponse = JSON.parse(responseText); | ||
const responseContents = parsedResponse.content[0].text; | ||
|
||
return responseContents.trim(); | ||
} catch (err) { | ||
console.error(err); | ||
return `# Error: ${err.message}`; | ||
} | ||
} |
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,62 @@ | ||
export async function sendPromptToAzureOpenAI(prompt, apiKey, apiUrl, aiModel) { | ||
const apiVersion = document.getElementById("azure-api-model-version").value; | ||
const endpoint = `${apiUrl}/openai/deployments/${aiModel}/chat/completions?api-version=${apiVersion}`; | ||
|
||
const body = JSON.stringify({ | ||
messages: [ | ||
{ | ||
role: "system", | ||
content: | ||
"You are a Python programming assistant who ONLY responds with blocks of commented, optimized code. You never respond with text. Just code, starting with ``` and ending with ```.", | ||
}, | ||
{ | ||
role: "user", | ||
content: prompt, | ||
}, | ||
], | ||
user: "scalene-user", | ||
}); | ||
|
||
console.log(body); | ||
|
||
const response = await fetch(endpoint, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"api-key": apiKey, | ||
}, | ||
body: body, | ||
}); | ||
|
||
const data = await response.json(); | ||
if (data.error) { | ||
if ( | ||
data.error.code in | ||
{ | ||
invalid_request_error: true, | ||
model_not_found: true, | ||
insufficient_quota: true, | ||
} | ||
) { | ||
return ""; | ||
} | ||
} | ||
try { | ||
console.log( | ||
`Debugging info: Retrieved ${JSON.stringify(data.choices[0], null, 4)}`, | ||
); | ||
} catch { | ||
console.log( | ||
`Debugging info: Failed to retrieve data.choices from the server. data = ${JSON.stringify( | ||
data, | ||
)}`, | ||
); | ||
} | ||
|
||
try { | ||
return data.choices[0].message.content.replace(/^\s*[\r\n]/gm, ""); | ||
} catch { | ||
// return "# Query failed. See JavaScript console (in Chrome: View > Developer > JavaScript Console) for more info.\n"; | ||
return "# Query failed. See JavaScript console (in Chrome: View > Developer > JavaScript Console) for more info.\n"; | ||
} | ||
} |
Oops, something went wrong.