Skip to content

Commit

Permalink
docs:document optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
dongjing007 committed Oct 20, 2023
1 parent 7739047 commit 630e563
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 15 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Play ChatGPT and other LLM with Xiaomi AI Speaker
- 如果你遇到了墙需要用 Cloudflare Workers 替换 api_base 请使用 `--api_base ${url}` 来替换。 **请注意,此处你输入的api应该是'`https://xxxx/v1`'的字样,域名需要用引号包裹**
- 可以跟小爱说 `开始持续对话` 自动进入持续对话状态,`结束持续对话` 结束持续对话状态。
- 可以使用 `--enable_edge_tts` 来获取更好的 tts 能力
- 可以使用 `--use_langchain` 替代 `--use_chatgpt_api` 来调用LangChain(默认chatgpt)服务,实现上网检索、数学运算..
- 可以使用 `--use_langchain` 替代 `--use_chatgpt_api` 来调用 LangChain(默认 chatgpt)服务,实现上网检索、数学运算..

e.g.

Expand All @@ -77,7 +77,7 @@ export OPENAI_API_KEY=${your_api_key}
xiaogpt --hardware LX06 --mute_xiaoai --use_gpt3
# 如果你想用 edge-tts
xiaogpt --hardware LX06 --cookie ${cookie} --use_chatgpt_api --enable_edge_tts
# 如果你想使用 LangChain + SerpApi 实现上网检索或其他本地服务(目前仅支持stream模式
# 如果你想使用 LangChain + SerpApi 实现上网检索或其他本地服务(目前仅支持 stream 模式
export OPENAI_API_KEY=${your_api_key}
export SERPAPI_API_KEY=${your_serpapi_key}
xiaogpt --hardware Lx06 --use_langchain --mute_xiaoai --stream --openai_key ${your_api_key} --serpapi_api_key ${your_serpapi_key}
Expand All @@ -102,7 +102,7 @@ python3 xiaogpt.py --hardware LX06 --mute_xiaoai --use_gpt3
python3 xiaogpt.py --hardware LX06 --mute_xiaoai --use_glm --glm_key ${glm_key}
# 如果你想使用 google 的 bard
python3 xiaogpt.py --hardware LX06 --mute_xiaoai --use_bard --bard_token ${bard_token}
# 如果你想使用 LangChain+SerpApi 实现上网检索或其他本地服务(目前仅支持stream模式
# 如果你想使用 LangChain+SerpApi 实现上网检索或其他本地服务(目前仅支持 stream 模式
export OPENAI_API_KEY=${your_api_key}
export SERPAPI_API_KEY=${your_serpapi_key}
python3 xiaogpt.py --hardware Lx06 --use_langchain --mute_xiaoai --stream --openai_key ${your_api_key} --serpapi_api_key ${your_serpapi_key}
Expand Down
12 changes: 7 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ dependencies = [
"bardapi",
"edge-tts>=6.1.3",
"EdgeGPT==0.1.26",
"langchain",
"datetime",
"bs4",
"chardet",
"typing"
"langchain==0.0.301",
"datetime==5.2",
"bs4==0.0.1",
"chardet==5.1.0",
"typing==3.7.4.3",
"google-search-results==2.4.2",
"numexpr==2.8.6"
]
license = {text = "MIT"}
dynamic = ["version"]
Expand Down
5 changes: 4 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ wcwidth==0.2.6
websockets==11.0
yarl==1.8.2
zhipuai==1.0.7
langchain==0.0.314
langchain==0.0.301
datetime==5.2
bs4==0.0.1
chardet==5.1.0
typing==3.7.4.3
google-search-results==2.4.2
numexpr==2.8.6

5 changes: 3 additions & 2 deletions xiaogpt/bot/langchain_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def from_config(cls, config):

async def ask(self, query, **options):
# todo,Currently only supports stream
raise Exception("The bot does not support it. Please use 'ask_stream'.")
raise Exception(
"The bot does not support it. Please use 'ask_stream,add: --stream'"
)

async def ask_stream(self, query, **options):
agent_search(query)
Expand All @@ -43,5 +45,4 @@ async def ask_stream(self, query, **options):
else:
break
except Exception as e:
# 处理异常的代码
print("An error occurred:", str(e))
8 changes: 5 additions & 3 deletions xiaogpt/langchain/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
from langchain.agents import AgentType
from langchain.tools import BaseTool
from langchain.llms import OpenAI
from langchain import LLMMathChain, SerpAPIWrapper

# from langchain.chains import LLMMathChain
from langchain.utilities import SerpAPIWrapper
from langchain.chat_models import ChatOpenAI
from langchain.memory import ChatMessageHistory
from xiaogpt.langchain.stream_call_back import StreamCallbackHandler
Expand All @@ -23,13 +25,13 @@ def agent_search(query):

# Initialization: search chain, mathematical calculation chain, custom summary email chain
search = SerpAPIWrapper()
llm_math_chain = LLMMathChain(llm=llm, verbose=False)
# llm_math_chain = LLMMathChain.from_llm(llm=llm, verbose=False)
mail_summary = MailSummaryTool()

# Tool list: search, mathematical calculations, custom summary emails
tools = [
Tool(name="Search", func=search.run, description="如果你不知道或不确定答案,可以使用这个搜索引擎检索答案"),
Tool(name="Calculator", func=llm_math_chain.run, description="在需要回答数学问题时非常有用"),
# Tool(name="Calculator", func=llm_math_chain.run, description="在需要回答数学问题时非常有用"),
Tool(
name="MailSummary",
func=mail_summary.run,
Expand Down
2 changes: 1 addition & 1 deletion xiaogpt/langchain/stream_call_back.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ def on_llm_new_token(self, token: str, **kwargs: Any) -> None:
token_copy = token
code = chardet.detect(token_copy.encode())["encoding"]
if code is not None:
# 接收流消息入队,在ask_stream时出队
# Receive stream messages into the queue and dequeue when ask_stream
streaming_call_queue.put(token)

0 comments on commit 630e563

Please sign in to comment.