diff --git a/README.md b/README.md index ac69d4e..e74704e 100644 --- a/README.md +++ b/README.md @@ -21,8 +21,8 @@ plugins: - uses: - plugin: http://localhost:4000 with: - # Use your own app name for local testing - ubiquityOsAppSlug: "UbiquityOS" + model: "" + openAiBaseUrl: "" ``` `.dev.vars` (for local testing): @@ -30,6 +30,8 @@ plugins: ```sh # OpenAI API key OPENAI_API_KEY=your-api-key +UBIQUITY_OS_APP_SLUG="UbiquityOS" + ``` ## Testing diff --git a/src/handlers/ask-gpt.ts b/src/handlers/ask-gpt.ts index fe3101e..f537da4 100644 --- a/src/handlers/ask-gpt.ts +++ b/src/handlers/ask-gpt.ts @@ -18,9 +18,10 @@ export async function askGpt(context: Context, formattedChat: string) { const { logger, env: { OPENAI_API_KEY }, + config: { model, openAiBaseUrl }, } = context; - const openAi = new OpenAI({ apiKey: OPENAI_API_KEY }); + const openAi = new OpenAI({ apiKey: OPENAI_API_KEY, baseURL: openAiBaseUrl }); const chat = createChatHistory(formattedChat); @@ -28,7 +29,7 @@ export async function askGpt(context: Context, formattedChat: string) { const res: OpenAI.Chat.Completions.ChatCompletion = await openAi.chat.completions.create({ messages: createChatHistory(formattedChat), - model: "chatgpt-4o-latest", + model: model ?? "o1-mini", }); const answer = res.choices[0].message.content; diff --git a/src/plugin.ts b/src/plugin.ts index 680245d..f89c894 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -24,11 +24,11 @@ export async function plugin(inputs: PluginInputs, env: Env) { export async function runPlugin(context: Context) { const { logger, - config: { ubiquityOsAppSlug }, + env: { UBIQUITY_OS_APP_SLUG }, } = context; const question = context.payload.comment.body; - const slugRegex = new RegExp(`@${ubiquityOsAppSlug} `, "gi"); + const slugRegex = new RegExp(`@${UBIQUITY_OS_APP_SLUG} `, "gi"); if (!question.match(slugRegex)) { logger.info("Comment does not mention the app. Skipping."); diff --git a/src/types/env.ts b/src/types/env.ts index eef600a..e8a5f7b 100644 --- a/src/types/env.ts +++ b/src/types/env.ts @@ -13,6 +13,7 @@ dotenv.config(); */ export const envSchema = T.Object({ OPENAI_API_KEY: T.String(), + UBIQUITY_OS_APP_SLUG: T.String(), }); export const envValidator = new StandardValidator(envSchema); diff --git a/src/types/plugin-inputs.ts b/src/types/plugin-inputs.ts index 78c05a3..a574032 100644 --- a/src/types/plugin-inputs.ts +++ b/src/types/plugin-inputs.ts @@ -20,7 +20,8 @@ export interface PluginInputs