diff --git a/README.md b/README.md index 73576691e..ad0505664 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,42 @@ pandas_ai.generate_features(df) pandas_ai.plot_histogram(df, column="gdp") ``` +### POE-API As LLM Reference + +``` +To use Pandas-ai without using OPENAI API use Poe-api + +Get Your TOKEN from poe.com by just creating account don't need to add any billing + +To get Token click Inspect -> Application -> Cookies -> p-b value +BOTS REFERENCE : + +"chinchilla": "ChatGPT", + "a2": "Claude-instant", + "capybara": "Assistant", + "a2_100k": "Claude-instant-100k", + "llama_2_7b_chat": "Llama-2-7b", + "llama_2_13b_chat": "Llama-2-13b", + "a2_2": "Claude-2-100k", + "llama_2_70b_chat": "Llama-2-70b", + "agouti": "ChatGPT-16k", + "beaver": "GPT-4", + "vizcacha": "GPT-4-32k", + "acouchy": "Google-PaLM" + +If you want to use ChatGPT use bot name as chinchilla + +Example usage + +from pandasai import PandasAI +from pandasai.llm.poe_api import POEAPI + +llm = POEAPI(bot_name='chinchilla',token = '') +pandas_ai = PandasAI(llm) + +``` + + Learn more about the shortcuts [here](https://pandas-ai.readthedocs.io/en/latest/shortcuts/). ## 🔒 Privacy & Security diff --git a/docs/requirements.txt b/docs/requirements.txt index 17c7b43de..9b5f40d3e 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -64,3 +64,5 @@ watchdog==2.1.9 # via mkdocs zipp==3.8.0 # via importlib-metadata + +poe-api diff --git a/pandasai/llm/poe_api.py b/pandasai/llm/poe_api.py new file mode 100644 index 000000000..1c06212cb --- /dev/null +++ b/pandasai/llm/poe_api.py @@ -0,0 +1,75 @@ +"""Poe-Api LLMs + +This module provides a family of commercially / non-commercially available +LLMs maintained by Quora +Example: + Use below example to call POEAPI supporrted models + >>> from pandasai.llm.poe_api import POEAPI +""" +import os +import requests +from typing import Optional + +from pandasai.prompts.base import Prompt +from .base import LLM + + +class POEAPI(LLM): + """POEAPI LLMs API + Base LLM class is extended to support POEAPILLM.Below example shows how + we can use override certain configurations to change model's behaviour. + Example: + >>> import pandas as pd + >>> from pandasai import PandasAI + >>> from pandasai.llm.POEAPI import POEAPI + >>> model = POEAPI(bot_name='', token='') + >>> df_ai = PandasAI(model) + >>> response = df_ai(df, prompt='What is the sum of the GDP in this table?') + + + """ + + + + def __init__( + self, + bot_name: str, + token : str, + **kwargs, + ) -> None: + self.bot_name = bot_name + self.token = token + """ + POEAPI client for using Pandas AI + Args: + bot_name: The name of the model. + token: The token of the Poe API. + + """ + + try: + import poe + + self.poe_api_bot = poe.Client(token=self.token + + + ) + except ImportError: + raise ImportError( + "Unable to import poe-api python package " + "Please install it with `pip install -U poe-api`" + ) + + + + + @property + def type(self) -> str: + return "POEAPI" + + def call(self, instruction: Prompt, value: str, suffix: str = "") -> str: + prompt = str(instruction) + prompt = prompt + value + suffix + for chunk in self.poe_api_bot.send_message(self.bot_name ,prompt,): + pass + return chunk['text'] \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 3bbc15390..5bbce981c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,6 +19,7 @@ google-generativeai = { version = "^0.1.0rc2", optional = true } google-cloud-aiplatform = { version = "^1.26.1", optional = true } langchain = { version = "^0.0.199", optional = true} beautifulsoup4 = { version = "^4.12.2", optional = true } +poe-api = "0.5.2" [tool.poetry.group.dev.dependencies] black = "^23.3.0" diff --git a/tests/llms/test_poeapi.py b/tests/llms/test_poeapi.py new file mode 100644 index 000000000..26796f18e --- /dev/null +++ b/tests/llms/test_poeapi.py @@ -0,0 +1,18 @@ +from unittest.mock import patch +from pandasai.llm.poe_api import POEAPI + + +class TestPOEAPI(unittest.TestCase): + """Unit tests for the base POE LLM class""" + + def setUp(self): + self.bot_name = "chinchilla" + self.token = '' + + self.poe_api_bot = POEAPI( + model_name=self.model_name, + ) + + def test_type(self, ): + + assert self.poe_api_bot.type == "POEAPI" \ No newline at end of file