Skip to content

Commit

Permalink
Merge pull request #68 from gentlementlegen/feat/symbol-coefficient
Browse files Browse the repository at this point in the history
feat!: symbol coefficients and configurable scores per group
  • Loading branch information
gentlementlegen authored Aug 26, 2024
2 parents c340ba4 + db0b6ec commit dae0b4d
Show file tree
Hide file tree
Showing 34 changed files with 6,191 additions and 1,559 deletions.
139 changes: 80 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Be sure to review all `*.test.*` files for implementation details.
}
},
"wordValue": 0.1,
"formattingMultiplier": 1
"multiplier": 1
},
"reward": 0.8,
"relevance": 0.5
Expand All @@ -42,11 +42,11 @@ Be sure to review all `*.test.*` files for implementation details.
}
```

Reward formula: `((count * wordValue) * (score * formattingMultiplier) * n) * relevance + task.reward = total`
Reward formula: `((count * wordValue) * (score * multiplier) * n) * relevance + task.reward = total`

## Plugin configuration

Here is a possible valid configuration to enable this plugin. See [these files](./src/configuration) for more details.
Here is a possible valid configuration to enable this plugin. See [these files](./src/configuration/) for more details.

```yaml
plugin: ubiquibot/conversation-rewards
Expand All @@ -61,70 +61,91 @@ with:
requirePriceLabel: true
contentEvaluator:
multipliers:
- select: [ISSUE_SPECIFICATION]
- role: [ISSUE_SPECIFICATION]
relevance: 1
- select: [PULL_AUTHOR]
- role: [PULL_AUTHOR]
relevance: 1
- select: [PULL_ASSIGNEE]
- role: [PULL_ASSIGNEE]
relevance: 1
- select: [PULL_COLLABORATOR]
- role: [PULL_COLLABORATOR]
relevance: 1
- select: [PULL_CONTRIBUTOR]
- role: [PULL_CONTRIBUTOR]
relevance: 1
userExtractor:
redeemTask: true
dataPurge:
dataPurge: {}
formattingEvaluator:
scores:
br: 0
code: 1
p: 1
em: 0
img: 0
strong: 0
blockquote: 0
h1: 1
h2: 1
h3: 1
h4: 1
h5: 1
h6: 1
a: 1
li: 1
td: 1
hr: 0
multipliers:
- select: [ISSUE_SPECIFICATION]
formattingMultiplier: 1
wordValue: 0.1
- select: [ISSUE_AUTHOR]
formattingMultiplier: 1
wordValue: 0.2
- select: [ISSUE_ASSIGNEE]
formattingMultiplier: 0
wordValue: 0
- select: [ISSUE_COLLABORATOR]
formattingMultiplier: 1
wordValue: 0.1
- select: [ISSUE_CONTRIBUTOR]
formattingMultiplier: 0.25
wordValue: 0.1
- select: [PULL_SPECIFICATION]
formattingMultiplier: 0
wordValue: 0
- select: [PULL_AUTHOR]
formattingMultiplier: 2
wordValue: 0.2
- select: [PULL_ASSIGNEE]
formattingMultiplier: 1
wordValue: 0.1
- select: [PULL_COLLABORATOR]
formattingMultiplier: 1
wordValue: 0.1
- select: [PULL_CONTRIBUTOR]
formattingMultiplier: 0.25
wordValue: 0.1
permitGeneration:
multipliers:
- role: [ ISSUE_SPECIFICATION ]
multiplier: 1
rewards:
regex:
"\\b\\w+\\b": 0.1
scores: # Scores can be set for each item differently
br: 0
code: 1
p: 1
em: 0
img: 0
strong: 0
blockquote: 0
h1: 1
h2: 1
h3: 1
h4: 1
h5: 1
h6: 1
a: 1
li: 1
ul: 1
td: 1
hr: 0
- role: [ISSUE_AUTHOR]
multiplier: 1
rewards:
regex:
"\\b\\w+\\b": 0.2
- role: [ISSUE_ASSIGNEE]
multiplier: 0
rewards:
regex:
"\\b\\w+\\b": 0
- role: [ISSUE_COLLABORATOR]
multiplier: 1
rewards:
regex:
"\\b\\w+\\b": 0.1
- role: [ISSUE_CONTRIBUTOR]
multiplier: 0.25
rewards:
regex:
"\\b\\w+\\b": 0.1
- role: [PULL_SPECIFICATION]
multiplier: 0
rewards:
regex:
"\\b\\w+\\b": 0
- role: [PULL_AUTHOR]
multiplier: 2
rewards:
regex:
"\\b\\w+\\b": 0.2
- role: [PULL_ASSIGNEE]
multiplier: 1
rewards:
regex:
"\\b\\w+\\b": 0.1
- role: [PULL_COLLABORATOR]
multiplier: 1
rewards:
regex:
"\\b\\w+\\b": 0.1
- role: [PULL_CONTRIBUTOR]
multiplier: 0.25
rewards:
regex:
"\\b\\w+\\b": 0.1
permitGeneration: {}
githubComment:
post: true
debug: false
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"ethers": "^6.13.0",
"js-tiktoken": "1.0.14",
"jsdom": "24.0.0",
"lodash": "4.17.21",
"markdown-it": "14.1.0",
"openai": "4.56.0",
"tsx": "4.7.1",
Expand Down
14 changes: 7 additions & 7 deletions src/configuration/config-reader.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { Value } from "@sinclair/typebox/value";
import program from "../parser/command-line";
import { IncentivesConfiguration, incentivesConfigurationSchema, validateIncentivesConfiguration } from "./incentives";
import { Value } from "@sinclair/typebox/value";
import { merge } from "lodash";

let configuration: IncentivesConfiguration | null = null;

try {
const defaultConf = Value.Create(incentivesConfigurationSchema);
configuration = Value.Decode(incentivesConfigurationSchema, defaultConf);
configuration = Value.Default(incentivesConfigurationSchema, {}) as IncentivesConfiguration;
} catch (e) {
console.error(e);
}

if (program.settings) {
const settings = merge(configuration, JSON.parse(program.settings));
const settings = Value.Default(
incentivesConfigurationSchema,
JSON.parse(program.settings)
) as IncentivesConfiguration;
if (validateIncentivesConfiguration.test(settings)) {
configuration = settings;
configuration = Value.Decode(incentivesConfigurationSchema, settings);
} else {
console.warn("Invalid incentives configuration detected, will revert to defaults.");
for (const error of validateIncentivesConfiguration.errors(settings)) {
console.warn(error);
}
}
}

export default configuration as IncentivesConfiguration;
12 changes: 6 additions & 6 deletions src/configuration/content-evaluator-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@ export const contentEvaluatorConfigurationType = Type.Object({
*/
multipliers: Type.Array(
Type.Object({
select: Type.Array(commentType),
role: Type.Array(commentType),
relevance: Type.Optional(Type.Number()),
}),
{
default: [
{
select: ["ISSUE_SPECIFICATION"],
role: ["ISSUE_SPECIFICATION"],
relevance: 1,
},
{
select: ["PULL_AUTHOR"],
role: ["PULL_AUTHOR"],
relevance: 1,
},
{
select: ["PULL_ASSIGNEE"],
role: ["PULL_ASSIGNEE"],
relevance: 1,
},
{
select: ["PULL_COLLABORATOR"],
role: ["PULL_COLLABORATOR"],
relevance: 1,
},
{
select: ["PULL_CONTRIBUTOR"],
role: ["PULL_CONTRIBUTOR"],
relevance: 1,
},
],
Expand Down
23 changes: 13 additions & 10 deletions src/configuration/data-collection-config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { Static, Type } from "@sinclair/typebox";

export const dataCollectionConfigurationType = Type.Object({
/**
* The maximum amount of retries on failure.
*/
maxAttempts: Type.Number({ default: 10, minimum: 1 }),
/**
* The delay between each retry, in milliseconds.
*/
delayMs: Type.Number({ default: 1000, minimum: 100 }),
});
export const dataCollectionConfigurationType = Type.Object(
{
/**
* The maximum amount of retries on failure.
*/
maxAttempts: Type.Number({ default: 10, minimum: 1 }),
/**
* The delay between each retry, in milliseconds.
*/
delayMs: Type.Number({ default: 1000, minimum: 100 }),
},
{ default: {} }
);

export type DataCollectionConfiguration = Static<typeof dataCollectionConfigurationType>;
Loading

0 comments on commit dae0b4d

Please sign in to comment.