Package: ai-microcore
AI MicroCore: A Minimalistic Foundation for AI Applicationsmicrocoreis a collection of python adapters for Large Language Models
and Semantic Search APIs allowing to
communicate with these services in a convenient way, make it easily switchable
and separate business logic from implementation details.It defines interfaces for features typically used in AI applications,
that allows you to keep your application as simple as possible and try various models & services
without need to change your application code.You even can switch between text completion and chat completion models only using configuration.The basic example of usage is as follows:frommicrocoreimportllmwhileuser_msg:=input('Enter message: '):print('AI: '+llm(user_msg))🔗 LinksAPI ReferencePyPi PackageGitHub Repository💻 InstallationInstall as PyPi package:pip install ai-microcoreAlternatively, you may just copymicrocorefolder to your project sources root.gitclonegit@github.com:Nayjest/ai-microcore.git&&mvai-microcore/microcore./&&rm-rfai-microcore📋 RequirementsPython 3.10+ / 3.11+Both v0.28.X and v1.x.x OpenAI package versions are supported.⚙️ ConfiguringMinimal ConfigurationHavingOPENAI_API_KEYin OS environment variables is enough for basic usage.Similarity search features will work out of the box if you have thechromadbpip package installed.Configuration MethodsThere are a few options available for configuring microcore:Usemicrocore.configure()💡 All configuration options should be available in IDE autocompletion tooltipsCreate a.envfile in your project root (example)Use a custom configuration file:mc.configure(DOT_ENV_FILE='dev-config.ini')Define OS environment variablesFor the full list of available configuration options, you may also checkmicrocore/config.py.Priority of Configuration SourcesConfiguration options passed as arguments tomicrocore.configure()have the highest priority.The priority of configuration file options (.envby default or the value ofDOT_ENV_FILE) is higher than OS environment variables.💡 SettingUSE_DOT_ENVtofalsedisables reading configuration files.OS environment variables have the lowest priority.🌟 Core Functionsllm(prompt: str, **kwargs) → strPerforms a request to a large language model (LLM)frommicrocoreimport*# Will print all requests and responses to consoleuse_logging()# Basic usageai_response=llm('What is your model name?')# You also may pass a list of strings as prompt# - For chat completion models elements are treated as separate messages# - For completion LLMs elements are treated as text linesllm(['1+2','='])llm('1+2=',model='gpt-4')# To specify a message role, you can use dictionary or classesllm(dict(role='system',content='1+2='))# equivalentllm(SysMsg('1+2='))# The returned value is a stringassert'7'==llm([SysMsg('You are a calculator'),UserMsg('1+2='),AssistantMsg('3'),UserMsg('3+4=')]).strip()# But it contains all fields of the LLM response in additional attributesforiinllm('1+2=?',n=3,temperature=2).choices:print('RESPONSE:',i.message.content)# To use response streaming you may specify the callback function:llm('Hi there',callback=lambdax:print(x,end=''))# Or multiple callbacks:output=[]llm('Hi there',callbacks=[lambdax:print(x,end=''),lambdax:output.append(x),])tpl(file_path, **params) → strRenders prompt template with params.Full-featured Jinja2 templates are used by default.Related configuration options:frommicrocoreimportconfigureconfigure(# 'tpl' folder in current working directory by defaultPROMPT_TEMPLATES_PATH='my_templates_folder')texts.search(collection: str, query: str | list, n_results: int = 5, where: dict = None, **kwargs) → list[str]Similarity searchtexts.find_one(self, collection: str, query: str | list) → str | NoneFind most similar texttexts.get_all(self, collection: str) -> list[str]Return collection of textstexts.save(collection: str, text: str, metadata: dict = None))Store text and related metadata in embeddings databasetexts.save_many(collection: str, items: list[tuple[str, dict] | str])Store multiple texts and related metadata in the embeddings databasetexts.clear(collection: str):Clear collectionAPI providers and models supportLLM Microcore supports all models & API providers having OpenAI API.List of API providers and models tested with LLM Microcore:API ProviderModelsOpenAIAll GPT-4 and GTP-3.5-Turbo modelsall text completion models (davinci, gpt-3.5-turbo-instruct, etc)Microsoft AzureAll OpenAI modelsdeepinfra.comdeepinfra/airoboros-70bjondurbin/airoboros-l2-70b-gpt4-1.4.1meta-llama/Llama-2-70b-chat-hfand other models having OpenAI APIAnyscalemeta-llama/Llama-2-70b-chat-hfmeta-llama/Llama-2-13b-chat-hfmeta-llama/Llama-7b-chat-hf🖼️ Examplescode-review-tool examplePerforms code review by LLM for changes in git .patch files in any programming languages.Other examplesPython functions as AI tools@TODO🤖 AI ModulesThis is experimental feature.Tweaks the Python import system to provide automatic setup of MicroCore environment
based on metadata in module docstrings.Usage:importmicrocore.ai_modulesFeatures:Automatically registers template folders of AI modules in Jinja2 environment🛠️ ContributingPlease seeCONTRIBUTINGfor details.📝 LicenseLicensed under theMIT License© 2023Vitalii Stepanenko