Skip to content

Commit

Permalink
Remove gpt4free
Browse files Browse the repository at this point in the history
  • Loading branch information
yym68686 committed Dec 25, 2023
1 parent 3c90dcd commit 91c092d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 33 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,11 @@ Here's a troubleshooting guide: Please carefully check if the GROUP_LIST is corr

To use the document question and answer feature, you must first enable the history record. You can turn on the history record through the `/info` command, or by setting the environment variable `PASS_HISTORY` to `True` to enable the history record by default. Please note that enabling the history record will incur additional costs, so this project does not enable the history record by default. This means that the question and answer feature cannot be used under the default settings. Before using this feature, you need to manually enable the history record.

- What is gpt4free in the `/info` command? Do I need to enable it?
<!-- - What is gpt4free in the `/info` command? Do I need to enable it?
gpt4free is an open-source project that reverse-engineers multiple platforms to use models like gpt4/gpt3 for free. As it's a free API, it may be unstable, so please use it with caution. If you have your own API, it is recommended to use that as a priority.
You can enable gpt4free by simply clicking on it in the `/info` command. Please note that gpt4free does not support all models. You can check the gpt4free documentation to see which models it supports. Once gpt4free is enabled, all questions and searches will use the gpt4free API. If you encounter any errors, please copy the robot's backend log to @yym68686, or open an issue on GitHub. Our developers will resolve it as soon as possible.
You can enable gpt4free by simply clicking on it in the `/info` command. Please note that gpt4free does not support all models. You can check the gpt4free documentation to see which models it supports. Once gpt4free is enabled, all questions and searches will use the gpt4free API. If you encounter any errors, please copy the robot's backend log to @yym68686, or open an issue on GitHub. Our developers will resolve it as soon as possible. -->

- After setting the `NICK`, there's no response when I @ the bot, and it only replies when the message starts with the nick. How can I make it respond to both the nick and @botname?

Expand Down
10 changes: 5 additions & 5 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ async def command_bot(update, context, language=None, prompt=translator_prompt,
if message:
if "claude" in config.GPT_ENGINE and config.ClaudeAPI:
robot = config.claudeBot
if not config.API or config.PLUGINS["USE_G4F"]:
import utils.gpt4free as gpt4free
robot = gpt4free
# if not config.API or config.PLUGINS["USE_G4F"]:
# import utils.gpt4free as gpt4free
# robot = gpt4free
if image_url:
robot = config.GPT4visionbot
title = "`🤖️ gpt-4-vision-preview`\n\n"
Expand Down Expand Up @@ -282,16 +282,16 @@ def update_first_buttons_message():
[
InlineKeyboardButton("更换问答模型", callback_data="更换问答模型"),
InlineKeyboardButton(language, callback_data="language"),
InlineKeyboardButton(f"历史记录 {history}", callback_data="PASS_HISTORY"),
],
[
InlineKeyboardButton(f"历史记录 {history}", callback_data="PASS_HISTORY"),
InlineKeyboardButton(f"搜索 {get_plugins_status('SEARCH_USE_GPT')}", callback_data='SEARCH_USE_GPT'),
InlineKeyboardButton(f"当前时间 {get_plugins_status('DATE')}", callback_data='DATE'),
],
[
InlineKeyboardButton(f"URL 总结 {get_plugins_status('URL')}", callback_data='URL'),
InlineKeyboardButton(f"版本信息 {get_plugins_status('VERSION')}", callback_data='VERSION'),
InlineKeyboardButton(f"gpt4free {get_plugins_status('USE_G4F')}", callback_data='USE_G4F'),
# InlineKeyboardButton(f"gpt4free {get_plugins_status('USE_G4F')}", callback_data='USE_G4F'),
],
]
return first_buttons
Expand Down
2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

PLUGINS = {
"SEARCH_USE_GPT": (os.environ.get('SEARCH_USE_GPT', "True") == "False") == False,
"USE_G4F": (os.environ.get('USE_G4F', "False") == "False") == False,
# "USE_G4F": (os.environ.get('USE_G4F', "False") == "False") == False,
"DATE": True,
"URL": True,
"VERSION": True,
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ duckduckgo-search==4.1.0
langchain==0.0.271
oauth2client==3.0.0
pdfminer.six
g4f==0.1.9.6
# g4f==0.1.9.6

# plugin
pytz
49 changes: 25 additions & 24 deletions utils/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,26 @@
from langchain.tools import DuckDuckGoSearchResults
from langchain.chains import LLMChain

from typing import Optional, List
from langchain.llms.base import LLM
import g4f
class EducationalLLM(LLM):

@property
def _llm_type(self) -> str:
return "custom"

def _call(self, prompt: str, stop: Optional[List[str]] = None) -> str:
out = g4f.ChatCompletion.create(
model=config.GPT_ENGINE,
messages=[{"role": "user", "content": prompt}],
) #
if stop:
stop_indexes = (out.find(s) for s in stop if s in out)
min_stop = min(stop_indexes, default=-1)
if min_stop > -1:
out = out[:min_stop]
return out
# from typing import Optional, List
# from langchain.llms.base import LLM
# import g4f
# class EducationalLLM(LLM):

# @property
# def _llm_type(self) -> str:
# return "custom"

# def _call(self, prompt: str, stop: Optional[List[str]] = None) -> str:
# out = g4f.ChatCompletion.create(
# model=config.GPT_ENGINE,
# messages=[{"role": "user", "content": prompt}],
# ) #
# if stop:
# stop_indexes = (out.find(s) for s in stop if s in out)
# min_stop = min(stop_indexes, default=-1)
# if min_stop > -1:
# out = out[:min_stop]
# return out

class ThreadWithReturnValue(threading.Thread):
def run(self):
Expand Down Expand Up @@ -264,10 +264,11 @@ def get_url_text_list(prompt):
start_time = record_time.time()
yield "🌐 正在搜索您的问题,提取关键词..."

if config.PLUGINS["USE_G4F"]:
chainllm = EducationalLLM()
else:
chainllm = ChatOpenAI(temperature=config.temperature, openai_api_base=config.bot_api_url.v1_url, model_name=config.GPT_ENGINE, openai_api_key=config.API)
# if config.PLUGINS["USE_G4F"]:
# chainllm = EducationalLLM()
# else:
# chainllm = ChatOpenAI(temperature=config.temperature, openai_api_base=config.bot_api_url.v1_url, model_name=config.GPT_ENGINE, openai_api_key=config.API)
chainllm = ChatOpenAI(temperature=config.temperature, openai_api_base=config.bot_api_url.v1_url, model_name=config.GPT_ENGINE, openai_api_key=config.API)

url_set_list, url_pdf_set_list = yield from get_search_url(prompt, chainllm)

Expand Down

0 comments on commit 91c092d

Please sign in to comment.