Home 吴恩达新项目,我加上了国产大模型API.md
Post
Cancel

吴恩达新项目,我加上了国产大模型API.md

大家好,我是章北海

昨天发现了吴恩达老师开源了他的翻译智能体项目:Translation-agent(⬅️点击阅读详情)

这是一个使用 Python 演示的反思智能体工作流的机器翻译示例。

主要步骤如下:

  1. 输入 prompt,使大型语言模型(LLM)将文本从 source_language 翻译成 target_language;
  2. 让 LLM 反思翻译结果,并提出建设性的改进建议;
  3. 利用这些建议改进翻译。

我简单测试了一下,感觉不甚理想。

看了源码,默认使用的 GPT-4 Turbo API,翻译一句话居然花了 0.025 美元,合 1 毛 8 分钱。

吴恩达老师在推特中说:这不是成熟的软件,希望开源社区能让代理翻译工作得更好。

本着向大佬学习的目的,我 Fork 了项目,并把 API 切成了阿里通义千问的 Qwen。

这不仅对国内的同学更友好,价格也更加低廉。

项目地址:https://github.com/tjxj/translation-agent-qwen/

简单测试,感觉比GPT-4还要好一点点

其实蛮简单的,因为 DashScope(阿里巴巴灵积模型服务)提供了与 OpenAI 兼容的接口。

主要看了帮助文档: https://help.aliyun.com/zh/dashscope/developer-reference/activate-dashscope-and-create-an-api-key?spm=a2c4g.11186623.0.0.564346c1orLyaQ

只需要修改/src/translation_agent/utils.py中模型调用部分代码,

然后把 .env 中 OPENAI_API_KEY 换成 DASHSCOPE_API_KEY 即可。

我还加了一个英译中的test.py

1
2
3
4
5
6
import translation_agent as ta
source_lang, target_lang, country = "English", "Simplified Chinese", "China"
source_text= "It's easy to look sharp when you haven't done anything."
print(f"Source text:\n\n{source_text}\n------------\n")
translation = ta.translate(source_lang, target_lang, source_text, country)
print(f"Translation:\n\n{translation}")

使用也很简单:

第一步,安装

1
2
3
4
5
pip install poetry 
git clone https://github.com/andrewyng/translation-agent.git
cd translation-agent
poetry install
poetry shell # activates virtual environment

第二步,填写API

还没有的同学可以申请一下:https://help.aliyun.com/zh/dashscope/opening-service?spm=a2c4g.11186623.0.0.467d64d1BfB7Dk

把 .env.sample 改成 .env,将自己的 DASHSCOPE_API_KEY 填进去

第三步,运行示例代码 test.py

原项目/examples/example_script.py 还提供了一个长文本翻译的Demo,对翻译质量敏感的同学可以试试。

This post is licensed under CC BY 4.0 by the author.