Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into v1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
tomatyss committed Jun 4, 2024
2 parents a159a7f + 14b997e commit 82b51b0
Show file tree
Hide file tree
Showing 5 changed files with 742 additions and 215 deletions.
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npm run check
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ To install:

## Usage

After installing and configuring your Azure API key, Endpoint and Deployment Ids you can start using any OpenAI model through the assistant panel in Prompt Mixer.
Make sure that you log in in Azure CLI `az login`.

After installing and configuring your Settings, you can start using any OpenAI model through the assistant panel in Prompt Mixer.

Refer to the Azure OpenAI documentation for details on how to format prompts for each model.

Expand Down
32 changes: 21 additions & 11 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ export interface ConnectorSetting {
Type: string;
}

async function getModels(settings: ConnectorSetting[]): Promise<string[]> {
async function getDynamicModelList(
settings: ConnectorSetting[],
): Promise<string[]> {
const accountName = settings.find((x) => x.SettingID === 'ACCOUNT_NAME')
?.Value as string;
const resourceGroupName = settings.find(
Expand All @@ -66,16 +68,22 @@ async function getModels(settings: ConnectorSetting[]): Promise<string[]> {
);
const deploymentNames = [];

for await (let item of client.deployments.list(
resourceGroupName,
accountName,
)) {
if (item?.name) deploymentNames.push(item.name);
}
try {
for await (const item of client.deployments.list(
resourceGroupName,
accountName,
)) {
if (item?.name) deploymentNames.push(item.name);
}

return deploymentNames;
return deploymentNames;
} catch (error) {
console.error('Error in getDynamicModelList function:', error);
return config.models;
}
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function isError(output: any): output is ErrorCompletion {
return (output as ErrorCompletion).error !== undefined;
}
Expand Down Expand Up @@ -108,6 +116,7 @@ const mapToResponse = (
};
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const mapErrorToCompletion = (error: any, model: string): ErrorCompletion => {
const errorMessage = error.message || JSON.stringify(error);

Expand All @@ -119,11 +128,12 @@ const mapErrorToCompletion = (error: any, model: string): ErrorCompletion => {
};
};

const logger = (object: any, description?: string): void => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const logger = (logBody: any, description?: string): void => {
if (description) console.log(`${description}`);

console.log(
utils.inspect(object, {
utils.inspect(logBody, {
showHidden: false,
depth: null,
colors: true,
Expand Down Expand Up @@ -260,4 +270,4 @@ function extractImageUrls(prompt: string): string[] {
});
}

export { main, config, getModels };
export { main, config, getDynamicModelList };
Loading

0 comments on commit 82b51b0

Please sign in to comment.