← 返回
沟通协作 Key 中文

Pywayne Llm Chat Bot

LLM chat interface using OpenAI-compatible APIs with streaming support and session management. Use when working with pywayne.llm.chat_bot module for creating...
支持流式传输和会话管理的 OpenAI 兼容 API 大模型聊天界面。用于 pywayne.llm.chat_bot 模块创建...
wangyendt
沟通协作 clawhub v0.1.0 1 版本 99883 Key: 需要
★ 0
Stars
📥 854
下载
💾 13
安装
1
版本
#latest

概述

Pywayne LLM Chat Bot

This module provides a synchronous LLM chat interface compatible with OpenAI APIs (including local servers like Ollama).

Quick Start

from pywayne.llm.chat_bot import LLMChat

# Create chat instance
chat = LLMChat(
    base_url="https://api.example.com/v1",
    api_key="your_api_key",
    model="deepseek-chat"
)

# Single-turn conversation (non-streaming)
response = chat.ask("Hello, LLM!", stream=False)
print(response)

# Streaming response
for token in chat.ask("Explain recursion", stream=True):
    print(token, end='', flush=True)

Multi-turn Conversation

# Use chat() for history tracking
for token in chat.chat("What is a class in Python?"):
    print(token, end='', flush=True)

# Continuation - remembers previous context
for token in chat.chat("How do I define a constructor?"):
    print(token, end='', flush=True)

# View history
for msg in chat.history:
    print(f"{msg['role']}: {msg['content']}")

# Clear history
chat.clear_history()

Configuration

LLMConfig Class

from pywayne.llm.chat_bot import LLMConfig

config = LLMConfig(
    base_url="https://api.example.com/v1",
    api_key="your_api_key",
    model="deepseek-chat",
    temperature=0.7,
    max_tokens=8192,
    top_p=1.0,
    frequency_penalty=0.0,
    presence_penalty=0.0,
    system_prompt="You are a helpful assistant"
)

chat = LLMChat(**config.to_dict())

Dynamic System Prompt Update

chat.update_system_prompt("You are now a Python expert, provide code examples")

Managing Multiple Sessions

from pywayne.llm.chat_bot import ChatManager

manager = ChatManager(
    base_url="https://api.example.com/v1",
    api_key="your_api_key",
    model="deepseek-chat",
    timeout=300  # Session timeout in seconds
)

# Get or create chat instance (maintains per-session history)
chat1 = manager.get_chat("user1")
chat2 = manager.get_chat("user2")

# Sessions are independent
chat1.chat("Hello from user1")
chat2.chat("Hello from user2")

# Remove a session
manager.remove_chat("user1")

Custom Configuration per Session

custom_config = LLMConfig(
    base_url=base_url,
    api_key=api_key,
    model="deepseek-chat",
    temperature=0.9,
    system_prompt="You are a creative writer"
)

chat3 = manager.get_chat("user3", config=custom_config)

API Reference

LLMChat

MethodDescription
---------------------
ask(prompt, stream=False)Single-turn conversation without history
chat(prompt, stream=True)Multi-turn conversation with history tracking
update_system_prompt(prompt)Update system prompt in-place
clear_history()Clear conversation history (keeps system prompt)
history (property)Get copy of current conversation history

ChatManager

MethodDescription
---------------------
get_chat(chat_id, stream=True, config=None)Get or create chat instance by ID
remove_chat(chat_id)Remove chat session

Parameters

ParameterDefaultDescription
---------------------------------
base_urlrequiredAPI base URL (e.g., https://api.deepseek.com/v1)
api_keyrequiredAPI authentication key
model"deepseek-chat"Model name
temperature0.7Controls randomness (0-2)
max_tokens2048/8192Maximum output tokens
top_p1.0Nucleus sampling (0-1)
frequency_penalty0.0Reduces repetition (-2 to 2)
presence_penalty0.0Encourages new topics (-2 to 2)
system_prompt"你是一个严谨的助手"System message
timeoutinfSession timeout in seconds (ChatManager only)

版本历史

共 1 个版本

  • v0.1.0 当前
    2026-03-29 09:57 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

productivity

Pywayne Statistics

wangyendt
综合性统计检验库,包含37种以上方法,涵盖正态性检验、位置检验、相关性检验、时间序列检验和模型诊断。
★ 0 📥 1,866
communication-collaboration

imap-smtp-email

gzlicanyi
使用IMAP/SMTP读取和发送邮件;检查新/未读邮件、获取内容、搜索邮箱、标记已读/未读、发送带附件的邮件。支持...
★ 114 📥 52,470
communication-collaboration

Himalaya

lamelas
{"answer":"通过IMAP/SMTP管理邮件的CLI。可在终端使用 `himalaya` 收发、回复、转发、搜索及整理邮件。支持多账户与MML(MIME元语言)编写邮件。"}
★ 68 📥 45,629