Skip to content

Commit

Permalink
Merge pull request #162 from bettyblocks/feat/extra-params-generative-ai
Browse files Browse the repository at this point in the history
feat: added new parameters, these can be used to connect to azure in …
  • Loading branch information
bettybas authored Jul 10, 2024
2 parents 4202d88 + d1dfdd8 commit ee04b43
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 3 deletions.
2 changes: 2 additions & 0 deletions __tests__/ai-classifier/1.0/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const input = {
maxTokens: 100,
temperature: 50,
model: 'text-davinci-002',
parameters: [],
};

const createPaths = (paths) => {
Expand Down Expand Up @@ -79,6 +80,7 @@ describe('Classifier function', () => {
variables: {
question: 'What tool is the best to ask for the current weather?',
},
parameters: {},
},
};

Expand Down
9 changes: 9 additions & 0 deletions functions/ai-anonymizer/1.0/function.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@
"default": 1024
}
},
{
"name": "parameters",
"label": "Extra parameters",
"info": "Define extra parameters that will be passed to the LLM, for example if you want to use azure openai",
"advanced": true,
"meta": {
"type": "Map"
}
},
{
"name": "result",
"label": "Result",
Expand Down
18 changes: 17 additions & 1 deletion functions/ai-anonymizer/1.0/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
const anonymizer = async ({ textToAnonymize, apiKey, maxTokens, model }) => {
const anonymizer = async ({
textToAnonymize,
apiKey,
maxTokens,
model,
parameters = [],
}) => {
const prompt = `Please review the following document and redact any Personal Identifiable Information (PII) such as names, addresses, phone numbers, email addresses, social security numbers, and any other details that could be used to identify an individual. Ensure the document remains coherent and retains its essential information while ensuring privacy and confidentiality. ${textToAnonymize}`;

// Convert parameters list to a single object
const parameterMap = parameters.reduce(
(previousValue, currentValue) => ({
...previousValue,
[currentValue.key]: currentValue.value,
}),
{},
);

const { result } = await generativeAI({
authorization: {
apiKey,
Expand All @@ -12,6 +27,7 @@ const anonymizer = async ({ textToAnonymize, apiKey, maxTokens, model }) => {
model,
settings: { maxNewTokens: maxTokens },
},
parameters: parameterMap,
},
});

Expand Down
9 changes: 9 additions & 0 deletions functions/ai-classifier/1.0/function.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@
"type": "Map"
}
},
{
"name": "parameters",
"label": "Extra parameters",
"info": "Define extra parameters that will be passed to the LLM, for example if you want to use azure openai",
"advanced": true,
"meta": {
"type": "Map"
}
},
{
"info": "The result produced by the classifier",
"name": "result",
Expand Down
15 changes: 14 additions & 1 deletion functions/ai-classifier/1.0/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const classifier = async ({ prompt, apiKey, model, variables }, paths) => {
const classifier = async (
{ prompt, apiKey, model, variables, parameters = [] },
paths,
) => {
const variableMap = variables.reduce(
(previousValue, currentValue) => ({
...previousValue,
Expand All @@ -7,6 +10,15 @@ const classifier = async ({ prompt, apiKey, model, variables }, paths) => {
{},
);

// Convert parameters list to a single object
const parameterMap = parameters.reduce(
(previousValue, currentValue) => ({
...previousValue,
[currentValue.key]: currentValue.value,
}),
{},
);

const choices = paths.map(({ label, value }) => ({
choice: label,
description:
Expand All @@ -27,6 +39,7 @@ const classifier = async ({ prompt, apiKey, model, variables }, paths) => {
model,
},
variables: variableMap,
parameters: parameterMap,
},
});

Expand Down
9 changes: 9 additions & 0 deletions functions/ai-prompt/1.0/function.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@
}
}
},
{
"name": "parameters",
"label": "Extra parameters",
"info": "Define extra parameters that will be passed to the LLM, for example if you want to use azure openai",
"advanced": true,
"meta": {
"type": "Map"
}
},
{
"name": "result",
"label": "Result",
Expand Down
11 changes: 11 additions & 0 deletions functions/ai-prompt/1.0/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const agent = async ({
maxTokens,
temperature,
model,
parameters = [],
}) => {
const variableMap = variables.reduce(
(previousValue, currentValue) => ({
Expand All @@ -14,6 +15,15 @@ const agent = async ({
{},
);

// Convert parameters list to a single object
const parameterMap = parameters.reduce(
(previousValue, currentValue) => ({
...previousValue,
[currentValue.key]: currentValue.value,
}),
{},
);

const { result } = await generativeAI({
authorization: {
apiKey,
Expand All @@ -26,6 +36,7 @@ const agent = async ({
model,
settings: { maxNewTokens: maxTokens, temperature: temperature / 100 },
},
parameters: parameterMap,
},
});

Expand Down
9 changes: 9 additions & 0 deletions functions/ai-query-generator/1.0/function.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@
"default": 256
}
},
{
"name": "parameters",
"label": "Extra parameters",
"info": "Define extra parameters that will be passed to the LLM, for example if you want to use azure openai",
"advanced": true,
"meta": {
"type": "Map"
}
},
{
"name": "result",
"label": "Result",
Expand Down
19 changes: 18 additions & 1 deletion functions/ai-query-generator/1.0/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ const regexQuery = (text) =>
const booleanQuery = (text) =>
`Generate a BM25 compatible boolean query for the following text: ${text}`;

const queryGenerator = async ({ query, style, apiKey, maxTokens, model }) => {
const queryGenerator = async ({
query,
style,
apiKey,
maxTokens,
model,
parameters = [],
}) => {
let prompt;

switch (style) {
Expand All @@ -19,6 +26,15 @@ const queryGenerator = async ({ query, style, apiKey, maxTokens, model }) => {
prompt = regexQuery(query);
}

// Convert parameters list to a single object
const parameterMap = parameters.reduce(
(previousValue, currentValue) => ({
...previousValue,
[currentValue.key]: currentValue.value,
}),
{},
);

const { result } = await generativeAI({
authorization: {
apiKey,
Expand All @@ -30,6 +46,7 @@ const queryGenerator = async ({ query, style, apiKey, maxTokens, model }) => {
model,
settings: { maxNewTokens: maxTokens },
},
parameters: parameterMap,
},
});

Expand Down
9 changes: 9 additions & 0 deletions functions/ai-summarizer/1.0/function.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@
"default": 1024
}
},
{
"name": "parameters",
"label": "Extra parameters",
"info": "Define extra parameters that will be passed to the LLM, for example if you want to use azure openai",
"advanced": true,
"meta": {
"type": "Map"
}
},
{
"name": "result",
"label": "Result",
Expand Down
11 changes: 11 additions & 0 deletions functions/ai-summarizer/1.0/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const summarizer = async ({
apiKey,
maxTokens,
model,
parameters = [],
}) => {
let prompt;

Expand All @@ -21,6 +22,15 @@ const summarizer = async ({
prompt = conciseSummary(textToSummarize);
}

// Convert parameters list to a single object
const parameterMap = parameters.reduce(
(previousValue, currentValue) => ({
...previousValue,
[currentValue.key]: currentValue.value,
}),
{},
);

const { result } = await generativeAI({
authorization: {
apiKey,
Expand All @@ -32,6 +42,7 @@ const summarizer = async ({
model,
settings: { maxNewTokens: maxTokens },
},
parameters: parameterMap,
},
});

Expand Down

0 comments on commit ee04b43

Please sign in to comment.