@langchain/together-ai 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @langchain/together-ai
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Initial provider package for Together AI chat models, embeddings, and legacy LLM support migrated from `@langchain/community`.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) LangChain, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,113 @@
1
+ # @langchain/together-ai
2
+
3
+ This package contains the LangChain.js integrations for [Together AI](https://www.together.ai/).
4
+
5
+ ## Installation
6
+
7
+ ```bash npm2yarn
8
+ npm install @langchain/together-ai @langchain/core
9
+ ```
10
+
11
+ This package, along with the main LangChain package, depends on [`@langchain/core`](https://npmjs.com/package/@langchain/core/). If you are using this package with other LangChain packages, make sure they all resolve to the same version of `@langchain/core`.
12
+
13
+ ## Authentication
14
+
15
+ Set the `TOGETHER_AI_API_KEY` environment variable or pass `apiKey` to the constructor.
16
+
17
+ ```bash
18
+ export TOGETHER_AI_API_KEY="your-api-key"
19
+ ```
20
+
21
+ ## Chat models
22
+
23
+ `ChatTogetherAI` is the recommended Together AI integration for chat and instruct models.
24
+
25
+ ```typescript
26
+ import { ChatTogetherAI } from "@langchain/together-ai";
27
+ import { HumanMessage } from "@langchain/core/messages";
28
+
29
+ const model = new ChatTogetherAI({
30
+ model: "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo",
31
+ temperature: 0,
32
+ });
33
+
34
+ const response = await model.invoke([new HumanMessage("Hello there!")]);
35
+ console.log(response.content);
36
+ ```
37
+
38
+ ## Embeddings
39
+
40
+ ```typescript
41
+ import { TogetherAIEmbeddings } from "@langchain/together-ai";
42
+
43
+ const embeddings = new TogetherAIEmbeddings({
44
+ model: "togethercomputer/m2-bert-80M-8k-retrieval",
45
+ });
46
+
47
+ const vector = await embeddings.embedQuery(
48
+ "What would be a good company name for a colorful socks startup?"
49
+ );
50
+ console.log(vector.length);
51
+ ```
52
+
53
+ ## Legacy completions LLM
54
+
55
+ ```typescript
56
+ import { TogetherAI } from "@langchain/together-ai";
57
+ import { PromptTemplate } from "@langchain/core/prompts";
58
+
59
+ const model = new TogetherAI({
60
+ model: "togethercomputer/StripedHyena-Nous-7B",
61
+ });
62
+
63
+ const prompt = PromptTemplate.fromTemplate("Answer briefly: {input}");
64
+ const response = await prompt.pipe(model).invoke({
65
+ input: "Tell me a joke about bears",
66
+ });
67
+
68
+ console.log(response);
69
+ ```
70
+
71
+ For chat or instruct models, prefer `ChatTogetherAI` over the legacy `TogetherAI` completions class.
72
+
73
+ ## Development
74
+
75
+ To develop the `@langchain/together-ai` package, follow these instructions:
76
+
77
+ ### Install dependencies
78
+
79
+ ```bash
80
+ pnpm install
81
+ ```
82
+
83
+ ### Build the package
84
+
85
+ ```bash
86
+ pnpm build
87
+ ```
88
+
89
+ Or from the repo root:
90
+
91
+ ```bash
92
+ pnpm build --filter @langchain/together-ai
93
+ ```
94
+
95
+ ### Run tests
96
+
97
+ Test files should live within a `tests/` folder in the `src/` directory. Unit tests should end in `.test.ts` and integration tests should end in `.int.test.ts`:
98
+
99
+ ```bash
100
+ pnpm test
101
+ pnpm test:int
102
+ pnpm test:standard:unit
103
+ ```
104
+
105
+ ### Lint & Format
106
+
107
+ ```bash
108
+ pnpm lint && pnpm format
109
+ ```
110
+
111
+ ### Adding new entry points
112
+
113
+ If you add a new file to be exported, either import and re-export it from `src/index.ts`, or add it to the `exports` field in `package.json` and run `pnpm build` to generate the new entry point.
@@ -0,0 +1,87 @@
1
+ let _langchain_core_utils_env = require("@langchain/core/utils/env");
2
+ let _langchain_openai = require("@langchain/openai");
3
+ //#region src/chat_models.ts
4
+ /**
5
+ * Together AI chat model integration.
6
+ *
7
+ * The Together AI chat API is OpenAI-compatible with a few unsupported request
8
+ * fields. Full API reference:
9
+ * https://docs.together.ai/reference/chat-completions
10
+ *
11
+ * Setup:
12
+ * Install `@langchain/together-ai` and set an environment variable named
13
+ * `TOGETHER_AI_API_KEY`.
14
+ *
15
+ * ```bash
16
+ * npm install @langchain/together-ai
17
+ * export TOGETHER_AI_API_KEY="your-api-key"
18
+ * ```
19
+ *
20
+ * ## [Constructor args](https://api.js.langchain.com/classes/_langchain_together_ai.ChatTogetherAI.html#constructor)
21
+ *
22
+ * ## [Runtime args](https://api.js.langchain.com/interfaces/_langchain_together_ai.ChatTogetherAICallOptions.html)
23
+ */
24
+ var ChatTogetherAI = class extends _langchain_openai.ChatOpenAICompletions {
25
+ static lc_name() {
26
+ return "ChatTogetherAI";
27
+ }
28
+ lc_serializable = true;
29
+ lc_namespace = [
30
+ "langchain",
31
+ "chat_models",
32
+ "together_ai"
33
+ ];
34
+ _llmType() {
35
+ return "togetherAI";
36
+ }
37
+ get lc_secrets() {
38
+ return {
39
+ togetherAIApiKey: "TOGETHER_AI_API_KEY",
40
+ apiKey: "TOGETHER_AI_API_KEY"
41
+ };
42
+ }
43
+ get lc_aliases() {
44
+ return {
45
+ togetherAIApiKey: "together_ai_api_key",
46
+ apiKey: "together_ai_api_key"
47
+ };
48
+ }
49
+ constructor(fields) {
50
+ const togetherAIApiKey = fields?.apiKey || fields?.togetherAIApiKey || (0, _langchain_core_utils_env.getEnvironmentVariable)("TOGETHER_AI_API_KEY");
51
+ if (!togetherAIApiKey) throw new Error("Together AI API key not found. Please set the TOGETHER_AI_API_KEY environment variable or pass the key into the \"apiKey\" field.");
52
+ super({
53
+ ...fields,
54
+ model: fields?.model || "mistralai/Mixtral-8x7B-Instruct-v0.1",
55
+ apiKey: togetherAIApiKey,
56
+ configuration: {
57
+ baseURL: "https://api.together.xyz/v1/",
58
+ ...fields?.configuration
59
+ }
60
+ });
61
+ this._addVersion("@langchain/together-ai", "0.0.1");
62
+ }
63
+ getLsParams(options) {
64
+ const params = super.getLsParams(options);
65
+ params.ls_provider = "together";
66
+ return params;
67
+ }
68
+ toJSON() {
69
+ const result = super.toJSON();
70
+ if ("kwargs" in result && typeof result.kwargs === "object" && result.kwargs != null) {
71
+ delete result.kwargs.openai_api_key;
72
+ delete result.kwargs.configuration;
73
+ }
74
+ return result;
75
+ }
76
+ async completionWithRetry(request, options) {
77
+ delete request.frequency_penalty;
78
+ delete request.presence_penalty;
79
+ delete request.logit_bias;
80
+ delete request.functions;
81
+ return super.completionWithRetry(request, options);
82
+ }
83
+ };
84
+ //#endregion
85
+ exports.ChatTogetherAI = ChatTogetherAI;
86
+
87
+ //# sourceMappingURL=chat_models.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat_models.cjs","names":["ChatOpenAICompletions"],"sources":["../src/chat_models.ts"],"sourcesContent":["import type {\n BaseChatModelParams,\n LangSmithParams,\n} from \"@langchain/core/language_models/chat_models\";\nimport { getEnvironmentVariable } from \"@langchain/core/utils/env\";\nimport {\n type ChatOpenAICallOptions,\n ChatOpenAICompletions,\n type OpenAIChatInput,\n type OpenAICoreRequestOptions,\n type OpenAIClient,\n} from \"@langchain/openai\";\n\ntype TogetherAIUnsupportedArgs =\n | \"frequencyPenalty\"\n | \"presencePenalty\"\n | \"logitBias\"\n | \"functions\";\n\ntype TogetherAIUnsupportedCallOptions = \"functions\" | \"function_call\";\n\nexport interface ChatTogetherAICallOptions extends Omit<\n ChatOpenAICallOptions,\n TogetherAIUnsupportedCallOptions\n> {\n response_format?: {\n type: \"json_object\";\n schema: Record<string, unknown>;\n };\n}\n\nexport interface ChatTogetherAIInput\n extends\n Omit<OpenAIChatInput, \"openAIApiKey\" | TogetherAIUnsupportedArgs>,\n BaseChatModelParams {\n /**\n * The Together AI API key to use for requests.\n * Alias for `apiKey`.\n * @default process.env.TOGETHER_AI_API_KEY\n */\n togetherAIApiKey?: string;\n /**\n * The Together AI API key to use for requests.\n * @default process.env.TOGETHER_AI_API_KEY\n */\n apiKey?: string;\n}\n\n/**\n * Together AI chat model integration.\n *\n * The Together AI chat API is OpenAI-compatible with a few unsupported request\n * fields. Full API reference:\n * https://docs.together.ai/reference/chat-completions\n *\n * Setup:\n * Install `@langchain/together-ai` and set an environment variable named\n * `TOGETHER_AI_API_KEY`.\n *\n * ```bash\n * npm install @langchain/together-ai\n * export TOGETHER_AI_API_KEY=\"your-api-key\"\n * ```\n *\n * ## [Constructor args](https://api.js.langchain.com/classes/_langchain_together_ai.ChatTogetherAI.html#constructor)\n *\n * ## [Runtime args](https://api.js.langchain.com/interfaces/_langchain_together_ai.ChatTogetherAICallOptions.html)\n */\nexport class ChatTogetherAI extends ChatOpenAICompletions<ChatTogetherAICallOptions> {\n static lc_name() {\n return \"ChatTogetherAI\";\n }\n\n lc_serializable = true;\n\n lc_namespace = [\"langchain\", \"chat_models\", \"together_ai\"];\n\n _llmType() {\n return \"togetherAI\";\n }\n\n get lc_secrets(): { [key: string]: string } | undefined {\n return {\n togetherAIApiKey: \"TOGETHER_AI_API_KEY\",\n apiKey: \"TOGETHER_AI_API_KEY\",\n };\n }\n\n get lc_aliases(): { [key: string]: string } | undefined {\n return {\n togetherAIApiKey: \"together_ai_api_key\",\n apiKey: \"together_ai_api_key\",\n };\n }\n\n constructor(fields?: Partial<ChatTogetherAIInput>) {\n const togetherAIApiKey =\n fields?.apiKey ||\n fields?.togetherAIApiKey ||\n getEnvironmentVariable(\"TOGETHER_AI_API_KEY\");\n\n if (!togetherAIApiKey) {\n throw new Error(\n 'Together AI API key not found. Please set the TOGETHER_AI_API_KEY environment variable or pass the key into the \"apiKey\" field.'\n );\n }\n\n super({\n ...fields,\n model: fields?.model || \"mistralai/Mixtral-8x7B-Instruct-v0.1\",\n apiKey: togetherAIApiKey,\n configuration: {\n baseURL: \"https://api.together.xyz/v1/\",\n ...fields?.configuration,\n },\n });\n this._addVersion(\"@langchain/together-ai\", __PKG_VERSION__);\n }\n\n getLsParams(options: this[\"ParsedCallOptions\"]): LangSmithParams {\n const params = super.getLsParams(options);\n params.ls_provider = \"together\";\n return params;\n }\n\n toJSON() {\n const result = super.toJSON();\n\n if (\n \"kwargs\" in result &&\n typeof result.kwargs === \"object\" &&\n result.kwargs != null\n ) {\n delete result.kwargs.openai_api_key;\n delete result.kwargs.configuration;\n }\n\n return result;\n }\n\n async completionWithRetry(\n request: OpenAIClient.Chat.ChatCompletionCreateParamsStreaming,\n options?: OpenAICoreRequestOptions\n ): Promise<AsyncIterable<OpenAIClient.Chat.Completions.ChatCompletionChunk>>;\n\n async completionWithRetry(\n request: OpenAIClient.Chat.ChatCompletionCreateParamsNonStreaming,\n options?: OpenAICoreRequestOptions\n ): Promise<OpenAIClient.Chat.Completions.ChatCompletion>;\n\n async completionWithRetry(\n request:\n | OpenAIClient.Chat.ChatCompletionCreateParamsStreaming\n | OpenAIClient.Chat.ChatCompletionCreateParamsNonStreaming,\n options?: OpenAICoreRequestOptions\n ): Promise<\n | AsyncIterable<OpenAIClient.Chat.Completions.ChatCompletionChunk>\n | OpenAIClient.Chat.Completions.ChatCompletion\n > {\n delete request.frequency_penalty;\n delete request.presence_penalty;\n delete request.logit_bias;\n delete request.functions;\n\n return super.completionWithRetry(request, options);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAoEA,IAAa,iBAAb,cAAoCA,kBAAAA,sBAAiD;CACnF,OAAO,UAAU;AACf,SAAO;;CAGT,kBAAkB;CAElB,eAAe;EAAC;EAAa;EAAe;EAAc;CAE1D,WAAW;AACT,SAAO;;CAGT,IAAI,aAAoD;AACtD,SAAO;GACL,kBAAkB;GAClB,QAAQ;GACT;;CAGH,IAAI,aAAoD;AACtD,SAAO;GACL,kBAAkB;GAClB,QAAQ;GACT;;CAGH,YAAY,QAAuC;EACjD,MAAM,mBACJ,QAAQ,UACR,QAAQ,qBAAA,GAAA,0BAAA,wBACe,sBAAsB;AAE/C,MAAI,CAAC,iBACH,OAAM,IAAI,MACR,oIACD;AAGH,QAAM;GACJ,GAAG;GACH,OAAO,QAAQ,SAAS;GACxB,QAAQ;GACR,eAAe;IACb,SAAS;IACT,GAAG,QAAQ;IACZ;GACF,CAAC;AACF,OAAK,YAAY,0BAAA,QAA0C;;CAG7D,YAAY,SAAqD;EAC/D,MAAM,SAAS,MAAM,YAAY,QAAQ;AACzC,SAAO,cAAc;AACrB,SAAO;;CAGT,SAAS;EACP,MAAM,SAAS,MAAM,QAAQ;AAE7B,MACE,YAAY,UACZ,OAAO,OAAO,WAAW,YACzB,OAAO,UAAU,MACjB;AACA,UAAO,OAAO,OAAO;AACrB,UAAO,OAAO,OAAO;;AAGvB,SAAO;;CAaT,MAAM,oBACJ,SAGA,SAIA;AACA,SAAO,QAAQ;AACf,SAAO,QAAQ;AACf,SAAO,QAAQ;AACf,SAAO,QAAQ;AAEf,SAAO,MAAM,oBAAoB,SAAS,QAAQ"}
@@ -0,0 +1,66 @@
1
+ import * as _langchain_core_load_serializable0 from "@langchain/core/load/serializable";
2
+ import { BaseChatModelParams, LangSmithParams } from "@langchain/core/language_models/chat_models";
3
+ import { ChatOpenAICallOptions, ChatOpenAICompletions, OpenAIChatInput, OpenAIClient, OpenAICoreRequestOptions } from "@langchain/openai";
4
+
5
+ //#region src/chat_models.d.ts
6
+ type TogetherAIUnsupportedArgs = "frequencyPenalty" | "presencePenalty" | "logitBias" | "functions";
7
+ type TogetherAIUnsupportedCallOptions = "functions" | "function_call";
8
+ interface ChatTogetherAICallOptions extends Omit<ChatOpenAICallOptions, TogetherAIUnsupportedCallOptions> {
9
+ response_format?: {
10
+ type: "json_object";
11
+ schema: Record<string, unknown>;
12
+ };
13
+ }
14
+ interface ChatTogetherAIInput extends Omit<OpenAIChatInput, "openAIApiKey" | TogetherAIUnsupportedArgs>, BaseChatModelParams {
15
+ /**
16
+ * The Together AI API key to use for requests.
17
+ * Alias for `apiKey`.
18
+ * @default process.env.TOGETHER_AI_API_KEY
19
+ */
20
+ togetherAIApiKey?: string;
21
+ /**
22
+ * The Together AI API key to use for requests.
23
+ * @default process.env.TOGETHER_AI_API_KEY
24
+ */
25
+ apiKey?: string;
26
+ }
27
+ /**
28
+ * Together AI chat model integration.
29
+ *
30
+ * The Together AI chat API is OpenAI-compatible with a few unsupported request
31
+ * fields. Full API reference:
32
+ * https://docs.together.ai/reference/chat-completions
33
+ *
34
+ * Setup:
35
+ * Install `@langchain/together-ai` and set an environment variable named
36
+ * `TOGETHER_AI_API_KEY`.
37
+ *
38
+ * ```bash
39
+ * npm install @langchain/together-ai
40
+ * export TOGETHER_AI_API_KEY="your-api-key"
41
+ * ```
42
+ *
43
+ * ## [Constructor args](https://api.js.langchain.com/classes/_langchain_together_ai.ChatTogetherAI.html#constructor)
44
+ *
45
+ * ## [Runtime args](https://api.js.langchain.com/interfaces/_langchain_together_ai.ChatTogetherAICallOptions.html)
46
+ */
47
+ declare class ChatTogetherAI extends ChatOpenAICompletions<ChatTogetherAICallOptions> {
48
+ static lc_name(): string;
49
+ lc_serializable: boolean;
50
+ lc_namespace: string[];
51
+ _llmType(): string;
52
+ get lc_secrets(): {
53
+ [key: string]: string;
54
+ } | undefined;
55
+ get lc_aliases(): {
56
+ [key: string]: string;
57
+ } | undefined;
58
+ constructor(fields?: Partial<ChatTogetherAIInput>);
59
+ getLsParams(options: this["ParsedCallOptions"]): LangSmithParams;
60
+ toJSON(): _langchain_core_load_serializable0.Serialized;
61
+ completionWithRetry(request: OpenAIClient.Chat.ChatCompletionCreateParamsStreaming, options?: OpenAICoreRequestOptions): Promise<AsyncIterable<OpenAIClient.Chat.Completions.ChatCompletionChunk>>;
62
+ completionWithRetry(request: OpenAIClient.Chat.ChatCompletionCreateParamsNonStreaming, options?: OpenAICoreRequestOptions): Promise<OpenAIClient.Chat.Completions.ChatCompletion>;
63
+ }
64
+ //#endregion
65
+ export { ChatTogetherAI, ChatTogetherAICallOptions, ChatTogetherAIInput };
66
+ //# sourceMappingURL=chat_models.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat_models.d.cts","names":[],"sources":["../src/chat_models.ts"],"mappings":";;;;;KAaK,yBAAA;AAAA,KAMA,gCAAA;AAAA,UAEY,yBAAA,SAAkC,IAAA,CACjD,qBAAA,EACA,gCAAA;EAEA,eAAA;IACE,IAAA;IACA,MAAA,EAAQ,MAAA;EAAA;AAAA;AAAA,UAIK,mBAAA,SAEb,IAAA,CAAK,eAAA,mBAAkC,yBAAA,GACvC,mBAAA;EAfiC;;;;AAErC;EAmBE,gBAAA;;;;;EAKA,MAAA;AAAA;;;;;;;;;;;AAdF;;;;;;;;;;cAqCa,cAAA,SAAuB,qBAAA,CAAsB,yBAAA;EAAA,OACjD,OAAA,CAAA;EAIP,eAAA;EAEA,YAAA;EAEA,QAAA,CAAA;EAAA,IAII,UAAA,CAAA;IAAA,CAAiB,GAAA;EAAA;EAAA,IAOjB,UAAA,CAAA;IAAA,CAAiB,GAAA;EAAA;EAOrB,WAAA,CAAY,MAAA,GAAS,OAAA,CAAQ,mBAAA;EAwB7B,WAAA,CAAY,OAAA,8BAAqC,eAAA;EAMjD,MAAA,CAAA,GANgE,kCAAA,CAM1D,UAAA;EAeA,mBAAA,CACJ,OAAA,EAAS,YAAA,CAAa,IAAA,CAAK,mCAAA,EAC3B,OAAA,GAAU,wBAAA,GACT,OAAA,CAAQ,aAAA,CAAc,YAAA,CAAa,IAAA,CAAK,WAAA,CAAY,mBAAA;EAEjD,mBAAA,CACJ,OAAA,EAAS,YAAA,CAAa,IAAA,CAAK,sCAAA,EAC3B,OAAA,GAAU,wBAAA,GACT,OAAA,CAAQ,YAAA,CAAa,IAAA,CAAK,WAAA,CAAY,cAAA;AAAA"}
@@ -0,0 +1,66 @@
1
+ import { ChatOpenAICallOptions, ChatOpenAICompletions, OpenAIChatInput, OpenAIClient, OpenAICoreRequestOptions } from "@langchain/openai";
2
+ import * as _langchain_core_load_serializable0 from "@langchain/core/load/serializable";
3
+ import { BaseChatModelParams, LangSmithParams } from "@langchain/core/language_models/chat_models";
4
+
5
+ //#region src/chat_models.d.ts
6
+ type TogetherAIUnsupportedArgs = "frequencyPenalty" | "presencePenalty" | "logitBias" | "functions";
7
+ type TogetherAIUnsupportedCallOptions = "functions" | "function_call";
8
+ interface ChatTogetherAICallOptions extends Omit<ChatOpenAICallOptions, TogetherAIUnsupportedCallOptions> {
9
+ response_format?: {
10
+ type: "json_object";
11
+ schema: Record<string, unknown>;
12
+ };
13
+ }
14
+ interface ChatTogetherAIInput extends Omit<OpenAIChatInput, "openAIApiKey" | TogetherAIUnsupportedArgs>, BaseChatModelParams {
15
+ /**
16
+ * The Together AI API key to use for requests.
17
+ * Alias for `apiKey`.
18
+ * @default process.env.TOGETHER_AI_API_KEY
19
+ */
20
+ togetherAIApiKey?: string;
21
+ /**
22
+ * The Together AI API key to use for requests.
23
+ * @default process.env.TOGETHER_AI_API_KEY
24
+ */
25
+ apiKey?: string;
26
+ }
27
+ /**
28
+ * Together AI chat model integration.
29
+ *
30
+ * The Together AI chat API is OpenAI-compatible with a few unsupported request
31
+ * fields. Full API reference:
32
+ * https://docs.together.ai/reference/chat-completions
33
+ *
34
+ * Setup:
35
+ * Install `@langchain/together-ai` and set an environment variable named
36
+ * `TOGETHER_AI_API_KEY`.
37
+ *
38
+ * ```bash
39
+ * npm install @langchain/together-ai
40
+ * export TOGETHER_AI_API_KEY="your-api-key"
41
+ * ```
42
+ *
43
+ * ## [Constructor args](https://api.js.langchain.com/classes/_langchain_together_ai.ChatTogetherAI.html#constructor)
44
+ *
45
+ * ## [Runtime args](https://api.js.langchain.com/interfaces/_langchain_together_ai.ChatTogetherAICallOptions.html)
46
+ */
47
+ declare class ChatTogetherAI extends ChatOpenAICompletions<ChatTogetherAICallOptions> {
48
+ static lc_name(): string;
49
+ lc_serializable: boolean;
50
+ lc_namespace: string[];
51
+ _llmType(): string;
52
+ get lc_secrets(): {
53
+ [key: string]: string;
54
+ } | undefined;
55
+ get lc_aliases(): {
56
+ [key: string]: string;
57
+ } | undefined;
58
+ constructor(fields?: Partial<ChatTogetherAIInput>);
59
+ getLsParams(options: this["ParsedCallOptions"]): LangSmithParams;
60
+ toJSON(): _langchain_core_load_serializable0.Serialized;
61
+ completionWithRetry(request: OpenAIClient.Chat.ChatCompletionCreateParamsStreaming, options?: OpenAICoreRequestOptions): Promise<AsyncIterable<OpenAIClient.Chat.Completions.ChatCompletionChunk>>;
62
+ completionWithRetry(request: OpenAIClient.Chat.ChatCompletionCreateParamsNonStreaming, options?: OpenAICoreRequestOptions): Promise<OpenAIClient.Chat.Completions.ChatCompletion>;
63
+ }
64
+ //#endregion
65
+ export { ChatTogetherAI, ChatTogetherAICallOptions, ChatTogetherAIInput };
66
+ //# sourceMappingURL=chat_models.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat_models.d.ts","names":[],"sources":["../src/chat_models.ts"],"mappings":";;;;;KAaK,yBAAA;AAAA,KAMA,gCAAA;AAAA,UAEY,yBAAA,SAAkC,IAAA,CACjD,qBAAA,EACA,gCAAA;EAEA,eAAA;IACE,IAAA;IACA,MAAA,EAAQ,MAAA;EAAA;AAAA;AAAA,UAIK,mBAAA,SAEb,IAAA,CAAK,eAAA,mBAAkC,yBAAA,GACvC,mBAAA;EAfiC;;;;AAErC;EAmBE,gBAAA;;;;;EAKA,MAAA;AAAA;;;;;;;;;;;AAdF;;;;;;;;;;cAqCa,cAAA,SAAuB,qBAAA,CAAsB,yBAAA;EAAA,OACjD,OAAA,CAAA;EAIP,eAAA;EAEA,YAAA;EAEA,QAAA,CAAA;EAAA,IAII,UAAA,CAAA;IAAA,CAAiB,GAAA;EAAA;EAAA,IAOjB,UAAA,CAAA;IAAA,CAAiB,GAAA;EAAA;EAOrB,WAAA,CAAY,MAAA,GAAS,OAAA,CAAQ,mBAAA;EAwB7B,WAAA,CAAY,OAAA,8BAAqC,eAAA;EAMjD,MAAA,CAAA,GANgE,kCAAA,CAM1D,UAAA;EAeA,mBAAA,CACJ,OAAA,EAAS,YAAA,CAAa,IAAA,CAAK,mCAAA,EAC3B,OAAA,GAAU,wBAAA,GACT,OAAA,CAAQ,aAAA,CAAc,YAAA,CAAa,IAAA,CAAK,WAAA,CAAY,mBAAA;EAEjD,mBAAA,CACJ,OAAA,EAAS,YAAA,CAAa,IAAA,CAAK,sCAAA,EAC3B,OAAA,GAAU,wBAAA,GACT,OAAA,CAAQ,YAAA,CAAa,IAAA,CAAK,WAAA,CAAY,cAAA;AAAA"}
@@ -0,0 +1,87 @@
1
+ import { getEnvironmentVariable } from "@langchain/core/utils/env";
2
+ import { ChatOpenAICompletions } from "@langchain/openai";
3
+ //#region src/chat_models.ts
4
+ /**
5
+ * Together AI chat model integration.
6
+ *
7
+ * The Together AI chat API is OpenAI-compatible with a few unsupported request
8
+ * fields. Full API reference:
9
+ * https://docs.together.ai/reference/chat-completions
10
+ *
11
+ * Setup:
12
+ * Install `@langchain/together-ai` and set an environment variable named
13
+ * `TOGETHER_AI_API_KEY`.
14
+ *
15
+ * ```bash
16
+ * npm install @langchain/together-ai
17
+ * export TOGETHER_AI_API_KEY="your-api-key"
18
+ * ```
19
+ *
20
+ * ## [Constructor args](https://api.js.langchain.com/classes/_langchain_together_ai.ChatTogetherAI.html#constructor)
21
+ *
22
+ * ## [Runtime args](https://api.js.langchain.com/interfaces/_langchain_together_ai.ChatTogetherAICallOptions.html)
23
+ */
24
+ var ChatTogetherAI = class extends ChatOpenAICompletions {
25
+ static lc_name() {
26
+ return "ChatTogetherAI";
27
+ }
28
+ lc_serializable = true;
29
+ lc_namespace = [
30
+ "langchain",
31
+ "chat_models",
32
+ "together_ai"
33
+ ];
34
+ _llmType() {
35
+ return "togetherAI";
36
+ }
37
+ get lc_secrets() {
38
+ return {
39
+ togetherAIApiKey: "TOGETHER_AI_API_KEY",
40
+ apiKey: "TOGETHER_AI_API_KEY"
41
+ };
42
+ }
43
+ get lc_aliases() {
44
+ return {
45
+ togetherAIApiKey: "together_ai_api_key",
46
+ apiKey: "together_ai_api_key"
47
+ };
48
+ }
49
+ constructor(fields) {
50
+ const togetherAIApiKey = fields?.apiKey || fields?.togetherAIApiKey || getEnvironmentVariable("TOGETHER_AI_API_KEY");
51
+ if (!togetherAIApiKey) throw new Error("Together AI API key not found. Please set the TOGETHER_AI_API_KEY environment variable or pass the key into the \"apiKey\" field.");
52
+ super({
53
+ ...fields,
54
+ model: fields?.model || "mistralai/Mixtral-8x7B-Instruct-v0.1",
55
+ apiKey: togetherAIApiKey,
56
+ configuration: {
57
+ baseURL: "https://api.together.xyz/v1/",
58
+ ...fields?.configuration
59
+ }
60
+ });
61
+ this._addVersion("@langchain/together-ai", "0.0.1");
62
+ }
63
+ getLsParams(options) {
64
+ const params = super.getLsParams(options);
65
+ params.ls_provider = "together";
66
+ return params;
67
+ }
68
+ toJSON() {
69
+ const result = super.toJSON();
70
+ if ("kwargs" in result && typeof result.kwargs === "object" && result.kwargs != null) {
71
+ delete result.kwargs.openai_api_key;
72
+ delete result.kwargs.configuration;
73
+ }
74
+ return result;
75
+ }
76
+ async completionWithRetry(request, options) {
77
+ delete request.frequency_penalty;
78
+ delete request.presence_penalty;
79
+ delete request.logit_bias;
80
+ delete request.functions;
81
+ return super.completionWithRetry(request, options);
82
+ }
83
+ };
84
+ //#endregion
85
+ export { ChatTogetherAI };
86
+
87
+ //# sourceMappingURL=chat_models.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat_models.js","names":[],"sources":["../src/chat_models.ts"],"sourcesContent":["import type {\n BaseChatModelParams,\n LangSmithParams,\n} from \"@langchain/core/language_models/chat_models\";\nimport { getEnvironmentVariable } from \"@langchain/core/utils/env\";\nimport {\n type ChatOpenAICallOptions,\n ChatOpenAICompletions,\n type OpenAIChatInput,\n type OpenAICoreRequestOptions,\n type OpenAIClient,\n} from \"@langchain/openai\";\n\ntype TogetherAIUnsupportedArgs =\n | \"frequencyPenalty\"\n | \"presencePenalty\"\n | \"logitBias\"\n | \"functions\";\n\ntype TogetherAIUnsupportedCallOptions = \"functions\" | \"function_call\";\n\nexport interface ChatTogetherAICallOptions extends Omit<\n ChatOpenAICallOptions,\n TogetherAIUnsupportedCallOptions\n> {\n response_format?: {\n type: \"json_object\";\n schema: Record<string, unknown>;\n };\n}\n\nexport interface ChatTogetherAIInput\n extends\n Omit<OpenAIChatInput, \"openAIApiKey\" | TogetherAIUnsupportedArgs>,\n BaseChatModelParams {\n /**\n * The Together AI API key to use for requests.\n * Alias for `apiKey`.\n * @default process.env.TOGETHER_AI_API_KEY\n */\n togetherAIApiKey?: string;\n /**\n * The Together AI API key to use for requests.\n * @default process.env.TOGETHER_AI_API_KEY\n */\n apiKey?: string;\n}\n\n/**\n * Together AI chat model integration.\n *\n * The Together AI chat API is OpenAI-compatible with a few unsupported request\n * fields. Full API reference:\n * https://docs.together.ai/reference/chat-completions\n *\n * Setup:\n * Install `@langchain/together-ai` and set an environment variable named\n * `TOGETHER_AI_API_KEY`.\n *\n * ```bash\n * npm install @langchain/together-ai\n * export TOGETHER_AI_API_KEY=\"your-api-key\"\n * ```\n *\n * ## [Constructor args](https://api.js.langchain.com/classes/_langchain_together_ai.ChatTogetherAI.html#constructor)\n *\n * ## [Runtime args](https://api.js.langchain.com/interfaces/_langchain_together_ai.ChatTogetherAICallOptions.html)\n */\nexport class ChatTogetherAI extends ChatOpenAICompletions<ChatTogetherAICallOptions> {\n static lc_name() {\n return \"ChatTogetherAI\";\n }\n\n lc_serializable = true;\n\n lc_namespace = [\"langchain\", \"chat_models\", \"together_ai\"];\n\n _llmType() {\n return \"togetherAI\";\n }\n\n get lc_secrets(): { [key: string]: string } | undefined {\n return {\n togetherAIApiKey: \"TOGETHER_AI_API_KEY\",\n apiKey: \"TOGETHER_AI_API_KEY\",\n };\n }\n\n get lc_aliases(): { [key: string]: string } | undefined {\n return {\n togetherAIApiKey: \"together_ai_api_key\",\n apiKey: \"together_ai_api_key\",\n };\n }\n\n constructor(fields?: Partial<ChatTogetherAIInput>) {\n const togetherAIApiKey =\n fields?.apiKey ||\n fields?.togetherAIApiKey ||\n getEnvironmentVariable(\"TOGETHER_AI_API_KEY\");\n\n if (!togetherAIApiKey) {\n throw new Error(\n 'Together AI API key not found. Please set the TOGETHER_AI_API_KEY environment variable or pass the key into the \"apiKey\" field.'\n );\n }\n\n super({\n ...fields,\n model: fields?.model || \"mistralai/Mixtral-8x7B-Instruct-v0.1\",\n apiKey: togetherAIApiKey,\n configuration: {\n baseURL: \"https://api.together.xyz/v1/\",\n ...fields?.configuration,\n },\n });\n this._addVersion(\"@langchain/together-ai\", __PKG_VERSION__);\n }\n\n getLsParams(options: this[\"ParsedCallOptions\"]): LangSmithParams {\n const params = super.getLsParams(options);\n params.ls_provider = \"together\";\n return params;\n }\n\n toJSON() {\n const result = super.toJSON();\n\n if (\n \"kwargs\" in result &&\n typeof result.kwargs === \"object\" &&\n result.kwargs != null\n ) {\n delete result.kwargs.openai_api_key;\n delete result.kwargs.configuration;\n }\n\n return result;\n }\n\n async completionWithRetry(\n request: OpenAIClient.Chat.ChatCompletionCreateParamsStreaming,\n options?: OpenAICoreRequestOptions\n ): Promise<AsyncIterable<OpenAIClient.Chat.Completions.ChatCompletionChunk>>;\n\n async completionWithRetry(\n request: OpenAIClient.Chat.ChatCompletionCreateParamsNonStreaming,\n options?: OpenAICoreRequestOptions\n ): Promise<OpenAIClient.Chat.Completions.ChatCompletion>;\n\n async completionWithRetry(\n request:\n | OpenAIClient.Chat.ChatCompletionCreateParamsStreaming\n | OpenAIClient.Chat.ChatCompletionCreateParamsNonStreaming,\n options?: OpenAICoreRequestOptions\n ): Promise<\n | AsyncIterable<OpenAIClient.Chat.Completions.ChatCompletionChunk>\n | OpenAIClient.Chat.Completions.ChatCompletion\n > {\n delete request.frequency_penalty;\n delete request.presence_penalty;\n delete request.logit_bias;\n delete request.functions;\n\n return super.completionWithRetry(request, options);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAoEA,IAAa,iBAAb,cAAoC,sBAAiD;CACnF,OAAO,UAAU;AACf,SAAO;;CAGT,kBAAkB;CAElB,eAAe;EAAC;EAAa;EAAe;EAAc;CAE1D,WAAW;AACT,SAAO;;CAGT,IAAI,aAAoD;AACtD,SAAO;GACL,kBAAkB;GAClB,QAAQ;GACT;;CAGH,IAAI,aAAoD;AACtD,SAAO;GACL,kBAAkB;GAClB,QAAQ;GACT;;CAGH,YAAY,QAAuC;EACjD,MAAM,mBACJ,QAAQ,UACR,QAAQ,oBACR,uBAAuB,sBAAsB;AAE/C,MAAI,CAAC,iBACH,OAAM,IAAI,MACR,oIACD;AAGH,QAAM;GACJ,GAAG;GACH,OAAO,QAAQ,SAAS;GACxB,QAAQ;GACR,eAAe;IACb,SAAS;IACT,GAAG,QAAQ;IACZ;GACF,CAAC;AACF,OAAK,YAAY,0BAAA,QAA0C;;CAG7D,YAAY,SAAqD;EAC/D,MAAM,SAAS,MAAM,YAAY,QAAQ;AACzC,SAAO,cAAc;AACrB,SAAO;;CAGT,SAAS;EACP,MAAM,SAAS,MAAM,QAAQ;AAE7B,MACE,YAAY,UACZ,OAAO,OAAO,WAAW,YACzB,OAAO,UAAU,MACjB;AACA,UAAO,OAAO,OAAO;AACrB,UAAO,OAAO,OAAO;;AAGvB,SAAO;;CAaT,MAAM,oBACJ,SAGA,SAIA;AACA,SAAO,QAAQ;AACf,SAAO,QAAQ;AACf,SAAO,QAAQ;AACf,SAAO,QAAQ;AAEf,SAAO,MAAM,oBAAoB,SAAS,QAAQ"}
@@ -0,0 +1,80 @@
1
+ let _langchain_core_utils_env = require("@langchain/core/utils/env");
2
+ let _langchain_core_embeddings = require("@langchain/core/embeddings");
3
+ let _langchain_core_utils_chunk_array = require("@langchain/core/utils/chunk_array");
4
+ //#region src/embeddings.ts
5
+ /**
6
+ * Class for generating embeddings using the Together AI embeddings API.
7
+ */
8
+ var TogetherAIEmbeddings = class extends _langchain_core_embeddings.Embeddings {
9
+ lc_serializable = true;
10
+ lc_namespace = [
11
+ "langchain",
12
+ "embeddings",
13
+ "together_ai"
14
+ ];
15
+ modelName = "togethercomputer/m2-bert-80M-8k-retrieval";
16
+ model = "togethercomputer/m2-bert-80M-8k-retrieval";
17
+ apiKey;
18
+ batchSize = 512;
19
+ stripNewLines = false;
20
+ timeout;
21
+ embeddingsAPIUrl = "https://api.together.xyz/v1/embeddings";
22
+ get lc_secrets() {
23
+ return { apiKey: "TOGETHER_AI_API_KEY" };
24
+ }
25
+ constructor(fields) {
26
+ super(fields ?? {});
27
+ const apiKey = fields?.apiKey ?? (0, _langchain_core_utils_env.getEnvironmentVariable)("TOGETHER_AI_API_KEY");
28
+ if (!apiKey) throw new Error("TOGETHER_AI_API_KEY not found.");
29
+ this.apiKey = apiKey;
30
+ this.modelName = fields?.model ?? fields?.modelName ?? this.model;
31
+ this.model = this.modelName;
32
+ this.timeout = fields?.timeout;
33
+ this.batchSize = fields?.batchSize ?? this.batchSize;
34
+ this.stripNewLines = fields?.stripNewLines ?? this.stripNewLines;
35
+ }
36
+ constructHeaders() {
37
+ return {
38
+ accept: "application/json",
39
+ "content-type": "application/json",
40
+ Authorization: `Bearer ${this.apiKey}`
41
+ };
42
+ }
43
+ constructBody(input) {
44
+ return {
45
+ model: this.model,
46
+ input
47
+ };
48
+ }
49
+ async embedDocuments(texts) {
50
+ const batches = (0, _langchain_core_utils_chunk_array.chunkArray)(this.stripNewLines ? texts.map((t) => t.replace(/\n/g, " ")) : texts, this.batchSize);
51
+ let batchResponses = [];
52
+ for await (const batch of batches) {
53
+ const batchRequests = batch.map((item) => this.embeddingWithRetry(item));
54
+ const response = await Promise.all(batchRequests);
55
+ batchResponses = batchResponses.concat(response);
56
+ }
57
+ return batchResponses.map((response) => response.data[0].embedding);
58
+ }
59
+ async embedQuery(text) {
60
+ const { data } = await this.embeddingWithRetry(this.stripNewLines ? text.replace(/\n/g, " ") : text);
61
+ return data[0].embedding;
62
+ }
63
+ async embeddingWithRetry(input) {
64
+ const body = JSON.stringify(this.constructBody(input));
65
+ const headers = this.constructHeaders();
66
+ return this.caller.call(async () => {
67
+ const fetchResponse = await fetch(this.embeddingsAPIUrl, {
68
+ method: "POST",
69
+ headers,
70
+ body
71
+ });
72
+ if (fetchResponse.status === 200) return fetchResponse.json();
73
+ throw new Error(`Error getting prompt completion from Together AI. ${JSON.stringify(await fetchResponse.json(), null, 2)}`);
74
+ });
75
+ }
76
+ };
77
+ //#endregion
78
+ exports.TogetherAIEmbeddings = TogetherAIEmbeddings;
79
+
80
+ //# sourceMappingURL=embeddings.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"embeddings.cjs","names":["Embeddings"],"sources":["../src/embeddings.ts"],"sourcesContent":["import { Embeddings, type EmbeddingsParams } from \"@langchain/core/embeddings\";\nimport { chunkArray } from \"@langchain/core/utils/chunk_array\";\nimport { getEnvironmentVariable } from \"@langchain/core/utils/env\";\n\nexport interface TogetherAIEmbeddingsParams extends EmbeddingsParams {\n /**\n * The API key to use for the Together AI API.\n * @default {process.env.TOGETHER_AI_API_KEY}\n */\n apiKey?: string;\n /**\n * Model name to use.\n * Alias for `model`.\n * @default {\"togethercomputer/m2-bert-80M-8k-retrieval\"}\n */\n modelName?: string;\n /**\n * Model name to use.\n * @default {\"togethercomputer/m2-bert-80M-8k-retrieval\"}\n */\n model?: string;\n /**\n * Timeout to use when making requests to Together AI.\n */\n timeout?: number;\n /**\n * The maximum number of documents to embed in a single logical batch.\n * @default {512}\n */\n batchSize?: number;\n /**\n * Whether to strip new lines from the input text.\n * @default {false}\n */\n stripNewLines?: boolean;\n}\n\ninterface TogetherAIEmbeddingsResult {\n object: string;\n data: Array<{\n object: \"embedding\";\n embedding: number[];\n index: number;\n }>;\n model: string;\n request_id: string;\n}\n\n/**\n * Class for generating embeddings using the Together AI embeddings API.\n */\nexport class TogetherAIEmbeddings\n extends Embeddings\n implements TogetherAIEmbeddingsParams\n{\n lc_serializable = true;\n\n lc_namespace = [\"langchain\", \"embeddings\", \"together_ai\"];\n\n modelName = \"togethercomputer/m2-bert-80M-8k-retrieval\";\n\n model = \"togethercomputer/m2-bert-80M-8k-retrieval\";\n\n apiKey: string;\n\n batchSize = 512;\n\n stripNewLines = false;\n\n timeout?: number;\n\n private embeddingsAPIUrl = \"https://api.together.xyz/v1/embeddings\";\n\n get lc_secrets(): { [key: string]: string } | undefined {\n return {\n apiKey: \"TOGETHER_AI_API_KEY\",\n };\n }\n\n constructor(fields?: Partial<TogetherAIEmbeddingsParams>) {\n super(fields ?? {});\n\n const apiKey =\n fields?.apiKey ?? getEnvironmentVariable(\"TOGETHER_AI_API_KEY\");\n if (!apiKey) {\n throw new Error(\"TOGETHER_AI_API_KEY not found.\");\n }\n\n this.apiKey = apiKey;\n this.modelName = fields?.model ?? fields?.modelName ?? this.model;\n this.model = this.modelName;\n this.timeout = fields?.timeout;\n this.batchSize = fields?.batchSize ?? this.batchSize;\n this.stripNewLines = fields?.stripNewLines ?? this.stripNewLines;\n }\n\n private constructHeaders() {\n return {\n accept: \"application/json\",\n \"content-type\": \"application/json\",\n Authorization: `Bearer ${this.apiKey}`,\n };\n }\n\n private constructBody(input: string) {\n return {\n model: this.model,\n input,\n };\n }\n\n async embedDocuments(texts: string[]): Promise<number[][]> {\n const batches = chunkArray(\n this.stripNewLines ? texts.map((t) => t.replace(/\\n/g, \" \")) : texts,\n this.batchSize\n );\n\n let batchResponses: TogetherAIEmbeddingsResult[] = [];\n for await (const batch of batches) {\n const batchRequests = batch.map((item) => this.embeddingWithRetry(item));\n const response = await Promise.all(batchRequests);\n batchResponses = batchResponses.concat(response);\n }\n\n return batchResponses.map((response) => response.data[0].embedding);\n }\n\n async embedQuery(text: string): Promise<number[]> {\n const { data } = await this.embeddingWithRetry(\n this.stripNewLines ? text.replace(/\\n/g, \" \") : text\n );\n return data[0].embedding;\n }\n\n private async embeddingWithRetry(\n input: string\n ): Promise<TogetherAIEmbeddingsResult> {\n const body = JSON.stringify(this.constructBody(input));\n const headers = this.constructHeaders();\n\n return this.caller.call(async () => {\n const fetchResponse = await fetch(this.embeddingsAPIUrl, {\n method: \"POST\",\n headers,\n body,\n });\n\n if (fetchResponse.status === 200) {\n return fetchResponse.json();\n }\n throw new Error(\n `Error getting prompt completion from Together AI. ${JSON.stringify(\n await fetchResponse.json(),\n null,\n 2\n )}`\n );\n });\n }\n}\n"],"mappings":";;;;;;;AAmDA,IAAa,uBAAb,cACUA,2BAAAA,WAEV;CACE,kBAAkB;CAElB,eAAe;EAAC;EAAa;EAAc;EAAc;CAEzD,YAAY;CAEZ,QAAQ;CAER;CAEA,YAAY;CAEZ,gBAAgB;CAEhB;CAEA,mBAA2B;CAE3B,IAAI,aAAoD;AACtD,SAAO,EACL,QAAQ,uBACT;;CAGH,YAAY,QAA8C;AACxD,QAAM,UAAU,EAAE,CAAC;EAEnB,MAAM,SACJ,QAAQ,WAAA,GAAA,0BAAA,wBAAiC,sBAAsB;AACjE,MAAI,CAAC,OACH,OAAM,IAAI,MAAM,iCAAiC;AAGnD,OAAK,SAAS;AACd,OAAK,YAAY,QAAQ,SAAS,QAAQ,aAAa,KAAK;AAC5D,OAAK,QAAQ,KAAK;AAClB,OAAK,UAAU,QAAQ;AACvB,OAAK,YAAY,QAAQ,aAAa,KAAK;AAC3C,OAAK,gBAAgB,QAAQ,iBAAiB,KAAK;;CAGrD,mBAA2B;AACzB,SAAO;GACL,QAAQ;GACR,gBAAgB;GAChB,eAAe,UAAU,KAAK;GAC/B;;CAGH,cAAsB,OAAe;AACnC,SAAO;GACL,OAAO,KAAK;GACZ;GACD;;CAGH,MAAM,eAAe,OAAsC;EACzD,MAAM,WAAA,GAAA,kCAAA,YACJ,KAAK,gBAAgB,MAAM,KAAK,MAAM,EAAE,QAAQ,OAAO,IAAI,CAAC,GAAG,OAC/D,KAAK,UACN;EAED,IAAI,iBAA+C,EAAE;AACrD,aAAW,MAAM,SAAS,SAAS;GACjC,MAAM,gBAAgB,MAAM,KAAK,SAAS,KAAK,mBAAmB,KAAK,CAAC;GACxE,MAAM,WAAW,MAAM,QAAQ,IAAI,cAAc;AACjD,oBAAiB,eAAe,OAAO,SAAS;;AAGlD,SAAO,eAAe,KAAK,aAAa,SAAS,KAAK,GAAG,UAAU;;CAGrE,MAAM,WAAW,MAAiC;EAChD,MAAM,EAAE,SAAS,MAAM,KAAK,mBAC1B,KAAK,gBAAgB,KAAK,QAAQ,OAAO,IAAI,GAAG,KACjD;AACD,SAAO,KAAK,GAAG;;CAGjB,MAAc,mBACZ,OACqC;EACrC,MAAM,OAAO,KAAK,UAAU,KAAK,cAAc,MAAM,CAAC;EACtD,MAAM,UAAU,KAAK,kBAAkB;AAEvC,SAAO,KAAK,OAAO,KAAK,YAAY;GAClC,MAAM,gBAAgB,MAAM,MAAM,KAAK,kBAAkB;IACvD,QAAQ;IACR;IACA;IACD,CAAC;AAEF,OAAI,cAAc,WAAW,IAC3B,QAAO,cAAc,MAAM;AAE7B,SAAM,IAAI,MACR,qDAAqD,KAAK,UACxD,MAAM,cAAc,MAAM,EAC1B,MACA,EACD,GACF;IACD"}
@@ -0,0 +1,61 @@
1
+ import { Embeddings, EmbeddingsParams } from "@langchain/core/embeddings";
2
+
3
+ //#region src/embeddings.d.ts
4
+ interface TogetherAIEmbeddingsParams extends EmbeddingsParams {
5
+ /**
6
+ * The API key to use for the Together AI API.
7
+ * @default {process.env.TOGETHER_AI_API_KEY}
8
+ */
9
+ apiKey?: string;
10
+ /**
11
+ * Model name to use.
12
+ * Alias for `model`.
13
+ * @default {"togethercomputer/m2-bert-80M-8k-retrieval"}
14
+ */
15
+ modelName?: string;
16
+ /**
17
+ * Model name to use.
18
+ * @default {"togethercomputer/m2-bert-80M-8k-retrieval"}
19
+ */
20
+ model?: string;
21
+ /**
22
+ * Timeout to use when making requests to Together AI.
23
+ */
24
+ timeout?: number;
25
+ /**
26
+ * The maximum number of documents to embed in a single logical batch.
27
+ * @default {512}
28
+ */
29
+ batchSize?: number;
30
+ /**
31
+ * Whether to strip new lines from the input text.
32
+ * @default {false}
33
+ */
34
+ stripNewLines?: boolean;
35
+ }
36
+ /**
37
+ * Class for generating embeddings using the Together AI embeddings API.
38
+ */
39
+ declare class TogetherAIEmbeddings extends Embeddings implements TogetherAIEmbeddingsParams {
40
+ lc_serializable: boolean;
41
+ lc_namespace: string[];
42
+ modelName: string;
43
+ model: string;
44
+ apiKey: string;
45
+ batchSize: number;
46
+ stripNewLines: boolean;
47
+ timeout?: number;
48
+ private embeddingsAPIUrl;
49
+ get lc_secrets(): {
50
+ [key: string]: string;
51
+ } | undefined;
52
+ constructor(fields?: Partial<TogetherAIEmbeddingsParams>);
53
+ private constructHeaders;
54
+ private constructBody;
55
+ embedDocuments(texts: string[]): Promise<number[][]>;
56
+ embedQuery(text: string): Promise<number[]>;
57
+ private embeddingWithRetry;
58
+ }
59
+ //#endregion
60
+ export { TogetherAIEmbeddings, TogetherAIEmbeddingsParams };
61
+ //# sourceMappingURL=embeddings.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"embeddings.d.cts","names":[],"sources":["../src/embeddings.ts"],"mappings":";;;UAIiB,0BAAA,SAAmC,gBAAA;;AAApD;;;EAKE,MAAA;EALkD;;;;;EAWlD,SAAA;EAmBA;;;AAiBF;EA/BE,KAAA;;;;EAIA,OAAA;EAuGgC;;;;EAlGhC,SAAA;EAuBQ;;;;EAlBR,aAAA;AAAA;;;;cAiBW,oBAAA,SACH,UAAA,YACG,0BAAA;EAEX,eAAA;EAEA,YAAA;EAEA,SAAA;EAEA,KAAA;EAEA,MAAA;EAEA,SAAA;EAEA,aAAA;EAEA,OAAA;EAAA,QAEQ,gBAAA;EAAA,IAEJ,UAAA,CAAA;IAAA,CAAiB,GAAA;EAAA;EAMrB,WAAA,CAAY,MAAA,GAAS,OAAA,CAAQ,0BAAA;EAAA,QAiBrB,gBAAA;EAAA,QAQA,aAAA;EAOF,cAAA,CAAe,KAAA,aAAkB,OAAA;EAgBjC,UAAA,CAAW,IAAA,WAAe,OAAA;EAAA,QAOlB,kBAAA;AAAA"}