Skip to content

Commit d831ad1

Browse files
committed
Added prem sdk documentation under deep dive
1 parent 62eaf88 commit d831ad1

File tree

1 file changed

+70
-0
lines changed
  • docs/docs/deep-dive/language_model_clients/remote_models

1 file changed

+70
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
## PremAI
2+
3+
[PremAI](https://app.premai.io) is a unified platform that lets you build powerful production-ready GenAI-powered applications with the least effort so that you can focus more on user experience and overall growth. With dspy, you can connect with several [best-in-class LLMs](https://models.premai.io/) of your choice with a single interface.
4+
5+
### Prerequisites
6+
7+
Refer to the [quick start](https://docs.premai.io/introduction) guide to getting started with the PremAI platform, create your first project and grab your API key.
8+
9+
### Setting up the PremAI Client
10+
11+
The constructor initializes the base class `LM` to support prompting requests to supported PremAI hosted models. This requires the following parameters:
12+
13+
- `model` (_str_): Models supported by PremAI. Example: `mistral-tiny`. We recommend using the model selected in [project launchpad](https://docs.premai.io/get-started/launchpad).
14+
- `project_id` (_int_): The [project id](https://docs.premai.io/get-started/projects) which contains the model of choice.
15+
- `api_key` (_Optional[str]_, _optional_): API provider from PremAI. Defaults to None.
16+
- `session_id` (_Optional[int]_, _optional_): The ID of the session to use. It helps to track the chat history.
17+
- `**kwargs`: Additional language model arguments will be passed to the API provider.
18+
19+
Example of PremAI constructor:
20+
21+
```python
22+
class PremAI(LM):
23+
def __init__(
24+
self,
25+
model: str,
26+
project_id: int,
27+
api_key: str,
28+
base_url: Optional[str] = None,
29+
session_id: Optional[int] = None,
30+
**kwargs,
31+
) -> None:
32+
```
33+
34+
### Under the Hood
35+
36+
#### `__call__(self, prompt: str, **kwargs) -> str`
37+
38+
**Parameters:**
39+
- `prompt` (_str_): Prompt to send to PremAI.
40+
- `**kwargs`: Additional keyword arguments for completion request.
41+
42+
**Returns:**
43+
- `str`: Completions string from the chosen LLM provider
44+
45+
Internally, the method handles the specifics of preparing the request prompt and corresponding payload to obtain the response.
46+
47+
### Using the PremAI client
48+
49+
```python
50+
premai_client = dspy.PremAI(project_id=1111)
51+
```
52+
53+
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.
54+
55+
```python
56+
dspy.configure(lm=premai_client)
57+
58+
#Example DSPy CoT QA program
59+
qa = dspy.ChainOfThought('question -> answer')
60+
61+
response = qa(question="What is the capital of Paris?")
62+
print(response.answer)
63+
```
64+
65+
2) Generate responses using the client directly.
66+
67+
```python
68+
response = premai_client(prompt='What is the capital of Paris?')
69+
print(response)
70+
```

0 commit comments

Comments
 (0)