@belcore/langchain 0.0.0-stage → 0.1.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 CHANGED
@@ -1,3 +1,3 @@
1
- # Temporary Holding Version
1
+ # @belcore/langchain
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ See the [Belcore integrations README](https://github.com/terracore-kr/belcore-integrations#readme).
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @belcore/langchain — Belcore as a LangChain.js chat model.
3
+ *
4
+ * const model = new ChatBelcore({ model: "openai/gpt-4o-mini" })
5
+ * const res = await model.invoke(historyFromYourDb)
6
+ * res.response_metadata.belcore.emotion // save for the next call
7
+ */
8
+ import { BaseChatModel, type BaseChatModelParams } from "@langchain/core/language_models/chat_models";
9
+ import { type BaseMessage } from "@langchain/core/messages";
10
+ import type { ChatResult } from "@langchain/core/outputs";
11
+ import { type BelcoreClientOptions, type ChatRequest } from "@belcore/sdk";
12
+ export interface ChatBelcoreParams extends BaseChatModelParams, BelcoreClientOptions {
13
+ model?: string;
14
+ /** Defaults sent with every call; per-call values can be passed via invoke(..., { belcore: {...} }). */
15
+ belcore?: Omit<ChatRequest, "messages" | "system" | "model">;
16
+ }
17
+ type CallOptions = ChatBelcore["ParsedCallOptions"] & {
18
+ belcore?: Omit<ChatRequest, "messages" | "system" | "model">;
19
+ };
20
+ export declare class ChatBelcore extends BaseChatModel {
21
+ static lc_name(): string;
22
+ model?: string;
23
+ private client;
24
+ private defaults;
25
+ constructor(params?: ChatBelcoreParams);
26
+ _llmType(): string;
27
+ _generate(messages: BaseMessage[], options: CallOptions): Promise<ChatResult>;
28
+ }
29
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @belcore/langchain — Belcore as a LangChain.js chat model.
3
+ *
4
+ * const model = new ChatBelcore({ model: "openai/gpt-4o-mini" })
5
+ * const res = await model.invoke(historyFromYourDb)
6
+ * res.response_metadata.belcore.emotion // save for the next call
7
+ */
8
+ import { BaseChatModel } from "@langchain/core/language_models/chat_models";
9
+ import { AIMessage } from "@langchain/core/messages";
10
+ import { Belcore } from "@belcore/sdk";
11
+ export class ChatBelcore extends BaseChatModel {
12
+ static lc_name() { return "ChatBelcore"; }
13
+ model;
14
+ client;
15
+ defaults;
16
+ constructor(params = {}) {
17
+ super(params);
18
+ this.model = params.model;
19
+ this.client = new Belcore(params);
20
+ this.defaults = params.belcore ?? {};
21
+ }
22
+ _llmType() { return "belcore"; }
23
+ async _generate(messages, options) {
24
+ const systems = [];
25
+ const out = [];
26
+ for (const m of messages) {
27
+ const type = m._getType();
28
+ const text = typeof m.content === "string" ? m.content : m.content.map((c) => ("text" in c && typeof c.text === "string" ? c.text : "")).join("\n");
29
+ if (type === "system")
30
+ systems.push(text);
31
+ else if (type === "human")
32
+ out.push({ role: "user", content: text });
33
+ else if (type === "ai")
34
+ out.push({ role: "assistant", content: text });
35
+ }
36
+ const res = await this.client.chat({ ...this.defaults, ...(options.belcore ?? {}), messages: out, ...(systems.length ? { system: systems.join("\n\n") } : {}), ...(this.model ? { model: this.model } : {}) }, { signal: options.signal });
37
+ const meta = { belcore: { emotion: res.emotion, memory: res.memory, degraded: res.degraded ?? false } };
38
+ return {
39
+ generations: [{ text: res.reply, message: new AIMessage({ content: res.reply, response_metadata: meta }) }],
40
+ llmOutput: { tokenUsage: { promptTokens: res.usage?.inputTokens, completionTokens: res.usage?.outputTokens } },
41
+ };
42
+ }
43
+ }
package/package.json CHANGED
@@ -1,6 +1,41 @@
1
1
  {
2
2
  "name": "@belcore/langchain",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Belcore chat model for LangChain.js",
5
+ "keywords": [
6
+ "langchain",
7
+ "memory",
8
+ "belcore"
9
+ ],
10
+ "license": "Apache-2.0",
11
+ "type": "module",
12
+ "main": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js"
18
+ }
19
+ },
20
+ "dependencies": {
21
+ "@belcore/sdk": "0.1.0"
22
+ },
23
+ "peerDependencies": {
24
+ "@langchain/core": ">=1"
25
+ },
26
+ "files": [
27
+ "dist",
28
+ "README.md"
29
+ ],
30
+ "scripts": {
31
+ "build": "tsc -p tsconfig.build.json"
32
+ },
33
+ "homepage": "https://belcore.xyz",
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "https://github.com/terracore-kr/belcore-integrations"
37
+ },
38
+ "engines": {
39
+ "node": ">=18"
40
+ }
6
41
  }