{"id":21012252,"url":"https://github.com/codebanesr/llms-client","last_synced_at":"2025-05-15T04:33:01.548Z","repository":{"id":167255239,"uuid":"642846901","full_name":"codebanesr/llms-client","owner":"codebanesr","description":"A client to make chat completion requests to any llm [currently supports chatgpt and claude]","archived":false,"fork":false,"pushed_at":"2023-05-25T23:22:59.000Z","size":203,"stargazers_count":14,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-11T12:46:38.987Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codebanesr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-05-19T13:31:32.000Z","updated_at":"2024-07-07T07:47:31.000Z","dependencies_parsed_at":"2023-07-06T14:01:21.427Z","dependency_job_id":null,"html_url":"https://github.com/codebanesr/llms-client","commit_stats":null,"previous_names":["shanurrahman/llms-client","codebanesr/llms-client"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codebanesr%2Fllms-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codebanesr%2Fllms-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codebanesr%2Fllms-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codebanesr%2Fllms-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codebanesr","download_url":"https://codeload.github.com/codebanesr/llms-client/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225327506,"owners_count":17457116,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-19T09:35:58.855Z","updated_at":"2024-11-19T09:35:59.597Z","avatar_url":"https://github.com/codebanesr.png","language":"TypeScript","readme":"## 📦 llms-client - Connect to Multiple Language Models (LLMs)\n\nA 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!\n\n🔗 Get it on [npm](https://www.npmjs.com/package/llms-client)\n\n#AI #Development #LLMs\n\n## Installation\n\nTo install the package, use npm:\n\n```bash\nnpm install llms-client\n```\n\n## Usage\n\nTo use the package, follow these steps:\n\n1. 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.\n\n   ```typescript\n   import { CompletionServiceSelector, AdapterConfig } from 'llms-client';\n\n   const adapterConfig: AdapterConfig = {\n     type: 'chatGPT', // Specify the desired language model: 'chatGPT', 'claudeAI', or 'bard'\n     baseurl: '\u003cbase-url\u003e', // Set the base URL for the adapter\n     apiKey: '\u003capi-key\u003e', // Set the API key for authentication\n     model: '\u003cmodel\u003e', // Optional: Specify the model for the adapter (if applicable)\n   };\n   ```\n\n2. Get chat completions by providing a list of messages and the maximum number of tokens in the completion response.\n\n```ts\nconst messages: Message[] = [\n  { role: \"system\", content: \"Welcome!\" },\n  { role: \"user\", content: \"Hello, how are you?\" },\n  { role: \"assistant\", content: \"I'm doing well, thank you!\" },\n];\n\nconst { CompletionServiceSelector } = require(\"../dist/index\");\n\nasync function completePrompt(prompt, maxTokens) {\n  const config = {\n    apiKey: \"\",\n    baseurl: \"https://api.openai.com\",\n    type: \"chatGPT\",\n    model: \"text-davinci-003\",\n  };\n\n  const service = new CompletionServiceSelector(config);\n\n  // only supports gpt-3.5-turbo\n  const chat_completion = await service.getChatCompletions(messages, maxTokens);\n  console.log({ chat_completion });\n}\n\ncompletePrompt(\"What is the purpose of life ?\", 300)\n  .then((data) =\u003e {\n    console.log(data);\n  })\n  .catch((e) =\u003e {\n    console.error(e);\n  });\n```\n\n---\n\n### Claude full example\n```ts\nconst { CompletionServiceSelector } = require('../dist/index');\n\nasync function completePrompt(prompt, maxTokens) {\n  const config = {\n    apiKey: '',\n    baseurl: 'https://api.anthropic.com/v1/complete',\n    type: 'claudeAI',\n    model: 'claude-v1'\n  };\n\n  const service = new CompletionServiceSelector(config);\n\n  const completionResponse = await service.complete(prompt, maxTokens);\n  console.log(completionResponse);\n\n  /** \n   * the last message's content has to be left empty... This will be filled by claude \n   * */ \n  const messages = [\n    { role: 'Human', content: 'Tell me a haiku about trees' },\n    { role: 'Assistant', content: '' }\n  ];\n\n  const chatResponse = await service.getChatCompletions(messages, 300);\n  console.log(chatResponse);\n}\n\ncompletePrompt('What is the capital of united states', 300)\n  .then(data =\u003e {\n    console.log(data);\n  })\n  .catch(e =\u003e {\n    console.error(e);\n  });\n```\n\n3. Make a completion with a prompt by providing the prompt and the maximum number of tokens in the completion response.\n\n   ```typescript\n   const prompt = 'Hello, world!';\n   completionService.complete(prompt, maxTokens)\n     .then((response: string) =\u003e {\n       // Handle the completion response\n       console.log(response);\n     })\n     .catch((error: Error) =\u003e {\n       // Handle errors\n       console.error(error);\n     });\n   ```\n\n## Available Scripts\n\nThe following scripts are available in the project's `package.json` file:\n\n- `start`: Starts the development server in watch mode.\n- `build`: Builds the package for production.\n- `test`: Runs tests for the package.\n- `lint`: Lints the package's source code.\n- `prepare`: Builds the package before publishing or versioning.\n- `size`: Checks the package size using size-limit.\n- `analyze`: Analyzes the package size and provides reasons using size-limit.\n\nYou can run these scripts using npm. For example:\n\n```bash\nnpm run build\n```\n\n## Usage examples\n[GPT usage example](test/gpt.test.js)\n[Claude(Anthropic) usage example](test/claude.test.js)\n[Bard usage example](test/bard.test.js) Coming soon\n\n## Configuration\n\nThe package can be configured using the `package.json` file. Some important fields include:\n\n- `name`: The name of the package.\n- `author`: The author of the package.\n- `module`: The entry point for the package's ES module version.\n\n## Contribution\n\nPlease follow the [Contribution Guide](CONTRIBUTING.md) for detailed instructions on how to contribute to this project.\n\n## Contributors\n\nThank you to the following people for their contributions to this project:\n\n* [Shanur Rahman](https://github.com/shanur-rahman) (shanur.cse.nitap@gmail.com)\n* [Marzoog AlGhazwi](https://github.com/Marzoog-Alghazwi) (marzoog.m.alghazwi@gmail.com)\n\n## License\n\nThis package is licensed under the MIT License.\n\n## Author\n\nThis package was created by Shanur Rahman.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodebanesr%2Fllms-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodebanesr%2Fllms-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodebanesr%2Fllms-client/lists"}