pip install mosaic-mindFor sentence transformer embeddings:
pip install mosaic-mind[sentence-transformers]For all optional dependencies:
pip install mosaic-mind[all]You'll need API keys for the services you want to use:
import os
# OpenAI
os.environ["OPENAI_API_KEY"] = "your-openai-api-key"
# Google (for Gemini)
os.environ["GOOGLE_API_KEY"] = "your-google-api-key"from mosaic.core.ai.llm import OpenAILLM
# Initialize the LLM
llm = OpenAILLM(api_key="your-openai-api-key")
# Generate a response
response = llm.generate("What is the capital of France?")
print(response.content)
# Output: The capital of France is Paris.from mosaic.core.ai.embedding import OpenAIEmbedding
# Initialize the embedding model
embedding = OpenAIEmbedding(api_key="your-openai-api-key")
# Generate embeddings
texts = ["Hello world", "Goodbye world"]
embeddings = embedding.embed(texts)
print(f"Embedding shape: {embeddings[0].shape}")
# Output: Embedding shape: (1536,)from mosaic.core.ai.llm import OpenAILLM
llm = OpenAILLM(api_key="your-openai-api-key")
response = llm.generate("Count the tokens in this text")
print(f"Input tokens: {response.usage.prompt_tokens}")
print(f"Output tokens: {response.usage.completion_tokens}")
print(f"Total tokens: {response.usage.total_tokens}")You can set API keys via environment variables:
export OPENAI_API_KEY="your-openai-api-key"
export GOOGLE_API_KEY="your-google-api-key"Create a .env file in your project root:
OPENAI_API_KEY=your-openai-api-key
GOOGLE_API_KEY=your-google-api-keyThen load it in your code:
from dotenv import load_dotenv
load_dotenv()
from mosaic.core.ai.llm import OpenAILLM
llm = OpenAILLM() # Will use environment variable- Check out the API Reference for detailed class documentation
- Explore Examples for more complex use cases
- Read the Guides for best practices and advanced topics