Documentation Index
Fetch the complete documentation index at: https://mintlify.com/dais-polymtl/sqlmorph/llms.txt
Use this file to discover all available pages before exploring further.
ModelManager is a factory class that returns a ready-to-use model object for whichever LLM provider you configure. Internally it maps a combination of ModelProvider and ModelType to the appropriate client class (OpenAIChatCompletion, OllamaChatCompletion, HuggingFaceChatCompletion, and their embedding counterparts), constructs it with the supplied credentials, and returns it. The returned object exposes a uniform get_chat_completion() or get_embedding() method so the rest of SQLMorph can switch providers without changing call sites.
ModelManager.create_model()
The single entry point for obtaining a model instance.
Selects the LLM backend. Must be a member of the
ModelProvider enum. Raises ValueError for unsupported values.Selects whether to create a chat-completion or embedding client. Must be a member of the
ModelType enum.The specific model to use. Pass an enum member appropriate for the chosen provider (e.g.,
OpenAIModel.GPT_4O for OpenAI, OllamaModel.LLAM3_1_8B for Ollama). The enum’s .value property is used as the model identifier string.Your OpenAI API key. Required when
model_provider=ModelProvider.OPENAI. Ignored for Ollama and HuggingFace.Optional Portkey gateway API key. When set, the OpenAI client routes requests through the Portkey gateway (
PORTKEY_GATEWAY_URL) using the provided credentials.Optional Portkey configuration ID. Used together with
portkey_api_key to select a specific Portkey config profile.model_provider and model_type combination:
| Provider | Type | Returned class |
|---|---|---|
OPENAI | COMPLETION | OpenAIChatCompletion |
OPENAI | EMBEDDING | OpenAIEmbeddings |
OLLAMA | COMPLETION | OllamaChatCompletion |
OLLAMA | EMBEDDING | OllamaEmbeddings |
HUGGINGFACE | COMPLETION | HuggingFaceChatCompletion |
HUGGINGFACE | EMBEDDING | HuggingFaceEmbeddings |
Enum reference
ModelProvider
ModelType
OpenAIModel
OllamaModel
OllamaModel member stores a (model_string, num_ctx) tuple. Call .get_num_ctx() to retrieve the context-window size; embedding models return None.
Using the returned model
get_chat_completion()
All completion model objects returned by ModelManager.create_model() expose a get_chat_completion() method. The OpenAI and Ollama signatures differ slightly.
- OpenAI
- Ollama
One string per completion choice (
response.choices[n].message.content). Typically a list of length 1.Wall-clock time in seconds for the API call.
Prompt token count from
response.usage.prompt_tokens.Completion token count from
response.usage.completion_tokens.compose_chat_messages() utility
Builds the messages list expected by the Chat Completions API from plain Python strings.
One string per user turn. The list length determines how many turns are added.
Optional list of assistant turn strings, one per user message. When provided, each assistant message is interleaved immediately after its corresponding user message to construct few-shot conversation history. Must be the same length as
user_messages if supplied.Optional system prompt prepended to the message list.
list[dict[str, str]] — a message list ready to pass directly to get_chat_completion().
Usage examples
Set
OPENAI_API_KEY in your environment or pass it explicitly to create_model(). The TQA and JQE NL generation modules read it via os.getenv("OPENAI_API_KEY") and forward it through create_model(). Ollama requires a locally running Ollama server; no API key is needed.