学术, 成果公开

使用 guan.chat() 批量处理文本以及灵活搭建大语言模型对话框架

这个网址提供了多个大语言对话模型的 API 接口:https://chat.guanjihuan.com。虽然智能程度不及 ChatGPT, Claude, Gemini, GPT4 等最先进的模型,但对于翻译、润色,以及简单的一些问题,还是足够用的,且可以根据不同模型的回答进行综合判断和筛选。

本篇给出 Guan 软件包调用大语言模型的代码例子,会更灵活一些。如果不愿意折腾的,可以直接使用以上链接的对话界面,忽略本篇内容。

该接口主要的应用场景是批量处理,例如批量翻译、批量提取信息、批量分析、批量分类等。

需要说明的是:使用 guan.chat() 接口不支持上下文的功能。如果需要实现上下文,可以参考这篇:对话模型chat.guanjihuan.com的主要实现代码开源

目前支持五个对话模型,之后可能不定期添加。如果发现 guan.chat() 模型调用失效,可联系我。

  • model=1:'qwen1.5-0.5b-chat'
  • model=2:'qwen-1.8b-chat'
  • model=3:'hunyuan-lite'
  • model=4:'ernie-tiny-8k'
  • model=5:'ernie-lite-8k'

Guan软件包网址:https://py.guanjihuan.com

安装方法:

pip install --upgrade guan -i https://pypi.python.org/simple

pip install --upgrade guan

Guan的版本要求 >= 0.1.106

使用方法:

import guan; response = guan.chat(prompt)

1. 代码示例(默认参数)

import guan
response = guan.chat(prompt='你好', model=1, stream=0, top_p=0.8, temperature=0.85)
print(response)

2. 代码示例(流式输出)

import guan
response = guan.chat(prompt='你好', model=1, stream=1, top_p=0.8, temperature=0.85)
print(response)

3. 代码示例(自动对话)

import guan
response0 = '你好'
for i0 in range(5):
    response1 = guan.chat(prompt=response0, model=1, stream=0, top_p=0.8, temperature=0.85)
    print('Robot 1:'+response1+'\n\n')
    response0 = guan.chat(prompt=response1, model=1, stream=0, top_p=0.8, temperature=0.85)
    print('Robot 2:'+response0+'\n\n')

4. 代码示例(引导对话)

import guan
response0 = '什么是神经网络?'
plus_message = '(回答字数少于50个字,最后反问我一个问题)'
for i0 in range(5):
    response1 = guan.chat(prompt=response0+plus_message, model=1, stream=0, top_p=0.8, temperature=0.85)
    print('Robot 1:'+response1+'\n\n')
    response0 = guan.chat(prompt=response1+plus_message, model=1, stream=0, top_p=0.8, temperature=0.85)
    print('Robot 2:'+response0+'\n\n')

5. 代码示例(分句润色)

import guan
content = "A topological insulator is a material with unique electronic properties. It behaves as an insulator in its interior but has conducting states on its surface. These surface states are protected by time-reversal symmetry and are robust against impurities and disorder. This means that electrons can flow on the surface without backscattering, even in the presence of defects or irregularities in the material. The special properties of topological insulators arise from their topological order, which is a global property of the material's electronic wavefunctions. This makes them interesting for potential applications in quantum computing and spintronics, where stable and efficient control of electronic states is crucial."
plus_message = '对以上文字进行学术英文润色。'
sentence_array = content.split('. ')
for sentence in sentence_array:
    print('润色前:', sentence+'. ')
    response = guan.chat(prompt=sentence+'. '+plus_message, model=1, stream=0, top_p=0.8, temperature=0.85)
    print('润色后:', response)
    print('\n')
85 次浏览

【说明:本站主要是个人的一些笔记和代码分享,内容可能会不定期修改。为了使全网显示的始终是最新版本,这里的文章未经同意请勿转载。引用请注明出处:https://www.guanjihuan.com

发表评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注

Captcha Code