Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 31 additions & 11 deletions settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,25 @@ import {

export enum SettingEnum {
ID_LLM_PROVIDER = `llm-provider`,

ID_GROQ_API_KEY = `groq-model`,
ID_GROQ_MODEL = `groq-api-key`,

ID_GEMINI_MODEL = `gemini-model`,
ID_GEMINI_API_KEY = `gemini-api-key`,


ID_RC_MODEL = `rc-model`,
ID_RC_AUTH_TOKEN = `rc-auth-token`,
ID_RC_USER_ID = `rc-user-id`,

KEY_GROQ = `groq`,
KEY_GEMINI = `gemini`,
KEY_RC = `rocketchat`,
}



export const settings: ISetting[] = [
{
id: SettingEnum.ID_LLM_PROVIDER,
Expand Down Expand Up @@ -50,6 +57,19 @@ export const settings: ISetting[] = [
i18nLabel: "Groq API Key (required for Groqcloud)",
i18nPlaceholder: "Groq API Key",
},


{
id: SettingEnum.ID_GEMINI_MODEL,
type: SettingType.STRING,
packageValue: "",
required: false,
public: false,
i18nLabel: "Gemini Model (required for Google AI Studio)",
i18nPlaceholder: "e.g. gemini-2.5-flash, gemini-1.5-pro",
},


{
id: SettingEnum.ID_GEMINI_API_KEY,
type: SettingType.PASSWORD,
Expand All @@ -74,21 +94,21 @@ export const settings: ISetting[] = [
},
{
id: SettingEnum.ID_RC_AUTH_TOKEN,
i18nLabel:
"Personal Access Token (required for In House (Rocket Chat))",
i18nLabel: "Personal Access Token (required for In House (Rocket Chat))",
i18nDescription: "Must be filled to enable file summary add-on",
type: SettingType.PASSWORD,
required: false,
public: false,
packageValue: "",
},
{
id: SettingEnum.ID_RC_USER_ID,
i18nLabel: "User ID (required for In House (Rocket Chat))",
i18nDescription: "Must be filled to enable file summary add-on",
type: SettingType.STRING,
required: false,
public: false,
packageValue: "",
},
{
id: SettingEnum.ID_RC_USER_ID,
i18nLabel: "User ID (required for In House (Rocket Chat))",
i18nDescription: "Must be filled to enable file summary add-on",
type: SettingType.STRING,
required: false,
public: false,
packageValue: "",
},

];
39 changes: 26 additions & 13 deletions utils/GeminiModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,45 @@ export async function createTextCompletionGemini(
throw new Error("geminiApiKey not configured.");
}

const url = `https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=${geminiApiKey}`;
const geminiModel = await read
.getEnvironmentReader()
.getSettings()
.getValueById(SettingEnum.ID_GEMINI_MODEL);

if (!geminiModel) {
throw new Error("geminiModel not configured.");
}

const url = `https://generativelanguage.googleapis.com/v1beta/models/${geminiModel}:generateContent?key=${geminiApiKey}`;

const body = {
contents: [{ parts: [{ text: prompt }] }],
};

const response = await http.post(url, {
headers: { "Content-Type": "application/json" },
headers: {
"Content-Type": "application/json",
},
content: JSON.stringify(body),
});

if (response.statusCode !== 200 || !response.content) {
return JSON.stringify({
message:
"Sorry! I was unable to process your request. Please try again.",
});
throw new Error(
"Sorry! I was unable to process your request. Please try again."
);
}

let text = JSON.parse(response.content)?.candidates?.[0]?.content
?.parts?.[0]?.text;
let text =
JSON.parse(response.content)?.candidates?.[0]?.content?.parts?.[0]
?.text;

if (!text) {
throw new Error("Empty response from Gemini");
}

// Clean up the response if it's wrapped in markdown code blocks
if (text.startsWith("```json") && text.endsWith("```")) {
text = text.slice(7, -3).trim(); // Remove ```json and ```
} else if (text.startsWith("```") && text.endsWith("```")) {
text = text.slice(3, -3).trim(); // Remove ``` and ```
// Remove markdown wrappers if present
if (text.startsWith("```") && text.endsWith("```")) {
text = text.replace(/^```[a-z]*\n?|```$/g, "").trim();
}

return text;
Expand Down