Skip to content

Commit

Permalink
Update package version to 0.0.2 better localstorage handling
Browse files Browse the repository at this point in the history
  • Loading branch information
eltorio committed Sep 27, 2024
1 parent 8841c52 commit f732bd4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sctg-ai-pane",
"version": "0.0.1",
"version": "0.0.2",
"repository": {
"type": "git",
"url": "https://github.com/OfficeDev/Office-Addin-TaskPane-React.git"
Expand Down
9 changes: 4 additions & 5 deletions src/aipane/aipane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
=========================================================
*/
import { Groq } from "groq-sdk";
const GROP_API_KEY = localStorage.getItem("apiKey");
const groq = new Groq({ apiKey: GROP_API_KEY, dangerouslyAllowBrowser: true });

async function groqRequest(model: string, text: string): Promise<string> {
async function groqRequest(model: string, apiKey: string, text: string): Promise<string> {
const groq = new Groq({ apiKey, dangerouslyAllowBrowser: true });
const chatCompletion = await groq.chat.completions.create({
messages: [
{
Expand All @@ -26,11 +25,11 @@ async function groqRequest(model: string, text: string): Promise<string> {
return chatCompletion.choices[0]?.message?.content || "";
}

export async function insertText(model: string, text: string) {
export async function insertText(model: string, apiKey: string, text: string) {
// Write text to the cursor point in the compose surface.
try {
console.log("Prompt text: \n" + text);
let aiText = await groqRequest(model, text);
let aiText = await groqRequest(model, apiKey, text);
console.log(`AI response (${model}): \n${aiText}`);
aiText = aiText.replace(/\n/g, "<br>");
Office.context.mailbox.item?.body.setSelectedDataAsync(
Expand Down
5 changes: 3 additions & 2 deletions src/aipane/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ const App: React.FC<AppProps> = (props: AppProps) => {
setModel(newValue);
}

const handlePromptSubmit = (text:string) => {
insertText(model, `${prompt}\n${text}`);
const handlePromptSubmit = (text: string) => {
const apiKey = localStorage.getItem("apiKey");
insertText(model, apiKey, `${prompt}\n${text}`);
};

return (
Expand Down

0 comments on commit f732bd4

Please sign in to comment.