langchain 0.0.207 → 0.0.209-rc.0
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/README.md +74 -19
- package/dist/experimental/autogpt/output_parser.cjs +10 -5
- package/dist/experimental/autogpt/output_parser.d.ts +3 -2
- package/dist/experimental/autogpt/output_parser.js +10 -5
- package/dist/experimental/chat_models/ollama_functions.d.ts +2 -3
- package/dist/experimental/openai_assistant/index.cjs +1 -1
- package/dist/experimental/openai_assistant/index.js +1 -1
- package/dist/load/import_constants.cjs +1 -0
- package/dist/load/import_constants.js +1 -0
- package/dist/retrievers/vectara_summary.cjs +17 -0
- package/dist/retrievers/vectara_summary.d.ts +1 -0
- package/dist/retrievers/vectara_summary.js +1 -0
- package/package.json +12 -4
- package/retrievers/vectara_summary.cjs +1 -0
- package/retrievers/vectara_summary.d.ts +1 -0
- package/retrievers/vectara_summary.js +1 -0
- package/dist/util/ollama.cjs +0 -47
- package/dist/util/ollama.d.ts +0 -89
- package/dist/util/ollama.js +0 -43
package/README.md
CHANGED
|
@@ -3,23 +3,25 @@
|
|
|
3
3
|
⚡ Building applications with LLMs through composability ⚡
|
|
4
4
|
|
|
5
5
|
[](https://github.com/langchain-ai/langchainjs/actions/workflows/ci.yml)  [](https://opensource.org/licenses/MIT) [](https://twitter.com/langchainai) [](https://discord.gg/6adMQxSpJS) [](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/langchain-ai/langchainjs)
|
|
6
|
-
[<img src="https://github.com/codespaces/badge.svg" title="Open in Github Codespace" width="150" height="20">](https://codespaces.new/
|
|
6
|
+
[<img src="https://github.com/codespaces/badge.svg" title="Open in Github Codespace" width="150" height="20">](https://codespaces.new/langchain-ai/langchainjs)
|
|
7
7
|
|
|
8
8
|
Looking for the Python version? Check out [LangChain](https://github.com/langchain-ai/langchain).
|
|
9
9
|
|
|
10
10
|
To help you ship LangChain apps to production faster, check out [LangSmith](https://smith.langchain.com).
|
|
11
11
|
[LangSmith](https://smith.langchain.com) is a unified developer platform for building, testing, and monitoring LLM applications.
|
|
12
|
-
Fill out [this form](https://airtable.com/appwQzlErAS2qiP0L/shrGtGaVBVAz7NcV2) to get off the waitlist or speak with our sales team
|
|
12
|
+
Fill out [this form](https://airtable.com/appwQzlErAS2qiP0L/shrGtGaVBVAz7NcV2) to get off the waitlist or speak with our sales team.
|
|
13
13
|
|
|
14
|
-
## Quick Install
|
|
14
|
+
## ⚡️ Quick Install
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
You can use npm, yarn, or pnpm to install LangChain.js
|
|
17
|
+
|
|
18
|
+
`npm install -S langchain` or `yarn add langchain` or `pnpm add langchain`
|
|
17
19
|
|
|
18
20
|
```typescript
|
|
19
|
-
import {
|
|
21
|
+
import { ChatOpenAI } from "langchain/chat_models/openai";
|
|
20
22
|
```
|
|
21
23
|
|
|
22
|
-
## Supported Environments
|
|
24
|
+
## 🌐 Supported Environments
|
|
23
25
|
|
|
24
26
|
LangChain is written in TypeScript and can be used in:
|
|
25
27
|
|
|
@@ -30,27 +32,80 @@ LangChain is written in TypeScript and can be used in:
|
|
|
30
32
|
- Browser
|
|
31
33
|
- Deno
|
|
32
34
|
|
|
33
|
-
## 🤔 What is
|
|
35
|
+
## 🤔 What is LangChain?
|
|
34
36
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
create a truly powerful app - the real power comes when you can combine them with other sources of computation or knowledge.
|
|
37
|
+
**LangChain** is a framework for developing applications powered by language models. It enables applications that:
|
|
38
|
+
- **Are context-aware**: connect a language model to sources of context (prompt instructions, few shot examples, content to ground its response in, etc.)
|
|
39
|
+
- **Reason**: rely on a language model to reason (about how to answer based on provided context, what actions to take, etc.)
|
|
39
40
|
|
|
40
|
-
This
|
|
41
|
+
This framework consists of several parts.
|
|
42
|
+
- **LangChain Libraries**: The Python and JavaScript libraries. Contains interfaces and integrations for a myriad of components, a basic runtime for combining these components into chains and agents, and off-the-shelf implementations of chains and agents.
|
|
43
|
+
- **[LangChain Templates](https://github.com/langchain-ai/langchain/tree/master/templates)**: (currently Python-only) A collection of easily deployable reference architectures for a wide variety of tasks.
|
|
44
|
+
- **[LangServe](https://github.com/langchain-ai/langserve)**: (currently Python-only) A library for deploying LangChain chains as a REST API.
|
|
45
|
+
- **[LangSmith](https://smith.langchain.com)**: A developer platform that lets you debug, test, evaluate, and monitor chains built on any LLM framework and seamlessly integrates with LangChain.
|
|
41
46
|
|
|
42
|
-
|
|
47
|
+
The LangChain libraries themselves are made up of several different packages.
|
|
48
|
+
- **[`@langchain/core`](https://github.com/langchain-ai/langchainjs/blob/main/langchain-core)**: Base abstractions and LangChain Expression Language.
|
|
49
|
+
- **[`@langchain/community`](https://github.com/langchain-ai/langchainjs/blob/main/libs/langchain-community)**: Third party integrations.
|
|
50
|
+
- **[`langchain`](https://github.com/langchain-ai/langchainjs/blob/main/langchain)**: Chains, agents, and retrieval strategies that make up an application's cognitive architecture.
|
|
43
51
|
|
|
44
|
-
|
|
52
|
+
Integrations may also be split into their own compatible packages.
|
|
45
53
|
|
|
46
|
-
|
|
54
|
+

|
|
47
55
|
|
|
48
|
-
This
|
|
56
|
+
This library aims to assist in the development of those types of applications. Common examples of these applications include:
|
|
57
|
+
|
|
58
|
+
**❓Question Answering over specific documents**
|
|
59
|
+
|
|
60
|
+
- [Documentation](https://js.langchain.com/docs/use_cases/question_answering/)
|
|
61
|
+
- End-to-end Example: [Doc-Chatbot](https://github.com/dissorial/doc-chatbot)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
**💬 Chatbots**
|
|
65
|
+
|
|
66
|
+
- [Documentation](https://js.langchain.com/docs/modules/model_io/models/chat/)
|
|
67
|
+
- End-to-end Example: [Chat-LangChain](https://github.com/langchain-ai/chat-langchain)
|
|
68
|
+
|
|
69
|
+
## 🚀 How does LangChain help?
|
|
70
|
+
|
|
71
|
+
The main value props of the LangChain libraries are:
|
|
72
|
+
1. **Components**: composable tools and integrations for working with language models. Components are modular and easy-to-use, whether you are using the rest of the LangChain framework or not
|
|
73
|
+
2. **Off-the-shelf chains**: built-in assemblages of components for accomplishing higher-level tasks
|
|
74
|
+
|
|
75
|
+
Off-the-shelf chains make it easy to get started. Components make it easy to customize existing chains and build new ones.
|
|
76
|
+
|
|
77
|
+
Components fall into the following **modules**:
|
|
78
|
+
|
|
79
|
+
**📃 Model I/O:**
|
|
49
80
|
|
|
50
|
-
|
|
81
|
+
This includes prompt management, prompt optimization, a generic interface for all LLMs, and common utilities for working with LLMs.
|
|
82
|
+
|
|
83
|
+
**📚 Retrieval:**
|
|
84
|
+
|
|
85
|
+
Data Augmented Generation involves specific types of chains that first interact with an external data source to fetch data for use in the generation step. Examples include summarization of long pieces of text and question/answering over specific data sources.
|
|
86
|
+
|
|
87
|
+
**🤖 Agents:**
|
|
88
|
+
|
|
89
|
+
Agents involve an LLM making decisions about which Actions to take, taking that Action, seeing an Observation, and repeating that until done. LangChain provides a standard interface for agents, a selection of agents to choose from, and examples of end-to-end agents.
|
|
90
|
+
|
|
91
|
+
## 📖 Documentation
|
|
92
|
+
|
|
93
|
+
Please see [here](https://js.langchain.com) for full documentation, which includes:
|
|
94
|
+
|
|
95
|
+
- [Getting started](https://js.langchain.com/docs/get_started/introduction): installation, setting up the environment, simple examples
|
|
96
|
+
- Overview of the [interfaces](https://js.langchain.com/docs/expression_language/), [modules](https://js.langchain.com/docs/modules/) and [integrations](https://js.langchain.com/docs/integrations/platforms)
|
|
97
|
+
- [Use case](https://js.langchain.com/docs/use_cases/) walkthroughs and best practice [guides](https://js.langchain.com/docs/guides/)
|
|
98
|
+
- [Reference](https://api.js.langchain.com): full API docs
|
|
51
99
|
|
|
52
100
|
## 💁 Contributing
|
|
53
101
|
|
|
54
|
-
As an open
|
|
102
|
+
As an open-source project in a rapidly developing field, we are extremely open to contributions, whether it be in the form of a new feature, improved infrastructure, or better documentation.
|
|
103
|
+
|
|
104
|
+
For detailed information on how to contribute, see [here](https://github.com/langchain-ai/langchainjs/blob/main/CONTRIBUTING.md).
|
|
105
|
+
|
|
106
|
+
Please report any security issues or concerns following our [security guidelines](https://github.com/langchain-ai/langchainjs/blob/main/SECURITY.md).
|
|
107
|
+
|
|
108
|
+
## 🖇️ Relationship with Python LangChain
|
|
109
|
+
|
|
110
|
+
This is built to integrate as seamlessly as possible with the [LangChain Python package](https://github.com/langchain-ai/langchain). Specifically, this means all objects (prompts, LLMs, chains, etc) are designed in a way where they can be serialized and shared between languages.
|
|
55
111
|
|
|
56
|
-
Check out [our contributing guidelines](https://github.com/langchain-ai/langchainjs/blob/main/CONTRIBUTING.md) for instructions on how to contribute.
|
|
@@ -3,15 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AutoGPTOutputParser = exports.preprocessJsonInput = void 0;
|
|
4
4
|
const output_parser_js_1 = require("../../schema/output_parser.cjs");
|
|
5
5
|
/**
|
|
6
|
-
* Utility function used to preprocess a string to be parsed as JSON.
|
|
7
|
-
* replaces single backslashes with double backslashes, while leaving
|
|
6
|
+
* Utility function used to preprocess a string to be parsed as JSON.
|
|
7
|
+
* It replaces single backslashes with double backslashes, while leaving
|
|
8
8
|
* already escaped ones intact.
|
|
9
|
+
* It also extracts the json code if it is inside a code block
|
|
9
10
|
*/
|
|
10
11
|
function preprocessJsonInput(inputStr) {
|
|
11
|
-
// Replace single backslashes with double backslashes,
|
|
12
|
-
// while leaving already escaped ones intact
|
|
13
12
|
const correctedStr = inputStr.replace(/(?<!\\)\\(?!["\\/bfnrt]|u[0-9a-fA-F]{4})/g, "\\\\");
|
|
14
|
-
|
|
13
|
+
const match = correctedStr.match(/```(.*)(\r\n|\r|\n)(?<code>[\w\W\n]+)(\r\n|\r|\n)```/);
|
|
14
|
+
if (match?.groups?.code) {
|
|
15
|
+
return match.groups.code.trim();
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
return correctedStr;
|
|
19
|
+
}
|
|
15
20
|
}
|
|
16
21
|
exports.preprocessJsonInput = preprocessJsonInput;
|
|
17
22
|
/**
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { BaseOutputParser } from "../../schema/output_parser.js";
|
|
2
2
|
import { AutoGPTAction } from "./schema.js";
|
|
3
3
|
/**
|
|
4
|
-
* Utility function used to preprocess a string to be parsed as JSON.
|
|
5
|
-
* replaces single backslashes with double backslashes, while leaving
|
|
4
|
+
* Utility function used to preprocess a string to be parsed as JSON.
|
|
5
|
+
* It replaces single backslashes with double backslashes, while leaving
|
|
6
6
|
* already escaped ones intact.
|
|
7
|
+
* It also extracts the json code if it is inside a code block
|
|
7
8
|
*/
|
|
8
9
|
export declare function preprocessJsonInput(inputStr: string): string;
|
|
9
10
|
/**
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import { BaseOutputParser } from "../../schema/output_parser.js";
|
|
2
2
|
/**
|
|
3
|
-
* Utility function used to preprocess a string to be parsed as JSON.
|
|
4
|
-
* replaces single backslashes with double backslashes, while leaving
|
|
3
|
+
* Utility function used to preprocess a string to be parsed as JSON.
|
|
4
|
+
* It replaces single backslashes with double backslashes, while leaving
|
|
5
5
|
* already escaped ones intact.
|
|
6
|
+
* It also extracts the json code if it is inside a code block
|
|
6
7
|
*/
|
|
7
8
|
export function preprocessJsonInput(inputStr) {
|
|
8
|
-
// Replace single backslashes with double backslashes,
|
|
9
|
-
// while leaving already escaped ones intact
|
|
10
9
|
const correctedStr = inputStr.replace(/(?<!\\)\\(?!["\\/bfnrt]|u[0-9a-fA-F]{4})/g, "\\\\");
|
|
11
|
-
|
|
10
|
+
const match = correctedStr.match(/```(.*)(\r\n|\r|\n)(?<code>[\w\W\n]+)(\r\n|\r|\n)```/);
|
|
11
|
+
if (match?.groups?.code) {
|
|
12
|
+
return match.groups.code.trim();
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
return correctedStr;
|
|
16
|
+
}
|
|
12
17
|
}
|
|
13
18
|
/**
|
|
14
19
|
* Class responsible for parsing the output of AutoGPT. It extends the
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { BaseChatModel, BaseChatModelParams } from "../../chat_models/base.js";
|
|
2
2
|
import { CallbackManagerForLLMRun } from "../../callbacks/manager.js";
|
|
3
3
|
import { BaseMessage, ChatResult } from "../../schema/index.js";
|
|
4
|
-
import { ChatOllama } from "../../chat_models/ollama.js";
|
|
5
|
-
import { OllamaInput } from "../../util/ollama.js";
|
|
4
|
+
import { ChatOllama, type ChatOllamaInput } from "../../chat_models/ollama.js";
|
|
6
5
|
import { BaseFunctionCallOptions } from "../../base_language/index.js";
|
|
7
6
|
export interface ChatOllamaFunctionsCallOptions extends BaseFunctionCallOptions {
|
|
8
7
|
}
|
|
9
|
-
export type OllamaFunctionsInput = Partial<
|
|
8
|
+
export type OllamaFunctionsInput = Partial<ChatOllamaInput> & BaseChatModelParams & {
|
|
10
9
|
llm?: ChatOllama;
|
|
11
10
|
toolSystemPromptTemplate?: string;
|
|
12
11
|
};
|
|
@@ -103,7 +103,7 @@ class OpenAIAssistantRunnable extends base_js_1.Runnable {
|
|
|
103
103
|
else {
|
|
104
104
|
// Submitting tool outputs to an existing run, outside the AgentExecutor
|
|
105
105
|
// framework.
|
|
106
|
-
run = await this.client.beta.threads.runs.submitToolOutputs(input.
|
|
106
|
+
run = await this.client.beta.threads.runs.submitToolOutputs(input.threadId, input.runId, {
|
|
107
107
|
tool_outputs: input.toolOutputs,
|
|
108
108
|
});
|
|
109
109
|
}
|
|
@@ -100,7 +100,7 @@ export class OpenAIAssistantRunnable extends Runnable {
|
|
|
100
100
|
else {
|
|
101
101
|
// Submitting tool outputs to an existing run, outside the AgentExecutor
|
|
102
102
|
// framework.
|
|
103
|
-
run = await this.client.beta.threads.runs.submitToolOutputs(input.
|
|
103
|
+
run = await this.client.beta.threads.runs.submitToolOutputs(input.threadId, input.runId, {
|
|
104
104
|
tool_outputs: input.toolOutputs,
|
|
105
105
|
});
|
|
106
106
|
}
|
|
@@ -135,6 +135,7 @@ exports.optionalImportEntrypoints = [
|
|
|
135
135
|
"langchain/retrievers/supabase",
|
|
136
136
|
"langchain/retrievers/zep",
|
|
137
137
|
"langchain/retrievers/metal",
|
|
138
|
+
"langchain/retrievers/vectara_summary",
|
|
138
139
|
"langchain/retrievers/self_query",
|
|
139
140
|
"langchain/retrievers/self_query/chroma",
|
|
140
141
|
"langchain/retrievers/self_query/functional",
|
|
@@ -132,6 +132,7 @@ export const optionalImportEntrypoints = [
|
|
|
132
132
|
"langchain/retrievers/supabase",
|
|
133
133
|
"langchain/retrievers/zep",
|
|
134
134
|
"langchain/retrievers/metal",
|
|
135
|
+
"langchain/retrievers/vectara_summary",
|
|
135
136
|
"langchain/retrievers/self_query",
|
|
136
137
|
"langchain/retrievers/self_query/chroma",
|
|
137
138
|
"langchain/retrievers/self_query/functional",
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("@langchain/community/retrievers/vectara_summary"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@langchain/community/retrievers/vectara_summary";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@langchain/community/retrievers/vectara_summary";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "langchain",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.209-rc.0",
|
|
4
4
|
"description": "Typescript bindings for langchain",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -643,6 +643,9 @@
|
|
|
643
643
|
"retrievers/parent_document.cjs",
|
|
644
644
|
"retrievers/parent_document.js",
|
|
645
645
|
"retrievers/parent_document.d.ts",
|
|
646
|
+
"retrievers/vectara_summary.cjs",
|
|
647
|
+
"retrievers/vectara_summary.js",
|
|
648
|
+
"retrievers/vectara_summary.d.ts",
|
|
646
649
|
"retrievers/tavily_search_api.cjs",
|
|
647
650
|
"retrievers/tavily_search_api.js",
|
|
648
651
|
"retrievers/tavily_search_api.d.ts",
|
|
@@ -1175,9 +1178,9 @@
|
|
|
1175
1178
|
},
|
|
1176
1179
|
"dependencies": {
|
|
1177
1180
|
"@anthropic-ai/sdk": "^0.9.1",
|
|
1178
|
-
"@langchain/community": "~0.0.
|
|
1179
|
-
"@langchain/core": "~0.1.
|
|
1180
|
-
"@langchain/openai": "~0.0.
|
|
1181
|
+
"@langchain/community": "~0.0.7-rc.0",
|
|
1182
|
+
"@langchain/core": "~0.1.2-rc.0",
|
|
1183
|
+
"@langchain/openai": "~0.0.6-rc.0",
|
|
1181
1184
|
"binary-extensions": "^2.2.0",
|
|
1182
1185
|
"expr-eval": "^2.0.2",
|
|
1183
1186
|
"js-tiktoken": "^1.0.7",
|
|
@@ -2266,6 +2269,11 @@
|
|
|
2266
2269
|
"import": "./retrievers/parent_document.js",
|
|
2267
2270
|
"require": "./retrievers/parent_document.cjs"
|
|
2268
2271
|
},
|
|
2272
|
+
"./retrievers/vectara_summary": {
|
|
2273
|
+
"types": "./retrievers/vectara_summary.d.ts",
|
|
2274
|
+
"import": "./retrievers/vectara_summary.js",
|
|
2275
|
+
"require": "./retrievers/vectara_summary.cjs"
|
|
2276
|
+
},
|
|
2269
2277
|
"./retrievers/tavily_search_api": {
|
|
2270
2278
|
"types": "./retrievers/tavily_search_api.d.ts",
|
|
2271
2279
|
"import": "./retrievers/tavily_search_api.js",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/retrievers/vectara_summary.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/retrievers/vectara_summary.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/retrievers/vectara_summary.js'
|
package/dist/util/ollama.cjs
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createOllamaStream = void 0;
|
|
4
|
-
const stream_js_1 = require("./stream.cjs");
|
|
5
|
-
async function* createOllamaStream(baseUrl, params, options) {
|
|
6
|
-
let formattedBaseUrl = baseUrl;
|
|
7
|
-
if (formattedBaseUrl.startsWith("http://localhost:")) {
|
|
8
|
-
// Node 18 has issues with resolving "localhost"
|
|
9
|
-
// See https://github.com/node-fetch/node-fetch/issues/1624
|
|
10
|
-
formattedBaseUrl = formattedBaseUrl.replace("http://localhost:", "http://127.0.0.1:");
|
|
11
|
-
}
|
|
12
|
-
const response = await fetch(`${formattedBaseUrl}/api/generate`, {
|
|
13
|
-
method: "POST",
|
|
14
|
-
body: JSON.stringify(params),
|
|
15
|
-
headers: {
|
|
16
|
-
"Content-Type": "application/json",
|
|
17
|
-
},
|
|
18
|
-
signal: options.signal,
|
|
19
|
-
});
|
|
20
|
-
if (!response.ok) {
|
|
21
|
-
const json = await response.json();
|
|
22
|
-
const error = new Error(`Ollama call failed with status code ${response.status}: ${json.error}`);
|
|
23
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
|
-
error.response = response;
|
|
25
|
-
throw error;
|
|
26
|
-
}
|
|
27
|
-
if (!response.body) {
|
|
28
|
-
throw new Error("Could not begin Ollama stream. Please check the given URL and try again.");
|
|
29
|
-
}
|
|
30
|
-
const stream = stream_js_1.IterableReadableStream.fromReadableStream(response.body);
|
|
31
|
-
const decoder = new TextDecoder();
|
|
32
|
-
let extra = "";
|
|
33
|
-
for await (const chunk of stream) {
|
|
34
|
-
const decoded = extra + decoder.decode(chunk);
|
|
35
|
-
const lines = decoded.split("\n");
|
|
36
|
-
extra = lines.pop() || "";
|
|
37
|
-
for (const line of lines) {
|
|
38
|
-
try {
|
|
39
|
-
yield JSON.parse(line);
|
|
40
|
-
}
|
|
41
|
-
catch (e) {
|
|
42
|
-
console.warn(`Received a non-JSON parseable chunk: ${line}`);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
exports.createOllamaStream = createOllamaStream;
|
package/dist/util/ollama.d.ts
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { BaseLanguageModelCallOptions } from "../base_language/index.js";
|
|
2
|
-
import type { StringWithAutocomplete } from "./types.js";
|
|
3
|
-
export interface OllamaInput {
|
|
4
|
-
embeddingOnly?: boolean;
|
|
5
|
-
f16KV?: boolean;
|
|
6
|
-
frequencyPenalty?: number;
|
|
7
|
-
logitsAll?: boolean;
|
|
8
|
-
lowVram?: boolean;
|
|
9
|
-
mainGpu?: number;
|
|
10
|
-
model?: string;
|
|
11
|
-
baseUrl?: string;
|
|
12
|
-
mirostat?: number;
|
|
13
|
-
mirostatEta?: number;
|
|
14
|
-
mirostatTau?: number;
|
|
15
|
-
numBatch?: number;
|
|
16
|
-
numCtx?: number;
|
|
17
|
-
numGpu?: number;
|
|
18
|
-
numGqa?: number;
|
|
19
|
-
numKeep?: number;
|
|
20
|
-
numThread?: number;
|
|
21
|
-
penalizeNewline?: boolean;
|
|
22
|
-
presencePenalty?: number;
|
|
23
|
-
repeatLastN?: number;
|
|
24
|
-
repeatPenalty?: number;
|
|
25
|
-
ropeFrequencyBase?: number;
|
|
26
|
-
ropeFrequencyScale?: number;
|
|
27
|
-
temperature?: number;
|
|
28
|
-
stop?: string[];
|
|
29
|
-
tfsZ?: number;
|
|
30
|
-
topK?: number;
|
|
31
|
-
topP?: number;
|
|
32
|
-
typicalP?: number;
|
|
33
|
-
useMLock?: boolean;
|
|
34
|
-
useMMap?: boolean;
|
|
35
|
-
vocabOnly?: boolean;
|
|
36
|
-
format?: StringWithAutocomplete<"json">;
|
|
37
|
-
}
|
|
38
|
-
export interface OllamaRequestParams {
|
|
39
|
-
model: string;
|
|
40
|
-
prompt: string;
|
|
41
|
-
format?: StringWithAutocomplete<"json">;
|
|
42
|
-
options: {
|
|
43
|
-
embedding_only?: boolean;
|
|
44
|
-
f16_kv?: boolean;
|
|
45
|
-
frequency_penalty?: number;
|
|
46
|
-
logits_all?: boolean;
|
|
47
|
-
low_vram?: boolean;
|
|
48
|
-
main_gpu?: number;
|
|
49
|
-
mirostat?: number;
|
|
50
|
-
mirostat_eta?: number;
|
|
51
|
-
mirostat_tau?: number;
|
|
52
|
-
num_batch?: number;
|
|
53
|
-
num_ctx?: number;
|
|
54
|
-
num_gpu?: number;
|
|
55
|
-
num_gqa?: number;
|
|
56
|
-
num_keep?: number;
|
|
57
|
-
num_thread?: number;
|
|
58
|
-
penalize_newline?: boolean;
|
|
59
|
-
presence_penalty?: number;
|
|
60
|
-
repeat_last_n?: number;
|
|
61
|
-
repeat_penalty?: number;
|
|
62
|
-
rope_frequency_base?: number;
|
|
63
|
-
rope_frequency_scale?: number;
|
|
64
|
-
temperature?: number;
|
|
65
|
-
stop?: string[];
|
|
66
|
-
tfs_z?: number;
|
|
67
|
-
top_k?: number;
|
|
68
|
-
top_p?: number;
|
|
69
|
-
typical_p?: number;
|
|
70
|
-
use_mlock?: boolean;
|
|
71
|
-
use_mmap?: boolean;
|
|
72
|
-
vocab_only?: boolean;
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
export interface OllamaCallOptions extends BaseLanguageModelCallOptions {
|
|
76
|
-
}
|
|
77
|
-
export type OllamaGenerationChunk = {
|
|
78
|
-
response: string;
|
|
79
|
-
model: string;
|
|
80
|
-
created_at: string;
|
|
81
|
-
done: boolean;
|
|
82
|
-
total_duration?: number;
|
|
83
|
-
load_duration?: number;
|
|
84
|
-
prompt_eval_count?: number;
|
|
85
|
-
prompt_eval_duration?: number;
|
|
86
|
-
eval_count?: number;
|
|
87
|
-
eval_duration?: number;
|
|
88
|
-
};
|
|
89
|
-
export declare function createOllamaStream(baseUrl: string, params: OllamaRequestParams, options: OllamaCallOptions): AsyncGenerator<OllamaGenerationChunk>;
|
package/dist/util/ollama.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { IterableReadableStream } from "./stream.js";
|
|
2
|
-
export async function* createOllamaStream(baseUrl, params, options) {
|
|
3
|
-
let formattedBaseUrl = baseUrl;
|
|
4
|
-
if (formattedBaseUrl.startsWith("http://localhost:")) {
|
|
5
|
-
// Node 18 has issues with resolving "localhost"
|
|
6
|
-
// See https://github.com/node-fetch/node-fetch/issues/1624
|
|
7
|
-
formattedBaseUrl = formattedBaseUrl.replace("http://localhost:", "http://127.0.0.1:");
|
|
8
|
-
}
|
|
9
|
-
const response = await fetch(`${formattedBaseUrl}/api/generate`, {
|
|
10
|
-
method: "POST",
|
|
11
|
-
body: JSON.stringify(params),
|
|
12
|
-
headers: {
|
|
13
|
-
"Content-Type": "application/json",
|
|
14
|
-
},
|
|
15
|
-
signal: options.signal,
|
|
16
|
-
});
|
|
17
|
-
if (!response.ok) {
|
|
18
|
-
const json = await response.json();
|
|
19
|
-
const error = new Error(`Ollama call failed with status code ${response.status}: ${json.error}`);
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
-
error.response = response;
|
|
22
|
-
throw error;
|
|
23
|
-
}
|
|
24
|
-
if (!response.body) {
|
|
25
|
-
throw new Error("Could not begin Ollama stream. Please check the given URL and try again.");
|
|
26
|
-
}
|
|
27
|
-
const stream = IterableReadableStream.fromReadableStream(response.body);
|
|
28
|
-
const decoder = new TextDecoder();
|
|
29
|
-
let extra = "";
|
|
30
|
-
for await (const chunk of stream) {
|
|
31
|
-
const decoded = extra + decoder.decode(chunk);
|
|
32
|
-
const lines = decoded.split("\n");
|
|
33
|
-
extra = lines.pop() || "";
|
|
34
|
-
for (const line of lines) {
|
|
35
|
-
try {
|
|
36
|
-
yield JSON.parse(line);
|
|
37
|
-
}
|
|
38
|
-
catch (e) {
|
|
39
|
-
console.warn(`Received a non-JSON parseable chunk: ${line}`);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|