LLMs
This document outlines the LLMs API wrappers included in the pandasai.
Base
This is a base class to implement any LLM to be used with pandasai framework.
pandasai.llm.base
Base class to implement a new LLM
This module is the base class to integrate the various LLMs API. This module also includes the Base LLM classes for OpenAI, HuggingFace and Google PaLM.
Example
from .base import BaseOpenAI
class CustomLLM(BaseOpenAI):
Custom Class Starts here!!
BaseGoogle
Bases: LLM
Base class to implement a new Google LLM
LLM base class is extended to be used with Google Palm API.
Source code in pandasai/llm/base.py
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | |
call(instruction, value, suffix='')
Call the Google LLM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instruction |
str
|
Instruction to pass |
required |
value |
str
|
Value to pass |
required |
suffix |
str
|
Suffix to pass |
''
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Response |
Source code in pandasai/llm/base.py
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | |
BaseOpenAI
Bases: LLM, ABC
Base class to implement a new OpenAI LLM LLM base class, this class is extended to be used with OpenAI API.
Source code in pandasai/llm/base.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
chat_completion(value)
Query the chat completion API
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value |
str
|
Prompt |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
LLM response |
Source code in pandasai/llm/base.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
completion(prompt)
Query the completion API
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt |
str
|
Prompt |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
LLM response |
Source code in pandasai/llm/base.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
HuggingFaceLLM
Bases: LLM
Base class to implement a new Hugging Face LLM.
LLM base class is extended to be used with HuggingFace LLM Modes APIs
Source code in pandasai/llm/base.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
call(instruction, value, suffix='')
A call method of HuggingFaceLLM class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instruction |
object
|
A prompt object |
required |
value |
str
|
required | |
suffix |
str
|
''
|
Returns (str): A string response
Source code in pandasai/llm/base.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
query(payload)
Query the HF API
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload |
A JSON form payload |
required |
Source code in pandasai/llm/base.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |
LLM
Base class to implement a new LLM.
Source code in pandasai/llm/base.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
call(instruction, value, suffix='')
abstractmethod
Execute the LLM with given prompt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instruction |
Prompt
|
Prompt |
required |
value |
str
|
Value |
required |
suffix |
str
|
Suffix. Defaults to "". |
''
|
Raises:
| Type | Description |
|---|---|
MethodNotImplementedError
|
Call method has not been implemented |
Source code in pandasai/llm/base.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
generate_code(instruction, prompt)
Generate the code based on the instruction and the given prompt.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Code |
Source code in pandasai/llm/base.py
130 131 132 133 134 135 136 137 | |
type()
property
Return type of LLM.
Raises:
| Type | Description |
|---|---|
APIKeyNotFoundError
|
Type has not been implemented |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Type of LLM a string |
Source code in pandasai/llm/base.py
39 40 41 42 43 44 45 46 47 48 49 50 | |
OpenAI
OpenAI API wrapper extended through BaseOpenAI class.
pandasai.llm.openai
OpenAI LLM API
This module is to run the OpenAI API using OpenAI API.
Example
Use below example to call OpenAI Model
from pandasai.llm.openai import OpenAI
OpenAI
Bases: BaseOpenAI
OpenAI LLM using BaseOpenAI Class.
An API call to OpenAi API is sent and response is recorded and returned. The default chat model is gpt-3.5-turbo while text-davinci-003 is only supported completion model. The list of supported Chat models includes ["gpt-4", "gpt-4-0314", "gpt-4-32k", "gpt-4-32k-0314","gpt-3.5-turbo", "gpt-3.5-turbo-0301"].
Source code in pandasai/llm/openai.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
__init__(api_token=None, **kwargs)
init method of OpenAI Class
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_token |
str
|
API Token fro OpenAI platform. |
None
|
**kwargs |
Extended Parameters inferred from BaseOpenAI class |
{}
|
Source code in pandasai/llm/openai.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
call(instruction, value, suffix='')
Call the OpenAI LLM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instruction |
Prompt
|
Instruction to pass |
required |
value |
str
|
Value to pass |
required |
suffix |
str
|
Suffix to pass |
''
|
Raises:
| Type | Description |
|---|---|
UnsupportedOpenAIModelError
|
Unsupported model |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Response |
Source code in pandasai/llm/openai.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
OpenAssistant
OpenAssistant wrapper extended through Base HuggingFace Class
pandasai.llm.open_assistant
Open Assistant LLM
This module is to run the HuggingFace OpenAssistant API hosted and maintained by HuggingFace.co. To generate HF_TOKEN go to https://huggingface.co/settings/tokens after creating Account on the platform.
Example
Use below example to call Starcoder Model
from pandasai.llm.open_assistant import OpenAssistant
OpenAssistant
Bases: HuggingFaceLLM
Open Assistant LLM
A base HuggingFaceLLM class is extended to use OpenAssistant Model via its API.
Currently oasst-sft-1-pythia-12b is supported via this module.
Source code in pandasai/llm/open_assistant.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
__init__(api_token=None)
init method of OpenAssistant Calss
Raises:
| Type | Description |
|---|---|
APIKeyNotFoundError
|
HuggingFace Hub API key is required |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_token |
str
|
API token from Huggingface platform |
None
|
Source code in pandasai/llm/open_assistant.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
Starcoder
Starcoder wrapper extended through Base HuggingFace Class
pandasai.llm.starcoder
Starcoder LLM This module is to run the StartCoder API hosted and maintained by HuggingFace.co. To generate HF_TOKEN go to https://huggingface.co/settings/tokens after creating Account on the platform.
Example
Use below example to call Starcoder Model
from pandasai.llm.starcoder import Starcoder
Starcoder
Bases: HuggingFaceLLM
Starcoder LLM API
A base HuggingFaceLLM class is extended to use Starcoder model.
Source code in pandasai/llm/starcoder.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
__init__(api_token=None)
init method of Starcoder Class
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_token |
str
|
API token from Huggingface platform |
None
|
Source code in pandasai/llm/starcoder.py
36 37 38 39 40 41 42 43 44 45 | |
Azure OpenAI
OpenAI API through Azure Platform wrapper
pandasai.llm.azure_openai
OpenAI LLM via Microsoft Azure Cloud
This module is to run the OpenAI API when using Microsoft Cloud infrastructure. Azure has implemented the openai API access to its platform. For details https://learn.microsoft.com/en-us/azure/cognitive-services/openai/reference.
Example
Use below example to call AzureOpenAI class
from pandasai.llm.azure_openai import AzureOpenAI
AzureOpenAI
Bases: BaseOpenAI
OpenAI LLM via Microsoft Azure This class in using BaseOpenAI class to include Azure OpenAI Features.
Source code in pandasai/llm/azure_openai.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
__init__(api_token=None, api_base=None, api_version=None, deployment_name=None, **kwargs)
init method of AzureOpenAI Class
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_token |
str
|
Azure OpenAI API token. |
None
|
api_base |
str
|
Base url of the Azure endpoint. It should look like the following: https://YOUR_RESOURCE_NAME.openai.azure.com/ |
None
|
api_version |
str
|
Version of the Azure OpenAI API. Be aware the API version may change. |
None
|
deployment_name |
str
|
Custom name of the deployed model |
None
|
**kwargs |
Inference Parameters |
{}
|
Source code in pandasai/llm/azure_openai.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
call(instruction, value, suffix='')
Call the Azure OpenAI LLM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instruction |
str
|
Instruction to pass |
required |
value |
str
|
Value to pass |
required |
suffix(str) |
Suffix to pass |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Response |
Source code in pandasai/llm/azure_openai.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
GooglePalm
GooglePalm class extended through BaseGoogle Class
pandasai.llm.google_palm
Google Palm LLM
This module is to run the Google PaLM API hosted and maintained by Google. To read more on Google PaLM follow https://developers.generativeai.google/products/palm.
Example
Use below example to call GooglePalm Model
from pandasai.llm.google_palm import GooglePalm
GooglePalm
Bases: BaseGoogle
Google Palm LLM BaseGoogle class is extended for Google Palm model. The default and only model support at the moment is models/text-bison-001.
Source code in pandasai/llm/google_palm.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
__init__(api_key, **kwargs)
init method of GooglePalm Class
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key |
str
|
API Key |
required |
**kwargs |
Extended Parameters inferred from BaseGoogle Class |
{}
|
Source code in pandasai/llm/google_palm.py
25 26 27 28 29 30 31 32 33 | |
Fake
A test fake class
pandasai.llm.fake
Fake LLM
FakeLLM
Bases: LLM
Fake LLM
Source code in pandasai/llm/fake.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | |