A Python library providing a unified interface to interact with various Large Language Models (LLMs), including Google's Vertex AI and OpenAI's GPT models.
- Abstracted LLM client interface for easy integration of multiple providers
- Built-in support for Google Vertex AI LLMs (Gemini and Bison)
- Prompt optimization using few-shot learning
- Text encoding using Vertex AI's TextEmbeddingModel
- Extensible design to add more LLM providers
- Clone the repository:
git clone https://github.com/MBassi91/multi-llm-client.git cd multi-llm-client - Install the required dependencies:
pip install -r requirements.txt
from vertexai_client import VertexAILLM
# Initialize the Vertex AI LLM client
client = VertexAILLM(model_name="gemini")
# Generate text using the client
text_input = "Once upon a time, in a faraway land, there was a"
response = client.generate_text(text_input)
print("Generated text:")
print(response)# Optimize a system prompt using few-shot examples
system_prompt = "Write a short story about a magical adventure."
few_shots = [
"Example 1: In a enchanted forest, a brave young girl named Lily discovered a hidden portal that led her to a world filled with talking animals and magical creatures. With the help of her new friends, she embarked on a quest to find a legendary treasure and save the magical realm from an evil sorcerer.",
"Example 2: Max, a curious boy, stumbled upon an old book in his grandfather's attic. As he opened the book, he was transported to a mystical land where dragons roamed the skies and wizards cast powerful spells. Max soon realized that he was the chosen one, destined to bring peace to the land by uniting the feuding dragons and wizards."
]
optimized_prompt = client.prompt_optimizer(
system_prompt,
few_shots=few_shots,
few_shots_limit=2
)
print("\nOptimized prompt:")
print(optimized_prompt)
# Generate text using the optimized prompt
optimized_response = client.generate_text(optimized_prompt)
print("\nGenerated text with optimized prompt:")
print(optimized_response)# Generate text embeddings for a list of texts
texts = ["Dinner in New York City", "Lunch in Paris"]
embeddings = client.get_text_embeddings(texts)
print("\nText embeddings:")
for embedding in embeddings:
print(embedding)- Create a new client file in the
llm_clients/directory, e.g.,openai_client.py. - Implement the
BaseLLMClientinterface fromllm_clients/base_client.py. - Add usage examples in the
llm_clients/directory.
Contributions are welcome! Please submit a pull request or open an issue to discuss your ideas.
This project is licensed under the MIT License.