diff options
-rw-r--r-- | README.md | 65 | ||||
-rw-r--r-- | g4f/__init__.py | 4 | ||||
-rw-r--r-- | g4f/api/__init__.py | 19 | ||||
-rw-r--r-- | setup.py | 2 |
4 files changed, 63 insertions, 27 deletions
@@ -5,11 +5,11 @@ new discord server: [discord.gg/XfybzPXPH5](https://discord.gg/XfybzPXPH5) ![248433934-7886223b-c1d1-4260-82aa-da5741f303bb](https://github.com/xtekky/gpt4free/assets/98614666/ea012c87-76e0-496a-8ac4-e2de090cc6c9) -> **Note** -> By using this repository or any code related to it, you agree to the [legal notice](./LEGAL_NOTICE.md). The author is not responsible for any copies, forks, re-uploads made by other users, or anything else related to GPT4Free. This is the author's only account and repository. To prevent impersonation or irresponsible actions, please comply with the GNU GPL license this Repository uses. +> [!Note] +> By using this repository or any code related to it, you agree to the [legal notice](LEGAL_NOTICE.md). The author is not responsible for any copies, forks, re-uploads made by other users, or anything else related to GPT4Free. This is the author's only account and repository. To prevent impersonation or irresponsible actions, please comply with the GNU GPL license this Repository uses. -> **Note** -> Latest pypi version: [`0.1.8.1`](https://pypi.org/project/g4f/0.1.8.1) +> [!Note] +> Latest pypi version: [`0.1.8.2`](https://pypi.org/project/g4f/0.1.8.2) ```sh pip install -U g4f ``` @@ -21,24 +21,38 @@ pip install -U g4f ## đ Table of Contents -- [Getting Started](#getting-started) - - [Prerequisites](#prerequisites) - - [Setting up the project](#setting-up-the-project) - - [Install using PyPi](#install-using-pypi) - - [Install using docker](#setting-up-with-docker) -- [Usage](#usage) +- [đ What's New](#-whats-new) +- [đ Table of Contents](#-table-of-contents) +- [đ ī¸ Getting Started](#ī¸-getting-started) + - [Prerequisites:](#prerequisites) + - [Setting up the project:](#setting-up-the-project) + - [Install using pypi](#install-using-pypi) + - [or](#or) + - [Setting up with Docker:](#setting-up-with-docker) +- [đĄ Usage](#-usage) - [The `g4f` Package](#the-g4f-package) - - [interference openai-proxy api (use with openai python package)](#interference-openai-proxy-api-use-with-openai-python-package) -- [Providers](#models) - - [gpt-3.5](#gpt-35) - - [gpt-4](#gpt-4) - - [Other Models](#other-models) -- [Related gpt4free projects](#related-gpt4free-projects) -- [Contribute](#contribute) -- [Contributors](#contributors) -- [Copyright](#copyright) -- [Star History](#star-history) -- [License](#license) + - [ChatCompletion](#chatcompletion) + - [Completion](#completion) + - [Providers](#providers) + - [Cookies Required](#cookies-required) + - [Async Support](#async-support) + - [Proxy and Timeout Support](#proxy-and-timeout-support) + - [Interference openai-proxy API (Use with openai python package)](#interference-openai-proxy-api-use-with-openai-python-package) + - [Run interference API from PyPi package](#run-interference-api-from-pypi-package) + - [Run interference API from repo](#run-interference-api-from-repo) +- [đ Providers and Models](#-providers-and-models) + - [GPT-4](#gpt-4) + - [GPT-3.5](#gpt-35) + - [Other](#other) + - [Models](#models) +- [đ Related GPT4Free Projects](#-related-gpt4free-projects) +- [đ¤ Contribute](#-contribute) + - [Create Provider with AI Tool](#create-provider-with-ai-tool) + - [Create Provider](#create-provider) +- [đ Contributors](#-contributors) +- [Šī¸ Copyright](#ī¸-copyright) +- [â Star History](#-star-history) +- [đ License](#-license) ## đ ī¸ Getting Started @@ -140,7 +154,7 @@ To stop the Docker containers, simply run: docker compose down ``` -> **Note** +> [!Note] > When using Docker, any changes you make to your local files will be reflected in the Docker container thanks to the volume mapping in the `docker-compose.yml` file. If you add or remove dependencies, however, you'll need to rebuild the Docker image using `docker compose build`. ## đĄ Usage @@ -531,6 +545,13 @@ if __name__ == "__main__": <td><a href="https://github.com/HexyeDEV/Telegram-Chatbot-Gpt4Free/issues"><img alt="Issues" src="https://img.shields.io/github/issues/HexyeDEV/Telegram-Chatbot-Gpt4Free?style=flat-square&labelColor=343b41"/></a></td> <td><a href="https://github.com/HexyeDEV/Telegram-Chatbot-Gpt4Free/pulls"><img alt="Pull Requests" src="https://img.shields.io/github/issues-pr/HexyeDEV/Telegram-Chatbot-Gpt4Free?style=flat-square&labelColor=343b41"/></a></td> </tr> + <tr> + <td><a href="https://github.com/Lin-jun-xiang/chatgpt-line-bot"><b>ChatGpt Line Bot</b></a></td> + <td><a href="https://github.com/Lin-jun-xiang/chatgpt-line-bot/stargazers"><img alt="Stars" src="https://img.shields.io/github/stars/Lin-jun-xiang/chatgpt-line-bot?style=flat-square&labelColor=343b41"/></a></td> + <td><a href="https://github.com/Lin-jun-xiang/chatgpt-line-bot/network/members"><img alt="Forks" src="https://img.shields.io/github/forks/Lin-jun-xiang/chatgpt-line-bot?style=flat-square&labelColor=343b41"/></a></td> + <td><a href="https://github.com/Lin-jun-xiang/chatgpt-line-bot/issues"><img alt="Issues" src="https://img.shields.io/github/issues/Lin-jun-xiang/chatgpt-line-bot?style=flat-square&labelColor=343b41"/></a></td> + <td><a href="https://github.com/Lin-jun-xiang/chatgpt-line-bot/pulls"><img alt="Pull Requests" src="https://img.shields.io/github/issues-pr/Lin-jun-xiang/chatgpt-line-bot?style=flat-square&labelColor=343b41"/></a></td> + </tr> <tr> <td><a href="https://github.com/Lin-jun-xiang/action-translate-readme"><b>Action Translate Readme</b></a></td> <td><a href="https://github.com/Lin-jun-xiang/action-translate-readme/stargazers"><img alt="Stars" src="https://img.shields.io/github/stars/Lin-jun-xiang/action-translate-readme?style=flat-square&labelColor=343b41"/></a></td> diff --git a/g4f/__init__.py b/g4f/__init__.py index 25e31833..fd8aa306 100644 --- a/g4f/__init__.py +++ b/g4f/__init__.py @@ -5,7 +5,7 @@ from .Provider import BaseProvider, RetryProvider from .typing import Messages, CreateResult, Union, List from . import debug -version = '0.1.8.1' +version = '0.1.8.2' version_check = True def check_pypi_version() -> None: @@ -15,6 +15,8 @@ def check_pypi_version() -> None: if version != latest_version: print(f'New pypi version: {latest_version} (current: {version}) | pip install -U g4f') + return False + return True except Exception as e: print(f'Failed to check g4f pypi version: {e}') diff --git a/g4f/api/__init__.py b/g4f/api/__init__.py index ad3b0db4..8eceb743 100644 --- a/g4f/api/__init__.py +++ b/g4f/api/__init__.py @@ -1,3 +1,6 @@ +import ast +import logging + from fastapi import FastAPI, Response, Request from fastapi.responses import StreamingResponse from typing import List, Union, Any, Dict, AnyStr @@ -68,14 +71,24 @@ class Api: 'stream': False, } - item_data.update(item or {}) + # item contains byte keys, and dict.get suppresses error + item_data.update({key.decode('utf-8') if isinstance(key, bytes) else key: str(value) for key, value in (item or {}).items()}) + # messages is str, need dict + if isinstance(item_data.get('messages'), str): + item_data['messages'] = ast.literal_eval(item_data.get('messages')) + model = item_data.get('model') stream = item_data.get('stream') messages = item_data.get('messages') try: - response = g4f.ChatCompletion.create(model=model, stream=stream, messages=messages) - except: + response = g4f.ChatCompletion.create( + model=model, + stream=stream, + messages=messages, + list_ignored_providers=self.list_ignored_providers) + except Exception as e: + logging.exception(e) return Response(content=json.dumps({"error": "An error occurred while generating the response."}, indent=4), media_type="application/json") completion_id = ''.join(random.choices(string.ascii_letters + string.digits, k=28)) @@ -11,7 +11,7 @@ with codecs.open(os.path.join(here, 'README.md'), encoding='utf-8') as fh: with open('requirements.txt') as f: required = f.read().splitlines() -VERSION = '0.1.8.1' +VERSION = '0.1.8.2' DESCRIPTION = ( 'The official gpt4free repository | various collection of powerful language models' ) |