forked from Sinaptik-AI/pandas-ai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
At the moment, however, the Falcon LLM seems to hallucinate quite often, we should support custom prompts for each LLM
- Loading branch information
Showing
8 changed files
with
138 additions
and
30 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,47 @@ | ||
# Command-Line Tool | ||
|
||
[Pai] is the command line tool designed to provide a convenient way to interact with `pandasai` through a command line interface (CLI). In order to access the CLI tool, make sure to create a virtualenv for testing purpose and to install project dependencies in your local virtual environment using `pip` by running the following command: | ||
|
||
``` | ||
pip install -e . | ||
``` | ||
|
||
Alternatively, you can use `poetry` to create and activate the virtual environment by running the following command: | ||
|
||
``` | ||
poetry shell | ||
``` | ||
|
||
Inside the activated virtual environment, install the project dependencies by running the following command: | ||
|
||
``` | ||
poetry install | ||
``` | ||
|
||
By following these steps, you will now have the necessary environment to access the CLI tool. | ||
By following these steps, you will now have the necessary environment to access the CLI tool. | ||
|
||
``` | ||
pai [OPTIONS] | ||
``` | ||
|
||
Options: | ||
|
||
- **-d, --dataset**: The file path to the dataset. | ||
- **-t, --token**: Your HuggingFace or OpenAI API token, if no token provided pai will pull from the `.env` file. | ||
- **-m, --model**: Choice of LLM, either `openai`, `open-assistant`, or `starcoder`. | ||
- **-m, --model**: Choice of LLM, either `openai`, `open-assistant`, `starcoder`, `falcon`, `azure-openai` or `google-palm`. | ||
- **-p, --prompt**: Prompt that PandasAI will run. | ||
|
||
To view a full list of available options and their descriptions, run the following command: | ||
|
||
``` | ||
pai --help | ||
``` | ||
>For example, | ||
>``` | ||
>pai -d "~/pandasai/example/data/Loan payments data.csv" -m "openai" -p "How many loans are from men and have been paid off?" | ||
>``` | ||
>Should result in the same output as the `from_csv.py` example. | ||
|
||
> For example, | ||
> | ||
> ``` | ||
> pai -d "~/pandasai/example/data/Loan payments data.csv" -m "openai" -p "How many loans are from men and have been paid off?" | ||
> ``` | ||
> | ||
> Should result in the same output as the `from_csv.py` example. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
""" Falcon LLM | ||
This module is to run the Falcon 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 Falcon Model | ||
>>> from pandasai.llm.falcon import Falcon | ||
""" | ||
|
||
|
||
import os | ||
from typing import Optional | ||
|
||
from dotenv import load_dotenv | ||
|
||
from ..exceptions import APIKeyNotFoundError | ||
from .base import HuggingFaceLLM | ||
|
||
load_dotenv() | ||
|
||
|
||
class Falcon(HuggingFaceLLM): | ||
|
||
"""Falcon LLM API | ||
A base HuggingFaceLLM class is extended to use Falcon model. | ||
""" | ||
|
||
api_token: str | ||
_api_url: str = ( | ||
"https://api-inference.huggingface.co/models/tiiuae/falcon-7b-instruct" | ||
) | ||
_max_retries: int = 5 | ||
|
||
def __init__(self, api_token: Optional[str] = None): | ||
""" | ||
__init__ method of Falcon Class | ||
Args: | ||
api_token (str): API token from Huggingface platform | ||
""" | ||
|
||
self.api_token = api_token or os.getenv("HUGGINGFACE_API_KEY") or None | ||
if self.api_token is None: | ||
raise APIKeyNotFoundError("HuggingFace Hub API key is required") | ||
|
||
@property | ||
def type(self) -> str: | ||
return "falcon" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"""Unit tests for the falcon LLM class""" | ||
|
||
import pytest | ||
|
||
from pandasai.exceptions import APIKeyNotFoundError | ||
from pandasai.llm.falcon import Falcon | ||
|
||
|
||
class TestFalconLLM: | ||
"""Unit tests for the Falcon LLM class""" | ||
|
||
def test_type(self): | ||
assert Falcon(api_token="test").type == "falcon" | ||
|
||
def test_init(self): | ||
with pytest.raises(APIKeyNotFoundError): | ||
Falcon() |