llms-client
v3.0.0
Published
A powerful package that enables users to effortlessly connect to various Language Models, including Claude, Bard, and ChatGPT. Stay tuned for upcoming support for Vicuna and Alpaca!
Downloads
18
Readme
📦 llms-client - Connect to Multiple Language Models (LLMs)
A powerful package that enables users to effortlessly connect to various Language Models, including Claude, Bard, and ChatGPT. Stay tuned for upcoming support for Vicuna and Alpaca!
🔗 Get it on npm
#AI #Development #LLMs
Installation
To install the package, use npm:
npm install llms-client
Usage
To use the package, follow these steps:
Import and create an instance of the
CompletionServiceSelector
class, providing the appropriate adapter configuration. The adapter configuration should include the type of LLM, base URL, and API key.import { CompletionServiceSelector, AdapterConfig } from 'llms-client'; const adapterConfig: AdapterConfig = { type: 'chatGPT', // Specify the desired language model: 'chatGPT', 'claudeAI', or 'bard' baseurl: '<base-url>', // Set the base URL for the adapter apiKey: '<api-key>', // Set the API key for authentication model: '<model>', // Optional: Specify the model for the adapter (if applicable) };
Get chat completions by providing a list of messages and the maximum number of tokens in the completion response.
const messages: Message[] = [
{ role: "system", content: "Welcome!" },
{ role: "user", content: "Hello, how are you?" },
{ role: "assistant", content: "I'm doing well, thank you!" },
];
const { CompletionServiceSelector } = require("../dist/index");
async function completePrompt(prompt, maxTokens) {
const config = {
apiKey: "",
baseurl: "https://api.openai.com",
type: "chatGPT",
model: "text-davinci-003",
};
const service = new CompletionServiceSelector(config);
// only supports gpt-3.5-turbo
const chat_completion = await service.getChatCompletions(messages, maxTokens);
console.log({ chat_completion });
}
completePrompt("What is the purpose of life ?", 300)
.then((data) => {
console.log(data);
})
.catch((e) => {
console.error(e);
});
Claude full example
const { CompletionServiceSelector } = require('../dist/index');
async function completePrompt(prompt, maxTokens) {
const config = {
apiKey: '',
baseurl: 'https://api.anthropic.com/v1/complete',
type: 'claudeAI',
model: 'claude-v1'
};
const service = new CompletionServiceSelector(config);
const completionResponse = await service.complete(prompt, maxTokens);
console.log(completionResponse);
/**
* the last message's content has to be left empty... This will be filled by claude
* */
const messages = [
{ role: 'Human', content: 'Tell me a haiku about trees' },
{ role: 'Assistant', content: '' }
];
const chatResponse = await service.getChatCompletions(messages, 300);
console.log(chatResponse);
}
completePrompt('What is the capital of united states', 300)
.then(data => {
console.log(data);
})
.catch(e => {
console.error(e);
});
Make a completion with a prompt by providing the prompt and the maximum number of tokens in the completion response.
const prompt = 'Hello, world!'; completionService.complete(prompt, maxTokens) .then((response: string) => { // Handle the completion response console.log(response); }) .catch((error: Error) => { // Handle errors console.error(error); });
Available Scripts
The following scripts are available in the project's package.json
file:
start
: Starts the development server in watch mode.build
: Builds the package for production.test
: Runs tests for the package.lint
: Lints the package's source code.prepare
: Builds the package before publishing or versioning.size
: Checks the package size using size-limit.analyze
: Analyzes the package size and provides reasons using size-limit.
You can run these scripts using npm. For example:
npm run build
Usage examples
GPT usage example Claude(Anthropic) usage example Bard usage example Coming soon
Configuration
The package can be configured using the package.json
file. Some important fields include:
name
: The name of the package.author
: The author of the package.module
: The entry point for the package's ES module version.
Contribution
Please follow the Contribution Guide for detailed instructions on how to contribute to this project.
Contributors
Thank you to the following people for their contributions to this project:
License
This package is licensed under the MIT License.
Author
This package was created by Shanur Rahman.