Skip to main content

gengwiki-python

梗Wiki 的 Python SDK,支持 Python 3.10 及以上。

pip install gengwiki

到个人中心创建 Key,然后保存到本机,之后的代码里就不用再写它了。

gengwiki keys add 老哥      # 粘贴时不显示,也不会留在命令历史里
gengwiki status            # 查看当前 Key、人设和额度
from gengwiki import GengWiki

client = GengWiki()                        # 也可以传入 Key,或者设置环境变量 GENGWIKI_API_KEY

client.search_memes("躺平")
client.meme("tang-ping").body
client.persona().as_message()              # {"role": "system", "content": "..."}

更多用法见 example/。

切换人设

一个 Key 终身绑定一个人设,所以切换人设就是切换到绑定了它的 Key。没有这样的 Key 时,登录后会自动创建一个并保存。

persona = client.use_persona("温柔姐姐")     # 按标题或 id
messages = [persona.as_message(), {"role": "user", "content": "你好"}]

client.personas("关键词") 可以浏览人设目录。Claude 的系统提示不放在消息列表里,所以要写成 system=persona.prompt。

命令行

安装后可以用 gengwiki,也可以用 python -m gengwiki。

gengwiki login                # 登录,密码不会保存
gengwiki status               # 当前站点、Key、人设和额度
gengwiki search 躺平           # 也有 meme、trending、personas
gengwiki use 温柔姐姐           # 切换人设
gengwiki sync --images        # 下载全部内容供离线使用
gengwiki keys                 # 也有 add、use、remove、secret、remote、rotate、revoke

给大模型用的工具

tools = client.tools.openai()        # OpenAI 和 DeepSeek 等的 Chat Completions
tools = client.tools.responses()     # OpenAI 的 Responses API
tools = client.tools.anthropic()     # Claude

while True:
    reply = llm.chat.completions.create(model=model, messages=messages, tools=tools).choices[0].message
    results = client.tools.run(reply)
    if not results:
        break
    messages += [reply, *results]

Claude 的回复用法相同,只是追加时写成 {"role": "assistant", "content": reply.content}。Responses API 把 response 传给 run,追加时写成 input += [*response.output, *results]。

想让模型不等提问就玩梗,把 client.meme_prompt(用户的话) 放进提示词。它会优先带上这句话提到的梗,再随机补一些 Key 范围内的梗和热门梗,并告诉模型只在非常贴切时才用。client.match_memes(用户的话) 返回这句话提到了哪些梗,可以用来决定机器人要不要插话。两个方法都不调用模型,缓存好之后也不发请求。

共有 5 个工具,分别是 search_memes、get_meme、trending_memes、search_stickers 和 search_lexicon。可以用 client.tools.openai(["search_memes"]) 只选其中几个。

开发

uv run python -m unittest discover -s tests -t .

tests/test_live.py 用来对照真实服务,只有设置了 GENGWIKI_LIVE_API 和 GENGWIKI_LIVE_SITE 才会运行,需要指向一套载入了 tests/live_seed.sql 的临时环境,绝对不要指向生产环境。

Metadata

Release files for gengwiki 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gengwiki 0.2.0
File Size Uploaded Provenance Actions
gengwiki-0.2.0.tar.gz 24.2 kB Without provenance Details for gengwiki-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gengwiki 0.2.0
File Interpreter ABI Platform Actions
gengwiki-0.2.0-py3-none-any.whl Python 3 none any Details for gengwiki-0.2.0-py3-none-any.whl

Total release size: 52.8 kB

Release files / gengwiki-0.2.0.tar.gz

Download URL gengwiki-0.2.0.tar.gz
Size 24.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2e1bb6ca9b3aaa6553ac452c6b2fb2c2127f28e963582810e1783da738a3689d
BLAKE2b-256 checksum
How to use checksums
be0facf308901687dbb93a03c0570feef3a99446b23d6b2881a9b84a0cec062c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / gengwiki-0.2.0-py3-none-any.whl

Download URL gengwiki-0.2.0-py3-none-any.whl
Size 28.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b49abe28f045cf4c156989f7934986df2409477a1c78d4ab1808afae440978bb
BLAKE2b-256 checksum
How to use checksums
c0e74797a3acdecd942e7d8cd3a099e33844758e92d2902901fc6736f076598f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for gengwiki 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page