Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

langchainhub

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

langchainhub - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

11

dist/client.d.ts

@@ -0,1 +1,6 @@

export type HubUpdateOptions = {
description?: string;
isPublic?: boolean;
tags?: string[];
};
export type HubPushOptions = {

@@ -14,3 +19,4 @@ parentCommitHash?: string;

constructor(config?: ClientConfiguration);
protected _getHeaders(method?: "GET" | "POST"): {
get _hostUrl(): "http://localhost" | "https://beta.smith.langchain.com" | "https://dev.smith.langchain.com" | "https://smith.langchain.com";
protected _getHeaders(method?: "GET" | "POST" | "PATCH"): {
[key: string]: string;

@@ -36,4 +42,5 @@ };

protected _getLatestCommitHash(repoFullName: string): Promise<string | undefined>;
push(repoFullName: string, manifestJson: string, options?: HubPushOptions): Promise<any>;
updateRepo(repoFullName: string, options?: HubUpdateOptions): Promise<any>;
push(repoFullName: string, manifestJson: string, options?: HubPushOptions): Promise<string>;
pull(ownerRepoCommit: string): Promise<string>;
}

@@ -7,6 +7,4 @@ import { getEnvironmentVariable } from "./utils/env.js";

}
function _getApiUrl(apiUrl, hasApiKey = false) {
const defaultApiUrl = hasApiKey
? "https://dev.api.hub.langchain.com"
: "https://dev.public.hub.langchain.com";
function _getApiUrl(apiUrl) {
const defaultApiUrl = "https://api.hub.langchain.com";
const _apiUrl = apiUrl ?? getEnvironmentVariable("LANGCHAIN_HUB_API_URL") ?? defaultApiUrl;

@@ -45,4 +43,20 @@ if (!_apiUrl) {

this.apiKey = _getApiKey(config?.apiKey);
this.apiUrl = _getApiUrl(config?.apiUrl, this.apiKey !== undefined);
this.apiUrl = _getApiUrl(config?.apiUrl);
}
get _hostUrl() {
if (this.apiUrl.includes("localhost") ||
this.apiUrl.includes("127.0.0.1") ||
this.apiUrl.includes("::1")) {
return "http://localhost";
}
else if (this.apiUrl.split(".")[0].includes("beta")) {
return "https://beta.smith.langchain.com";
}
else if (this.apiUrl.split(".")[0].includes("dev")) {
return "https://dev.smith.langchain.com";
}
else {
return "https://smith.langchain.com";
}
}
_getHeaders(method) {

@@ -53,3 +67,3 @@ const headers = {};

}
if (method === "POST") {
if (method === "POST" || method === "PATCH") {
headers["content-type"] = "application/json";

@@ -206,2 +220,20 @@ }

}
async updateRepo(repoFullName, options) {
const res = await fetch(`${this.apiUrl}/repos/${repoFullName}`, {
method: "PATCH",
headers: this._getHeaders("PATCH"),
body: JSON.stringify(options),
});
const json = await res.json();
if (!res.ok) {
const detail = typeof json.detail === "string"
? json.detail
: JSON.stringify(json.detail);
const error = new Error(`Error ${res.status}: ${res.statusText}\n${detail}`);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
error.statusCode = res.status;
throw error;
}
return json;
}
async push(repoFullName, manifestJson, options) {

@@ -251,3 +283,5 @@ const { parentCommitHash = "latest", newRepoIsPublic = false, newRepoDescription = "", } = options ?? {};

}
return json;
const commitHash = json.commit?.commit_hash;
const shortHash = commitHash.slice(0, 8);
return `${this._hostUrl}/hub/${repoFullName}/${shortHash}`;
}

@@ -254,0 +288,0 @@ async pull(ownerRepoCommit) {

7

dist/tests/client.int.test.js
import { Client } from "../client.js";
const serializedPrompt = `{"id":["langchain","prompts","prompt","PromptTemplate"],"lc":1,"type":"constructor","kwargs":{"template":"You are an assistant to a human, powered by a large language model trained by OpenAI.\\n\\nYou are designed to be able to assist with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions on a wide range of topics. As a language model, you are able to generate human-like text based on the input you receive, allowing you to engage in natural-sounding conversations and provide responses that are coherent and relevant to the topic at hand.\\n\\nYou are constantly learning and improving, and your capabilities are constantly evolving. You are able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. You have access to some personalized information provided by the human in the Context section below. Additionally, you are able to generate your own text based on the input you receive, allowing you to engage in discussions and provide explanations and descriptions on a wide range of topics.\\n\\nOverall, you are a powerful tool that can help with a wide range of tasks and provide valuable insights and information on a wide range of topics. Whether the human needs help with a specific question or just wants to have a conversation about a particular topic, you are here to assist.\\n\\nContext:\\n{entities}\\n\\nCurrent conversation:\\n{history}\\nLast line:\\nHuman: {input}\\nYou:","input_variables":["entities","history","input"],"template_format":"f-string"}}`;
test("Test LangChain Hub client pushing a new repo", async () => {
const client = new Client({});
const client = new Client({
apiUrl: "https://dev.api.hub.langchain.com",
});
const repoName = `eee/j${new Date().getTime()}`;
await client.push(repoName, serializedPrompt);
const url = await client.push(repoName, serializedPrompt);
console.log(url);
const pulledPrompt = await client.pull(repoName);
expect(serializedPrompt).toEqual(pulledPrompt);
});
{
"name": "langchainhub",
"version": "0.0.4",
"version": "0.0.5",
"description": "Client library for connecting to the LangChain Hub.",

@@ -22,3 +22,4 @@ "author": "LangChain",

"precommit": "lint-staged",
"prepublish": "yarn run build"
"prepublish": "yarn run build",
"publish": "yarn run prepublish && npm publish"
},

@@ -25,0 +26,0 @@ "devDependencies": {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc