GithubHelp home page GithubHelp logo

llm-couplet-composer's Introduction

📜🖌️ LLM Chinese Couplet Composer

Static Badge Python Version GitHub License GitHub last commit

🏮 语言模型创作对联 - 基于 LangChain 实现 🏮

快速开始

pip 安装

git clone [email protected]:habaneraa/llm-couplet-composer.git
cd llm-couplet-composer
pip install -e .

poetry 安装

git clone [email protected]:habaneraa/llm-couplet-composer.git
cd llm-couplet-composer
poetry install

或者,手动安装依赖,不安装此包

pip install langchain langchain-openai typer

配置模型调用 API:请按照 model_config.yml.example 手动修改,修改后删掉 .example 后缀

安装包后可以直接在命令行启动: couplet <上联> (确保你在虚拟环境内)

或者执行 Python: python ./llm_couplet/cli.py <上联>

Python 批量调用 (使用协程)

from llm_couplet.chain import CoupletComposer, LLMConfig

api_key = 'xxx'
base_url = 'https://api.openai.com/v1'
composer = CoupletComposer(
    LLMConfig('gpt-3.5-turbo-instruct', api_key, base_url, 0.1),
    LLMConfig('gpt-3.5-turbo', api_key, base_url, 0.7),
)

async def process_inputs(inputs: list[str]) -> list[str]:
    tasks = [asyncio.create_task(composer.acompose(input_str)) for input_str in inputs]
    return await asyncio.gather(*tasks)

上联 = ['烟锁池塘柳', '建党创军,开天辟地锤镰举', '学历非能力']
下联 = asyncio.run(process_inputs(上联))
for first, last in zip(上联, 下联):
    print(f'上联:{first};下联:{last}')

llm-couplet-composer's People

Contributors

habaneraa avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.