You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/api/language_model_clients/PremAI.md
+51-25Lines changed: 51 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ sidebar_position: 5
4
4
5
5
# dspy.PremAI
6
6
7
-
[PremAI](https://app.premai.io)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.
7
+
[PremAI](https://app.premai.io) 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.
8
8
9
9
### Prerequisites
10
10
@@ -66,11 +66,53 @@ Internally, the method handles the specifics of preparing the request prompt and
66
66
-`prompt` (_str_): Prompt to send to PremAI.
67
67
-`**kwargs`: Additional keyword arguments for completion request. Example: parameters like `temperature`, `max_tokens` etc. You can find all the additional kwargs [here](https://docs.premai.io/get-started/sdk#optional-parameters).
68
68
69
+
### Prem Templates
70
+
71
+
Writing Prompt Templates can be super messy. Prompt templates are long, hard to manage, and must be continuously tweaked to improve and keep the same throughout the application.
72
+
73
+
With **Prem**, writing and managing prompts can be super easy. The **_Templates_** tab inside the [launchpad](https://docs.premai.io/get-started/launchpad) helps you write as many prompts as you need and use it inside the SDK to make your application run using those prompts. You can read more about Prompt Templates [here](https://docs.premai.io/get-started/prem-templates).
74
+
75
+
Using templates in DSPy is quite easy. First, here is an example of a prompt template that you store / re-iterate inside Prem.
76
+
77
+
```python
78
+
template ="""
79
+
Summarize the following content by creating a bullet point list and return it in json
80
+
${content}
81
+
"""
82
+
```
83
+
84
+
**Please note:** Prompt templates are not defined in Python code. Here is an example of a Template, which has an associated template id.
85
+
86
+
Assuming this prompt template is stored under a template with id: `78069ce8-xxxxx-xxxxx-xxxx-xxx`:
87
+
88
+
```python
89
+
from dspy import PremAI
90
+
91
+
client = PremAI(project_id=1234)
92
+
template_id ="78069ce8-xxxxx-xxxxx-xxxx-xxx"
93
+
94
+
msg ="""
95
+
I am playing in a garden on a fine sunday
96
+
evening. I then went to my friend Tara's place
97
+
and then went for movies in the city center mall.
98
+
"""
99
+
100
+
response = client(
101
+
prompt="some-random-dummy-text",
102
+
template_id=template_id,
103
+
params={"content": msg}
104
+
)
105
+
106
+
print(response)
107
+
```
108
+
109
+
When you use templates, there is no need to place `msg` / prompt inside the `prompt` argument. DSPy only accepts string prompts to conduct LLM requests, but we might require multiple string inputs when using templates. Templates allow you to provide additional inputs (key:value pairs) within the `params` argument, which should be mapped with the template variable. Our example template had one variable `content`, so our params become: `{"content": msg}`.
110
+
69
111
### Native RAG Support
70
112
71
113
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](https://docs.premai.io/get-started/repositories).
72
114
73
-
Repositories are also supported through the dspy-premai integration. Here is how you can use this workflow:
115
+
Repositories are also supported through the dspy-premai integration. Here is how you can use this workflow:
74
116
75
117
```python
76
118
query ="what is the diameter of individual Galaxy"
@@ -82,21 +124,21 @@ repositories = dict(
82
124
)
83
125
```
84
126
85
-
First, we start by defining our repository with some valid repository ids. You can learn more about how to get the repository id [here](https://docs.premai.io/get-started/repositories).
127
+
First, we start by defining our repository with some valid repository ids. You can learn more about how to get the repository id [here](https://docs.premai.io/get-started/repositories).
86
128
87
-
> Note: This is similar to LM integrations where now you are overriding the repositories connected in the launchpad when you invoke the argument' repositories'.
129
+
> Note: This is similar to LM integrations where now you are overriding the repositories connected in the launchpad when you invoke the argument' repositories'.
88
130
89
-
Now, we connect the repository with our chat object to invoke RAG-based generations.
131
+
Now, we connect the repository with our chat object to invoke RAG-based generations.
Here is what an example generation would look like with PremAI Repositories.
141
+
Here is what an example generation would look like with PremAI Repositories.
100
142
101
143
```bash
102
144
'The diameters of individual galaxies range from 80,000-150,000 light-years.'
@@ -113,23 +155,7 @@ Here is what an example generation would look like with PremAI Repositories.
113
155
"document_name": "Kegy 202 Chapter 2",
114
156
"similarity_score": 0.586126983165741,
115
157
"content": "n thousands\n of light-years. The diameters of individual\n galaxies range from 80,000-150,000 light\n "
116
-
},
117
-
{
118
-
"repository_id": 1991,
119
-
"document_id": 1307,
120
-
"chunk_id": 173925,
121
-
"document_name": "Kegy 202 Chapter 2",
122
-
"similarity_score": 0.4815782308578491,
123
-
"content": " for development of galaxies. A galaxy contains\n a large number of stars. Galaxies spread over\n vast distances that are measured in thousands\n "
124
-
},
125
-
{
126
-
"repository_id": 1991,
127
-
"document_id": 1307,
128
-
"chunk_id": 173916,
129
-
"document_name": "Kegy 202 Chapter 2",
130
-
"similarity_score": 0.38112708926200867,
131
-
"content": " was separated from the from each other as the balloon expands.\n solar surface. As the passing star moved away, Similarly, the distance between the galaxies is\n the material separated from the solar surface\n continued to revolve around the sun and it\n slowly condensed into planets. Sir James Jeans\n and later Sir Harold Jeffrey supported thisnot to be republishedalso found to be increasing and thereby, the\n universe is"
132
-
}
158
+
},`
133
159
],
134
160
"kwargs": {
135
161
"max_tokens": 100,
@@ -157,4 +183,4 @@ Here is what an example generation would look like with PremAI Repositories.
157
183
158
184
So this also means that you do not need to create your own RAG pipeline when using the PremAI Platform and can instead take advantage of its local RAG technology to deliver best-in-class performance for Retrieval Augmented Generations.
159
185
160
-
> Ideally, you do not need to connect Repository IDs here to get Retrieval Augmented Generations. You can still get the same result if you have connected the repositories in PremAI platform.
186
+
> Ideally, you do not need to connect Repository IDs here to get Retrieval Augmented Generations. You can still get the same result if you have connected the repositories in PremAI platform.
0 commit comments