-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
hub.ts
35 lines (33 loc) · 1.08 KB
/
hub.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { Client, ClientConfiguration, HubPushOptions } from "langchainhub";
import { Runnable } from "@langchain/core/runnables";
import { load } from "./load/index.js";
/**
* Push a prompt to the hub.
* If the specified repo doesn't already exist, it will be created.
* @param repoFullName The full name of the repo.
* @param runnable The prompt to push.
* @param options
* @returns The URL of the newly pushed prompt in the hub.
*/
export async function push(
repoFullName: string,
runnable: Runnable,
options?: HubPushOptions & ClientConfiguration
) {
const client = new Client(options);
return client.push(repoFullName, JSON.stringify(runnable), options);
}
/**
* Pull a prompt from the hub.
* @param ownerRepoCommit The name of the repo containing the prompt, as well as an optional commit hash separated by a slash.
* @param options
* @returns
*/
export async function pull<T extends Runnable>(
ownerRepoCommit: string,
options?: ClientConfiguration
) {
const client = new Client(options);
const result = await client.pull(ownerRepoCommit);
return load<T>(result);
}