Spaces:
Paused
Paused
Alessandro commited on
Commit ·
602cfdc
1
Parent(s): b745266
other things + Embedding Model selection
Browse filesFiles changed (4)
- initialize.py+1-1
- models.py+15
- python/helpers/settings.py+46-9
- webui/settings.css+25-4
32 unmodified lines333435363637383932 unmodified lines chat_model = chat_llm, utility_model = utility_llm, embeddings_model = embedding_llm, prompts_subdir = "dianoia-xl", prompts_subdir = "", # memory_subdir = "", knowledge_subdirs = ["default","custom"], auto_memory_count = 0,43 unmodified lines444546474849505152535455563 unmodified lines60616263646566676869707172737475767743 unmodified lines OPENROUTER = "OpenRouter" SAMBANOVA = "Sambanova"
class EmbeddingProvider(Enum): OPENAI = "OpenAI" # default HUGGINGFACE = "HuggingFace" OLLAMA = "Ollama" LMSTUDIO = "LM Studio" OPENROUTER = "OpenRouter" AZURE = "OpenAI Azure"
# Utility function to get API keys from environment variablesdef get_api_key(service):3 unmodified lines
def get_model(type: ModelType, provider: ModelProvider, name: str, **kwargs): if type == ModelType.EMBEDDING: # call function for embedding models return get_embedding_model(provider, name, **kwargs) # for other model types fnc_name = f"get_{provider.name.lower()}_{type.name.lower()}" # function name of model getter model = globals()[fnc_name](name, **kwargs) # call function by name return model
def get_embedding_model(provider: EmbeddingProvider, name: str, **kwargs): fnc_name = f"get_{provider.name.lower()}_embedding" # function name for embedding models model = globals()[fnc_name](name, **kwargs) # call function by name return model
# Ollama modelsdef get_ollama_chat(2 unmodified lines3456678922 unmodified lines3233343535363739 unmodified lines77787981808182838485878687888938 unmodified lines12812913013213313113213313413513613813713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717858 unmodified lines23723823920324024124224321 unmodified lines2652662672312682692702712 unmodified linesimport refrom typing import Any, Optional, TypedDictfrom . import filesfrom models import get_model, ModelProvider, ModelTypefrom models import get_model, get_embedding_model, ModelProvider, EmbeddingProvider, ModelTypefrom langchain_core.language_models.chat_models import BaseChatModelfrom langchain_core.embeddings import Embeddings
22 unmodified lines
def convert_out(settings: Settings) -> dict[str, Any]:
# main model section chat_model_fields = [] chat_model_fields.append(39 unmodified lines } )
chat_model_seciton = { chat_model_section = { "title": "Chat Model", "description": "Selection and settings for main chat model used by Agent Zero", "fields": chat_model_fields, }
# main model section # utility model section util_model_fields = [] util_model_fields.append( {38 unmodified lines } )
util_model_seciton = { "title": "Utility model", util_model_section = { "title": "Utility Model", "description": "Smaller, cheaper, faster model for handling utility tasks like organizing memory, preparing prompts, summarizing.", "fields": util_model_fields, }
result = {"sections": [chat_model_seciton, util_model_seciton]} # embedding model section embed_model_fields = [] embed_model_fields.append( { "id": "embed_model_provider", "title": "Embedding model provider", "description": "Select provider for embedding model used by the framework", "type": "select", "value": settings["embed_model_provider"], "options": [{"value": p.name, "label": p.value} for p in EmbeddingProvider], } ) embed_model_fields.append( { "id": "embed_model_name", "title": "Embedding model name", "description": "Exact name of model from selected provider", "type": "input", "value": settings["embed_model_name"], } )
embed_model_fields.append( { "id": "embed_model_kwargs", "title": "Embedding model additional parameters", "description": "Any other parameters supported by the model. Format is KEY=VALUE on individual lines, just like .env file.", "type": "textarea", "value": _dict_to_env(settings["embed_model_kwargs"]), } )
embed_model_section = { "title": "Embedding Model", "description": "Settings for the embedding model used by Agent Zero.", "fields": embed_model_fields, }
result = {"sections": [chat_model_section, util_model_section, embed_model_section]} return result
def convert_in(settings: dict[str, Any]) -> Settings:58 unmodified lines settings = get_settings() return get_model( type=ModelType.EMBEDDING, provider=ModelProvider[settings["embed_model_provider"]], provider=EmbeddingProvider[settings["embed_model_provider"]], name=settings["embed_model_name"], **settings["embed_model_kwargs"], )21 unmodified lines util_model_name="gpt-4o-mini", util_model_temperature=0, util_model_kwargs={}, embed_model_provider=ModelProvider.OPENAI.name, embed_model_provider=EmbeddingProvider.OPENAI.name, embed_model_name="text-embedding-3-small", embed_model_kwargs={}, )123456789101119 unmodified lines313233262734353637383 unmodified lines4243444546474849172 unmodified lines22222322422522622722821822923023123223323423523623723823924024124222724324424524624724824925016 unmodified lines267268269270271272273* { transition: all var(--transition-speed) ease-in-out;}
select { transition: none;}
.modal-overlay { position: fixed; top: 0;19 unmodified lines}
.modal-header { padding: 1.5rem 2rem; border-bottom: 1px solid #eee; padding: 0.875rem 2rem; border-bottom: 1px solid var(--color-border);}
.modal-content {3 unmodified lines background-clip: border-box; border: 6px solid transparent; transition: all 0.3s ease; margin-bottom: 0; padding-bottom: 0;}
.modal-content::-webkit-scrollbar {172 unmodified lines.btn-ok { background: #3270e2; color: white; transition: background 0.3s ease-in-out;}
.btn-ok:hover{ background: #274170; background: #3265c0;}
.btn-ok:active{ background: #345693;}
.btn-cancel { background: #ddd; color: #333; transition: background 0.3s ease-in-out;}
.btn-cancel:hover { background: #222 background: #a6a6a6}
.btn-cancel:active { background: #808080}
.btn-field {16 unmodified lines font-size: inherit; cursor: pointer; font-family: Rubik; outline: none;}
select:disabled {initialize.py+1-1
models.py+15
python/helpers/settings.py+46-9
webui/settings.css+25-4