Skip to content

Commit

Permalink
added gpt4free package
Browse files Browse the repository at this point in the history
  • Loading branch information
sudouser777 committed Apr 29, 2023
1 parent 94b3030 commit 54b4c78
Show file tree
Hide file tree
Showing 66 changed files with 492 additions and 422 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ Please note the following:
| **Star History** | Star History | [![Link to Section](https://img.shields.io/badge/Link-Go%20to%20Section-blue)](#star-history) | - |
| **Usage Examples** | | | |
| `theb` | Example usage for theb (gpt-3.5) | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](openai_rev/theb/README.md) | ![Active](https://img.shields.io/badge/Active-brightgreen) |
| `forefront` | Example usage for forefront (gpt-4) | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](./forefront/README.md) | ![Active](https://img.shields.io/badge/Active-brightgreen) | ||
| `quora (poe)` | Example usage for quora | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](./quora/README.md) | ![Active](https://img.shields.io/badge/Active-brightgreen) |
| `you` | Example usage for you | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](./you/README.md) | ![Active](https://img.shields.io/badge/Active-brightgreen) |
| `forefront` | Example usage for forefront (gpt-4) | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](gpt4free/forefront/README.md) | ![Active](https://img.shields.io/badge/Active-brightgreen) | ||
| `quora (poe)` | Example usage for quora | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](gpt4free/quora/README.md) | ![Active](https://img.shields.io/badge/Active-brightgreen) |
| `you` | Example usage for you | [![Link to File](https://img.shields.io/badge/Link-Go%20to%20File-blue)](gpt4free/you/README.md) | ![Active](https://img.shields.io/badge/Active-brightgreen) |
| **Try it Out** | | | |
| Google Colab Jupyter Notebook | Example usage for gpt4free | [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/DanielShemesh/gpt4free-colab/blob/main/gpt4free.ipynb) | - |
| replit Example (feel free to fork this repl) | Example usage for gpt4free | [![](https://img.shields.io/badge/Open%20in-Replit-1A1E27?logo=replit)](https://replit.com/@gpt4free/gpt4free-webui) | - |
Expand Down Expand Up @@ -126,10 +126,10 @@ Please note the following:
## Best sites <a name="best-sites"></a>

#### gpt-4
- [`/forefront`](./forefront/README.md)
- [`/forefront`](gpt4free/forefront/README.md)

#### gpt-3.5
- [`/you`](./you/README.md)
- [`/you`](gpt4free/you/README.md)

## Install <a name="install"></a>
Download or clone this GitHub repo
Expand Down
57 changes: 0 additions & 57 deletions cocalc/__init__.py

This file was deleted.

16 changes: 0 additions & 16 deletions forefront/README.md

This file was deleted.

154 changes: 0 additions & 154 deletions forefront/__init__.py

This file was deleted.

36 changes: 0 additions & 36 deletions forefront/typing.py

This file was deleted.

64 changes: 64 additions & 0 deletions gpt4free/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from enum import Enum

from gpt4free import cocalc
from gpt4free import forefront
from gpt4free import quora
from gpt4free import theb
from gpt4free import you


class Provider(Enum):
"""An enum representing different providers."""

You = 'you'
Poe = 'poe'
ForeFront = 'fore_front'
Theb = 'theb'
CoCalc = 'cocalc'


class Completion:
"""This class will be used for invoking the given provider"""

@staticmethod
def create(provider: Provider, prompt: str, **kwargs) -> str:
"""
Invokes the given provider with given prompt and addition arguments and returns the string response
:param provider: an enum representing the provider to use while invoking
:param prompt: input provided by the user
:param kwargs: Additional keyword arguments to pass to the provider while invoking
:return: A string representing the response from the provider
"""
if provider == Provider.Poe:
return Completion.__poe_service(prompt, **kwargs)
elif provider == Provider.You:
return Completion.__you_service(prompt, **kwargs)
elif provider == Provider.ForeFront:
return Completion.__fore_front_service(prompt, **kwargs)
elif provider == Provider.Theb:
return Completion.__theb_service(prompt, **kwargs)
elif provider == Provider.CoCalc:
return Completion.__cocalc_service(prompt, **kwargs)
else:
raise Exception('Provider not exist, Please try again')

@staticmethod
def __you_service(prompt: str, **kwargs) -> str:
return you.Completion.create(prompt, **kwargs).text

@staticmethod
def __poe_service(prompt: str, **kwargs) -> str:
return quora.Completion.create(prompt=prompt, **kwargs).text

@staticmethod
def __fore_front_service(prompt: str, **kwargs) -> str:
return forefront.Completion.create(prompt=prompt, **kwargs).text

@staticmethod
def __theb_service(prompt: str, **kwargs):
return ''.join(theb.Completion.create(prompt=prompt))

@staticmethod
def __cocalc_service(prompt: str, **kwargs):
return cocalc.Completion.create(prompt, cookie_input=kwargs.get('cookie_input', '')).text
Loading

0 comments on commit 54b4c78

Please sign in to comment.