Skip to content

Commit

Permalink
chore: lint files
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul committed Dec 14, 2023
1 parent c016183 commit ab8b481
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 20 deletions.
1 change: 1 addition & 0 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@gomomento/sdk": "^1.51.1",
"@google/generative-ai": "^0.1.0",
"@langchain/community": "workspace:*",
"@langchain/core": "workspace:*",
"@langchain/google-genai": "workspace:*",
"@langchain/mistralai": "workspace:*",
"@opensearch-project/opensearch": "^2.2.0",
Expand Down
6 changes: 3 additions & 3 deletions examples/src/models/chat/chat_mistralai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { ChatPromptTemplate } from "langchain/prompts";

const model = new ChatMistralAI({
apiKey: process.env.MISTRAL_API_KEY,
modelName: "mistral-small"
modelName: "mistral-small",
});
const prompt = ChatPromptTemplate.fromMessages([
["system", "You are a helpful assistant"],
["human", "{input}"]
["human", "{input}"],
]);
const chain = prompt.pipe(model);
const response = await chain.invoke({
input: "Hello"
input: "Hello",
});
console.log("response", response);
/**
Expand Down
6 changes: 3 additions & 3 deletions examples/src/models/chat/chat_stream_mistralai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import { StringOutputParser } from "langchain/schema/output_parser";

const model = new ChatMistralAI({
apiKey: process.env.MISTRAL_API_KEY,
modelName: "mistral-small"
modelName: "mistral-small",
});
const prompt = ChatPromptTemplate.fromMessages([
["system", "You are a helpful assistant"],
["human", "{input}"]
["human", "{input}"],
]);
const outputParser = new StringOutputParser();
const chain = prompt.pipe(model).pipe(outputParser);
const response = await chain.stream({
input: "Hello"
input: "Hello",
});
for await (const item of response) {
console.log("stream item:", item);
Expand Down
26 changes: 13 additions & 13 deletions libs/langchain-mistralai/src/chat_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ import {
AIMessage,
HumanMessage,
HumanMessageChunk,
AIMessageChunk
AIMessageChunk,
} from "@langchain/core/messages";
import { type BaseLanguageModelCallOptions } from "@langchain/core/language_models/base";
import MistralClient, {
type ChatCompletionResult as MistralAIChatCompletionResult,
type ChatCompletionOptions as MistralAIChatCompletionOptions,
type Message as MistralAIInputMessage
type Message as MistralAIInputMessage,
} from "@mistralai/mistralai";
import { CallbackManagerForLLMRun } from "@langchain/core/callbacks/manager";
import {
type BaseChatModelParams,
BaseChatModel
BaseChatModel,
} from "@langchain/core/language_models/chat_models";

import {
ChatGeneration,
ChatGenerationChunk,
ChatResult
ChatResult,
} from "@langchain/core/outputs";
import { getEnvironmentVariable } from "@langchain/core/utils/env";
import { NewTokenIndices } from "@langchain/core/callbacks/base";
Expand Down Expand Up @@ -116,7 +116,7 @@ function convertMessagesToMistralMessages(

return messages.map((message) => ({
role: getRole(message._getType()),
content: getContent(message.content)
content: getContent(message.content),
}));
}

Expand Down Expand Up @@ -208,7 +208,7 @@ export class ChatMistralAI<
topP: this.topP,
maxTokens: this.maxTokens,
safeMode: this.safeMode,
randomSeed: this.randomSeed
randomSeed: this.randomSeed,
};
return params;
}
Expand Down Expand Up @@ -259,7 +259,7 @@ export class ChatMistralAI<
const mistralMessages = convertMessagesToMistralMessages(messages);
const input = {
...params,
messages: mistralMessages
messages: mistralMessages,
};

// Handle streaming
Expand Down Expand Up @@ -288,7 +288,7 @@ export class ChatMistralAI<
const {
completion_tokens: completionTokens,
prompt_tokens: promptTokens,
total_tokens: totalTokens
total_tokens: totalTokens,
} = response?.usage ?? {};

if (completionTokens) {
Expand All @@ -315,7 +315,7 @@ export class ChatMistralAI<
const text = part.message?.content ?? "";
const generation: ChatGeneration = {
text,
message: mistralAIResponseToChatMessage(part)
message: mistralAIResponseToChatMessage(part),
};
if (part.finish_reason) {
generation.generationInfo = { finish_reason: part.finish_reason };
Expand All @@ -324,7 +324,7 @@ export class ChatMistralAI<
}
return {
generations,
llmOutput: { tokenUsage }
llmOutput: { tokenUsage },
};
}

Expand All @@ -337,7 +337,7 @@ export class ChatMistralAI<
const params = this.invocationParams();
const input = {
...params,
messages: mistralMessages
messages: mistralMessages,
};

const streamIterable = await this.completionWithRetry(input, true);
Expand All @@ -353,12 +353,12 @@ export class ChatMistralAI<
}
const newTokenIndices = {
prompt: 0,
completion: choice.index ?? 0
completion: choice.index ?? 0,
};
const generationChunk = new ChatGenerationChunk({
message: _convertDeltaToMessageChunk(delta),
text: delta.content ?? "",
generationInfo: newTokenIndices
generationInfo: newTokenIndices,
});
yield generationChunk;
// eslint-disable-next-line no-void
Expand Down
3 changes: 2 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8455,7 +8455,7 @@ __metadata:
languageName: unknown
linkType: soft

"@langchain/core@workspace:langchain-core, @langchain/core@~0.1.0, @langchain/core@~0.1.1":
"@langchain/core@workspace:*, @langchain/core@workspace:langchain-core, @langchain/core@~0.1.0, @langchain/core@~0.1.1":
version: 0.0.0-use.local
resolution: "@langchain/core@workspace:langchain-core"
dependencies:
Expand Down Expand Up @@ -18952,6 +18952,7 @@ __metadata:
"@gomomento/sdk": ^1.51.1
"@google/generative-ai": ^0.1.0
"@langchain/community": "workspace:*"
"@langchain/core": "workspace:*"
"@langchain/google-genai": "workspace:*"
"@langchain/mistralai": "workspace:*"
"@opensearch-project/opensearch": ^2.2.0
Expand Down

0 comments on commit ab8b481

Please sign in to comment.