Skip to content

Commit

Permalink
feat: adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
whilefoo committed Sep 23, 2023
1 parent f41c036 commit 3056bc9
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 58 deletions.
16 changes: 0 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,22 +224,6 @@ Bounty bot is built using the [probot](https://probot.github.io/) framework so i
├── <a href="https://github.com/ubiquity/ubiquibot/tree/development/src/utils">utils</a> A set of utility functions
</pre>

## Default Config Notes (`ubiquibot-config-default.ts`)

We can't use a `jsonc` file due to limitations with Netlify. Here is a snippet of some values with notes next to them.

```jsonc
{
"payment-permit-max-price": 9007199254740991, // Number.MAX_SAFE_INTEGER
"max-concurrent-assigns": 9007199254740991, // Number.MAX_SAFE_INTEGER
"comment-element-pricing": {
/* https://github.com/syntax-tree/mdast#nodes */
"strong": 0 // Also includes italics, unfortunately https://github.com/syntax-tree/mdast#strong
/* https://github.com/syntax-tree/mdast#gfm */
}
}
```

## Supabase Cron Job (`logs-cleaner`)

##### Dashboard > Project > Database > Extensions
Expand Down
30 changes: 27 additions & 3 deletions src/configs/ubiquibot-config-default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export const DefaultConfig: MergedConfig = {
evmNetworkId: 100,
priceMultiplier: 1,
issueCreatorMultiplier: 2,
paymentPermitMaxPrice: 9007199254740991,
maxConcurrentAssigns: 9007199254740991,
paymentPermitMaxPrice: Number.MAX_SAFE_INTEGER,
maxConcurrentAssigns: Number.MAX_SAFE_INTEGER,
assistivePricing: false,
disableAnalytics: false,
commentIncentives: false,
Expand Down Expand Up @@ -87,7 +87,31 @@ export const DefaultConfig: MergedConfig = {
],
incentives: {
comment: {
elements: {},
elements: {
h1: 0,
h2: 0,
h3: 0,
h4: 0,
h5: 0,
h6: 0,
a: 0,
ul: 0,
li: 0,
p: 0,
img: 0,
code: 0,
table: 0,
td: 0,
tr: 0,
br: 0,
blockquote: 0,
em: 0,
strong: 0,
hr: 0,
del: 0,
pre: 0,
ol: 0,
},
totals: {
word: 0,
},
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/comment/handlers/ask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const ask = async (body: string) => {
}

if (!issue) {
return `This command can only be used on issues`;
return `This command can only be used on issues on pull requests`;
}

const chatHistory: CreateChatCompletionRequestMessage[] = [];
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/comment/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ export const userCommands = (): UserCommands[] => {
},
{
id: IssueCommentCommands.ASK,
description: `Ask a technical question to the Ubiquity AI. \n example usage: "/ask How do I do X?"`,
description: `Ask a technical question to the UbiquiBot. \n example usage: "/ask How do I do X?"`,
handler: ask,
callback: commandCallback,
},
Expand Down
64 changes: 46 additions & 18 deletions src/handlers/comment/handlers/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,51 @@ export const tableComment = ({
days?: number;
}) => {
return `
<code>
<table>
${
isBountyStale
? `<tr><td>Warning!</td> <td>This task was created over ${days} days ago. Please confirm that this issue specification is accurate before starting.</td></tr>`
: ``
}
<tr>
<td>Deadline</td>
<td>${deadline}</td>
</tr>
<tr>
<td>Registered Wallet</td>
<td>${wallet}</td>
</tr>
${multiplier ? `<tr><td>Payment Multiplier</td><td>${multiplier}</td></tr>` : ``}
${reason ? `<tr><td>Multiplier Reason</td><td>${reason}</td></tr>` : ``}
${bounty ? `<tr><td>Total Bounty</td><td>${bounty}</td></tr>` : ``}
</table></code>`;
${
isBountyStale
? `
<tr>
<td>Warning!</td>
<td>This task was created over ${days} days ago. Please confirm that this issue specification is accurate before starting.</td>
</tr>`
: ``
}
<tr>
<td>Deadline</td>
<td>${deadline}</td>
</tr>
<tr>
<td>Registered Wallet</td>
<td>${wallet}</td>
</tr>
${
multiplier
? `
<tr>
<td>Payment Multiplier</td>
<td>${multiplier}</td>
</tr>`
: ``
}
${
reason
? `
<tr>
<td>Multiplier Reason</td>
<td>${reason}</td>
</tr>`
: ``
}
${
bounty
? `
<tr>
<td>Total Bounty</td>
<td>${bounty}</td>
</tr>`
: ``
}
</table>
`;
};
4 changes: 2 additions & 2 deletions src/handlers/push/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getBotContext, getLogger } from "../../bindings";
import { createCommitComment, getFileContent } from "../../helpers";
import { CommitsPayload, PushPayload, WideConfigSchema } from "../../types";
import { CommitsPayload, PushPayload, ConfigSchema } from "../../types";
import { parseYAML } from "../../utils/private";
import { updateBaseRate } from "./update-base";
import { validate } from "../../utils/ajv";
Expand Down Expand Up @@ -87,7 +87,7 @@ export const validateConfigChange = async () => {
if (configFileContent) {
const decodedConfig = Buffer.from(configFileContent, "base64").toString();
const config = parseYAML(decodedConfig);
const { valid, error } = validate(WideConfigSchema, config);
const { valid, error } = validate(ConfigSchema, config);
if (!valid) {
await createCommitComment(`@${payload.sender.login} Config validation failed! ${error}`, commitSha, BASE_RATE_FILE);
}
Expand Down
10 changes: 5 additions & 5 deletions src/helpers/gpt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import OpenAI from "openai";
import { CreateChatCompletionRequestMessage } from "openai/resources/chat";
import { ErrorDiff } from "../utils/helpers";

export const sysMsg = `You are the UbiquityAI, designed to provide accurate technical answers. \n
export const sysMsg = `You are the UbiquiBot, designed to provide accurate technical answers. \n
Whenever appropriate, format your response using GitHub Flavored Markdown. Utilize tables, lists, and code blocks for clear and organized answers. \n
Do not make up answers. If you are unsure, say so. \n
Original Context exists only to provide you with additional information to the current question, use it to formulate answers. \n
Expand All @@ -14,7 +14,7 @@ All replies MUST end with "\n\n <!--- { 'UbiquityAI': 'answer' } ---> ".\n
`;

export const gptContextTemplate = `
You are the UbiquityAI, designed to review and analyze pull requests.
You are the UbiquiBot, designed to review and analyze pull requests.
You have been provided with the spec of the issue and all linked issues or pull requests.
Using this full context, Reply in pure JSON format, with the following structure omitting irrelvant information pertaining to the specification.
You MUST provide the following structure, but you may add additional information if you deem it relevant.
Expand Down Expand Up @@ -118,17 +118,17 @@ export const decideContextGPT = async (
{
role: "system",
content: "This issue/Pr context: \n" + JSON.stringify(streamlined),
name: "UbiquityAI",
name: "UbiquiBot",
} as CreateChatCompletionRequestMessage,
{
role: "system",
content: "Linked issue(s) context: \n" + JSON.stringify(linkedIssueStreamlined),
name: "UbiquityAI",
name: "UbiquiBot",
} as CreateChatCompletionRequestMessage,
{
role: "system",
content: "Linked Pr(s) context: \n" + JSON.stringify(linkedPRStreamlined),
name: "UbiquityAI",
name: "UbiquiBot",
} as CreateChatCompletionRequestMessage
);

Expand Down
6 changes: 2 additions & 4 deletions src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export const GPTResponseSchema = Type.Object({

export type GPTResponse = Static<typeof GPTResponseSchema>;

export const WideConfigSchema = Type.Object(
export const ConfigSchema = Type.Object(
{
evmNetworkId: Type.Optional(Type.Number()),
priceMultiplier: Type.Optional(Type.Number()),
Expand Down Expand Up @@ -199,9 +199,7 @@ export const WideConfigSchema = Type.Object(
}
);

export type WideConfig = Static<typeof WideConfigSchema>;

export type WideRepoConfig = WideConfig;
export type Config = Static<typeof ConfigSchema>;

export const MergedConfigSchema = Type.Object({
evmNetworkId: Type.Number(),
Expand Down
16 changes: 8 additions & 8 deletions src/utils/private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import merge from "lodash/merge";

import { DefaultConfig } from "../configs";
import { validate } from "./ajv";
import { WideConfig, WideRepoConfig, WideConfigSchema } from "../types";
import { Config, ConfigSchema } from "../types";

const CONFIG_REPO = "ubiquibot-config";
const CONFIG_PATH = ".github/ubiquibot-config.yml";
Expand Down Expand Up @@ -34,12 +34,12 @@ export const getConfigSuperset = async (context: Context, type: "org" | "repo",
};

export interface MergedConfigs {
parsedRepo: WideRepoConfig | undefined;
parsedOrg: WideRepoConfig | undefined;
parsedRepo: Config | undefined;
parsedOrg: Config | undefined;
parsedDefault: MergedConfig;
}

export const parseYAML = (data?: string): WideConfig | undefined => {
export const parseYAML = (data?: string): Config | undefined => {
try {
if (data) {
const parsedData = YAML.parse(data);
Expand Down Expand Up @@ -111,17 +111,17 @@ export const getWideConfig = async (context: Context) => {
const orgConfig = await getConfigSuperset(context, "org", CONFIG_PATH);
const repoConfig = await getConfigSuperset(context, "repo", CONFIG_PATH);

const parsedOrg: WideRepoConfig | undefined = parseYAML(orgConfig);
const parsedOrg: Config | undefined = parseYAML(orgConfig);

if (parsedOrg) {
const { valid, error } = validate(WideConfigSchema, parsedOrg);
const { valid, error } = validate(ConfigSchema, parsedOrg);
if (!valid) {
throw new Error(`Invalid org config: ${error}`);
}
}
const parsedRepo: WideRepoConfig | undefined = parseYAML(repoConfig);
const parsedRepo: Config | undefined = parseYAML(repoConfig);
if (parsedRepo) {
const { valid, error } = validate(WideConfigSchema, parsedRepo);
const { valid, error } = validate(ConfigSchema, parsedRepo);
if (!valid) {
throw new Error(`Invalid repo config: ${error}`);
}
Expand Down

0 comments on commit 3056bc9

Please sign in to comment.