{"id":19977434,"url":"https://github.com/dmickelson/llmfactoryproject","last_synced_at":"2026-04-15T20:01:50.195Z","repository":{"id":254831496,"uuid":"847359784","full_name":"dmickelson/LLMFactoryProject","owner":"dmickelson","description":"Simple factory pattern that lets you choose different LLM providers on a dynamic basis","archived":false,"fork":false,"pushed_at":"2024-09-05T20:23:20.000Z","size":12,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-12T10:09:10.194Z","etag":null,"topics":["chatgpt","factory-pattern","gemini","llm","openai","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dmickelson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-25T15:52:33.000Z","updated_at":"2024-10-30T13:31:12.000Z","dependencies_parsed_at":"2024-08-26T12:56:30.621Z","dependency_job_id":"c1bb2339-c7ce-4477-a2e5-63186bb89511","html_url":"https://github.com/dmickelson/LLMFactoryProject","commit_stats":null,"previous_names":["dmickelson/llmfactoryproject"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmickelson%2FLLMFactoryProject","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmickelson%2FLLMFactoryProject/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmickelson%2FLLMFactoryProject/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmickelson%2FLLMFactoryProject/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dmickelson","download_url":"https://codeload.github.com/dmickelson/LLMFactoryProject/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241411542,"owners_count":19958753,"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":["chatgpt","factory-pattern","gemini","llm","openai","python"],"created_at":"2024-11-13T03:28:02.725Z","updated_at":"2026-04-15T20:01:50.131Z","avatar_url":"https://github.com/dmickelson.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LLM Factory Project\n\nThis project implements a simple factory pattern that allows you to dynamically choose different Language Model (LLM) providers. It uses the Instructor module under the hood for getting structured output.\n\n## Features\n\n- Supports multiple LLM providers: OpenAI, Anthropic, Cohere, and Ollama\n- Dynamic selection of LLM provider at runtime\n- Structured output using Pydantic models\n- Caching of settings for improved performance\n- Environment-based configuration using .env files\n\n## Usage\n\nTo use the LLM Factory, follow these steps:\n\n1. Set up your environment variables in a `.env` file with the necessary API keys for each provider.\n2. Import the `LLMFactory` and `CompletionModel` from the `llmfactory` module.\n3. Create an instance of `LLMFactory` with your chosen provider.\n4. Use the `create_completion` method to generate responses.\n\nExample:\n\n```python\nfrom llmfactory import llm_factory\n\nmessages = [\n    {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n    {\"role\": \"user\", \"content\": \"If it takes 2 hours to dry 1 shirt out in the sun, how long will it take to dry 5 shirts?\"},\n]\n\nllm = llm_factory.LLMFactory(\"cohere\")\ncompletion = llm.create_completion(\n    response_model=llm_factory.CompletionModel,\n    messages=messages,\n)\n\nprint(f\"Response: {completion.response}\")\nprint(f\"Reasoning: {completion.reasoning}\")\n```\n\n## Project Structure\n\n- llmfactory/llm_factory.py: Contains the main LLMFactory class and CompletionModel.\n- llmfactory/settings.py: Defines the settings for each LLM provider using Pydantic.\n- main.py: Provides an example of how to use the LLM Factory.\n\n## Class Diagram\n\n```mermaid\nclassDiagram\n    class LLMFactory {\n        +LLMProviders provider\n        +LLMSettings settings\n        +_initialize_client()\n        +create_completion()\n    }\n\n    class Settings {\n        +OpenAISettings openai\n        +AnthropicSettings anthropic\n        +OllamaSettings ollama\n        +CohereSettings cohere\n    }\n\n    class OpenAISettings {\n        +String api_key\n        +String default_model\n        +int max_tokens\n    }\n\n    class AnthropicSettings {\n        +String api_key\n        +String default_model\n        +int max_tokens\n    }\n\n    class CohereSettings {\n        +String api_key\n        +String default_model\n        +int max_tokens\n    }\n\n    class OllamaSettings {\n        +String api_key\n        +String default_model\n        +String base_url\n    }\n\n    class CompletionModel {\n        +String response\n        +String reasoning\n    }\n\n    LLMFactory --\u003e Settings\n    LLMFactory --\u003e CompletionModel\n    Settings --\u003e OpenAISettings\n    Settings --\u003e AnthropicSettings\n    Settings --\u003e OllamaSettings\n    Settings --\u003e CohereSettings\n\n    Settings \u003c|-- get_settings\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmickelson%2Fllmfactoryproject","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdmickelson%2Fllmfactoryproject","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmickelson%2Fllmfactoryproject/lists"}