Skip to content

Commit

Permalink
ran eslint on azure_ml files
Browse files Browse the repository at this point in the history
  • Loading branch information
ericckzhou committed Dec 21, 2023
1 parent 0dfb5dd commit 988ceae
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
19 changes: 10 additions & 9 deletions langchain/src/chat_models/azure_ml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ export class LlamaContentFormatter implements ChatContentFormatter {
messages: BaseMessage[],
modelArgs: Record<string, unknown>
): string {
let msgs = messages.map((message) => {
this._convertMessageToRecord(message);
});
const msgs = messages.map((message) => this._convertMessageToRecord(message));
return JSON.stringify({
input_data: {
input_string: msgs,
Expand Down Expand Up @@ -78,13 +76,19 @@ export class AzureMLChatOnlineEndpoint
static lc_name() {
return "AzureMLChatOnlineEndpoint";
}

static lc_description() {
return "A class for interacting with AzureML Chat models.";
}

endpointUrl: string;

endpointApiKey: string;

modelArgs?: Record<string, unknown>;

contentFormatter: ChatContentFormatter;

httpClient: AzureMLHttpClient;

constructor(fields: AzureMLChatParams) {
Expand All @@ -100,16 +104,17 @@ export class AzureMLChatOnlineEndpoint
}

this.endpointUrl =
fields.endpointUrl || getEnvironmentVariable("AZUREML_URL") + "";
fields.endpointUrl || `${getEnvironmentVariable("AZUREML_URL") }`;
this.endpointApiKey =
fields.endpointApiKey || getEnvironmentVariable("AZUREML_API_KEY") + "";
fields.endpointApiKey || `${getEnvironmentVariable("AZUREML_API_KEY") }`;
this.httpClient = new AzureMLHttpClient(
this.endpointUrl,
this.endpointApiKey
);
this.contentFormatter = fields.contentFormatter;
this.modelArgs = fields?.modelArgs;
}

get _identifying_params() {
const modelKwargs = this.modelArgs || {};
return {
Expand All @@ -122,10 +127,6 @@ export class AzureMLChatOnlineEndpoint
return "azureml_chat";
}

_combineLLMOutput(): Record<string, any> | undefined {
return [];
}

async _call(
messages: BaseMessage[],
modelArgs: Record<string, unknown>
Expand Down
20 changes: 17 additions & 3 deletions langchain/src/llms/azure_ml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { getEnvironmentVariable } from "../util/env.js";

export class AzureMLHttpClient {
endpointUrl: string;

endpointApiKey: string;

deploymentName?: string;

constructor(
Expand Down Expand Up @@ -78,6 +80,7 @@ export class GPT2ContentFormatter implements ContentFormatter {
parameters: modelArgs,
});
}

formatResponsePayload(output: string): string {
return JSON.parse(output)[0]["0"];
}
Expand All @@ -93,8 +96,9 @@ export class HFContentFormatter implements ContentFormatter {
parameters: modelArgs,
});
}

formatResponsePayload(output: string): string {
return JSON.parse(output)[0]["generated_text"];
return JSON.parse(output)[0].generated_text;
}
}

Expand All @@ -110,6 +114,7 @@ export class DollyContentFormatter implements ContentFormatter {
parameters: modelArgs,
});
}

formatResponsePayload(output: string): string {
return JSON.parse(output)[0];
}
Expand All @@ -127,6 +132,7 @@ export class LlamaContentFormatter implements ContentFormatter {
parameters: modelArgs,
});
}

formatResponsePayload(output: string): string {
return JSON.parse(output)[0]["0"];
}
Expand All @@ -149,12 +155,15 @@ export class AzureMLOnlineEndpoint extends LLM implements AzureMLParams {
_llmType() {
return "azure_ml";
}

static lc_name() {
return "AzureMLOnlineEndpoint";
}

static lc_description() {
return "A class for interacting with AzureML models.";
}

static lc_fields() {
return {
endpointUrl: {
Expand All @@ -175,10 +184,15 @@ export class AzureMLOnlineEndpoint extends LLM implements AzureMLParams {
}

endpointUrl: string;

endpointApiKey: string;

deploymentName?: string;

contentFormatter: ContentFormatter;

modelArgs?: Record<string, unknown>;

httpClient: AzureMLHttpClient;

constructor(fields: AzureMLParams) {
Expand All @@ -194,9 +208,9 @@ export class AzureMLOnlineEndpoint extends LLM implements AzureMLParams {
}

this.endpointUrl =
fields.endpointUrl || getEnvironmentVariable("AZUREML_URL") + "";
fields.endpointUrl || `${getEnvironmentVariable("AZUREML_URL") }`;
this.endpointApiKey =
fields.endpointApiKey || getEnvironmentVariable("AZUREML_API_KEY") + "";
fields.endpointApiKey || `${getEnvironmentVariable("AZUREML_API_KEY") }`;
this.deploymentName = fields.deploymentName;
this.httpClient = new AzureMLHttpClient(
this.endpointUrl,
Expand Down

0 comments on commit 988ceae

Please sign in to comment.