Skip to content

Commit

Permalink
chore: hardcode bot name
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Sep 26, 2024
1 parent 48faffb commit 5076ec8
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ plugins:
- uses:
- plugin: http://localhost:4000
with:
# Use your own app name for local testing
ubiquityOsAppSlug: "UbiquityOS"
model: ""
openAiBaseUrl: ""
```
`.dev.vars` (for local testing):

```sh
# OpenAI API key
OPENAI_API_KEY=your-api-key
UBIQUITY_OS_APP_SLUG="UbiquityOS"
```

## Testing
Expand Down
5 changes: 3 additions & 2 deletions src/handlers/ask-gpt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ 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);

logger.info(`Sending chat to OpenAI`, { chat });

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;
Expand Down
4 changes: 2 additions & 2 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
1 change: 1 addition & 0 deletions src/types/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/types/plugin-inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export interface PluginInputs<T extends SupportedEventsU = SupportedEventsU, TU
*/

export const pluginSettingsSchema = T.Object({
ubiquityOsAppSlug: T.String(),
model: T.Optional(T.String({ default: "o1-mini" })),
openAiBaseUrl: T.Optional(T.String({ default: "" })),
});

export const pluginSettingsValidator = new StandardValidator(pluginSettingsSchema);
Expand Down
5 changes: 2 additions & 3 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,9 @@ function createContext(body = TEST_SLASH_COMMAND) {
organization: { login: "ubiquity" } as unknown as Context["payload"]["organization"],
},
logger: new Logs("debug"),
config: {
ubiquityOsAppSlug: "UbiquityOS",
},
config: {},
env: {
UBIQUITY_OS_APP_SLUG: "UbiquityOS",
OPENAI_API_KEY: "test",
},
octokit: new octokit.Octokit(),
Expand Down

0 comments on commit 5076ec8

Please sign in to comment.