Skip to main content

PremAI

PremAI

PremAI is an all-in-one platform that simplifies the process of creating robust, production-ready applications powered by Generative AI. By streamlining the development process, PremAI allows you to concentrate on enhancing user experience and driving overall growth for your application.

Prerequisites

Refer to the quick start guide to getting started with the PremAI platform, create your first project and grab your API key.

Setting up the PremAI Client

The constructor initializes the base class LM to support prompting requests to supported PremAI hosted models. This requires the following parameters:

  • model (str): Models supported by PremAI. Example: mistral-tiny. We recommend using the model selected in project launchpad.
  • project_id (int): The project id which contains the model of choice.
  • api_key (Optional[str], optional): API provider from PremAI. Defaults to None.
  • **kwargs: Additional language model arguments will be passed to the API provider.

Example of PremAI constructor:

class PremAI(LM):
def __init__(
self,
model: str,
project_id: int,
api_key: str,
base_url: Optional[str] = None,
session_id: Optional[int] = None,
**kwargs,
) -> None:

Under the Hood

__call__(self, prompt: str, **kwargs) -> str

Parameters:

  • prompt (str): Prompt to send to PremAI.
  • **kwargs: Additional keyword arguments for completion request. You can find all the additional kwargs here.

Returns:

  • str: Completions string from the chosen LLM provider

Internally, the method handles the specifics of preparing the request prompt and corresponding payload to obtain the response.

Using the PremAI client

premai_client = dspy.PremAI(project_id=1111)

Please note that, this is a dummy project_id. You need to change this to the project_id you are interested to use with dspy.

dspy.configure(lm=premai_client)

#Example DSPy CoT QA program
qa = dspy.ChainOfThought('question -> answer')

response = qa(question="What is the capital of Paris?")
print(response.answer)
  1. Generate responses using the client directly.
response = premai_client(prompt='What is the capital of Paris?')
print(response)

Native RAG Support

PremAI Repositories allow users to upload documents (.txt, .pdf, etc.) and connect those repositories to the LLMs to serve as vector databases and support native RAG. You can learn more about PremAI repositories here.

Repositories are also supported through the dspy-premai integration. Here is how you can use this workflow:

query = "what is the diameter of individual Galaxy"
repository_ids = [1991, ]
repositories = dict(
ids=repository_ids,
similarity_threshold=0.3,
limit=3
)

First, we start by defining our repository with some valid repository ids. You can learn more about how to get the repository id here.

Note: This is similar to LM integrations where now you are overriding the repositories connected in the launchpad when you invoke the argument' repositories'.

Now, we connect the repository with our chat object to invoke RAG-based generations.

response = premai_client(prompt=query, max_tokens=100, repositories=repositories)

print(response)
print("---")
print(json.dumps(premai_client.history, indent=4))