Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support LangChain #344

Merged
merged 11 commits into from
Oct 22, 2023
Merged

feat: support LangChain #344

merged 11 commits into from
Oct 22, 2023

Conversation

dongjing007
Copy link
Contributor

Implement local services: search, mathematical operations, email summary

Implement local services: search, mathematical operations, email summary
@yihong0618
Copy link
Owner

@yihong0618 @frostming @pjq can you help to review this, seems amazing

Implement local services: search, mathematical operations, email summary
@dongjing007
Copy link
Contributor Author

dongjing007 commented Oct 18, 2023

演示:
1、注册 serpai,将key写入环境变量 export SERPAPI_API_KEY=xxx
2、调用服务:python xiaogpt.py --hardware Lx06 --use_langchain --mute_xiaoai --stream --openai_key ${your_api_key} --serpapi_api_key ${your_serpapi_key}
3、query eg:'杭州亚运会中国队获得了多少枚金牌?' /// '计算3的2次方' // '帮我总结今天收到的邮件'(需配置邮箱信息)

运行:
image

待办:
1、历史对话记录,待使用LangChain扩展
2、目前仅支持--stream流

xiaogpt很棒,谢谢提供这么好玩的项目!关于pr有任何问题,欢迎联系告知,致敬~ :)

@yihong0618
Copy link
Owner

@dongjing007 感谢。有个小建议,能把注释和 print 改成英文么?不是因为我们是国际化的,而是之前用英语弄的,稍微统一一点儿。

hint:

pip install -U black
black .

@yihong0618
Copy link
Owner

可能需要把你的工作添加到 README 里

@dongjing007
Copy link
Contributor Author

@dongjing007 感谢。有个小建议,能把注释和 print 改成英文么?不是因为我们是国际化的,而是之前用英语弄的,稍微统一一点儿。

hint:

pip install -U black black .

好的,沒问题,我改下~

@dongjing007
Copy link
Contributor Author

可能需要把你的工作添加到 README 里

好的,我再补充下

@dongjing007
Copy link
Contributor Author

@yihong0618 你好,已经对PR进行了优化:

fix:

  • requirements.txt / pyproject.toml 增加包支持

style:

  • black .

docs:

  • 注释及print转为英文。(prompt及query涉及程序运行,因未做改动)
  • 修改readme:增加对langchain运行的说明

麻烦再看一下,是否还有其他问题,谢谢~ 😃

@yihong0618
Copy link
Owner

好的,可能晚上看哈,白天有点事情。

@dongjing007
Copy link
Contributor Author

好的,可能晚上看哈,白天有点事情。

嗯嗯,不急的,有空再处理

README.md Outdated
@@ -76,6 +77,10 @@ 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模式)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

目前仅支持stream模式 -> 目前仅支持 stream 模式

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok,已调整

README.md Outdated
@@ -57,6 +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)服务,实现上网检索、数学运算..
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

来调用 LangChain(默认 chatgpt)服务,实现上网检索、数学运算..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok,已调整

pyproject.toml Outdated
@@ -20,6 +20,11 @@ dependencies = [
"bardapi",
"edge-tts>=6.1.3",
"EdgeGPT==0.1.26",
"langchain",
"datetime",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lock the langchain version since it changes a lot

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok,已调整

else:
break
except Exception as e:
# 处理异常的代码
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop the comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok,已调整

@yihong0618
Copy link
Owner

测试了大部分代码没问题,有个小的疑问是,邮件这个功能稍微比较私人话,我们可以把他移动到 langchain/examples 之类的么?
仅仅保持搜索功能。

- sample deletion email summary
- directory optimization

fix:
- the default value should be 'chatgptapi' instead of 'chatgpt'
@dongjing007
Copy link
Contributor Author

测试了大部分代码没问题,有个小的疑问是,邮件这个功能稍微比较私人话,我们可以把他移动到 langchain/examples 之类的么? 仅仅保持搜索功能。

好的,已优化 ~

refactor:

  • sample deletion email summary
  • directory optimization

fix:

  • the default value should be 'chatgptapi' instead of 'chatgpt'

PS:
1、原意是用email总结,示例如何接入langchain自定义 😊
2、PR的代码,我都会从0搭环境和包测试,过程中发现原项目有个默认值设定bug🐛,已一并修复
image

@yihong0618
Copy link
Owner

@dongjing007 thanks merging now.

@yihong0618 yihong0618 merged commit 12158d5 into yihong0618:main Oct 22, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants