repo
stringlengths
7
90
file_url
stringlengths
81
315
file_path
stringlengths
4
228
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 14:38:15
2026-01-05 02:33:18
truncated
bool
2 classes
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/lib/itchat/core.py
lib/itchat/core.py
import requests from . import storage class Core(object): def __init__(self): ''' init is the only method defined in core.py alive is value showing whether core is running - you should call logout method to change it - after logout, a core object can login again...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/lib/itchat/log.py
lib/itchat/log.py
import logging class LogSystem(object): handlerList = [] showOnCmd = True loggingLevel = logging.INFO loggingFile = None def __init__(self): self.logger = logging.getLogger('itchat') self.logger.addHandler(logging.NullHandler()) self.logger.setLevel(self.loggingLevel) ...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/lib/itchat/utils.py
lib/itchat/utils.py
import re, os, sys, subprocess, copy, traceback, logging try: from HTMLParser import HTMLParser except ImportError: from html.parser import HTMLParser try: from urllib import quote as _quote quote = lambda n: _quote(n.encode('utf8', 'replace')) except ImportError: from urllib.parse import quote im...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/lib/itchat/config.py
lib/itchat/config.py
import os, platform VERSION = '1.5.0.dev' # use this envrionment to initialize the async & sync componment ASYNC_COMPONENTS = os.environ.get('ITCHAT_UOS_ASYNC', False) BASE_URL = 'https://login.weixin.qq.com' OS = platform.system() # Windows, Linux, Darwin DIR = os.getcwd() DEFAULT_QR = 'QR.png' TIMEOUT = (10, 60) ...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/lib/itchat/__init__.py
lib/itchat/__init__.py
from .core import Core from .config import VERSION, ASYNC_COMPONENTS from .log import set_logging if ASYNC_COMPONENTS: from .async_components import load_components else: from .components import load_components __version__ = VERSION instanceList = [] def load_async_itchat() -> Core: """load async-base...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/lib/itchat/content.py
lib/itchat/content.py
TEXT = 'Text' MAP = 'Map' CARD = 'Card' NOTE = 'Note' SHARING = 'Sharing' PICTURE = 'Picture' RECORDING = VOICE = 'Recording' ATTACHMENT = 'Attachment' VIDEO = 'Video' FRIENDS = 'Friends' SYSTEM = 'System' INCOME_MSG = [TEXT, MAP, CARD, NOTE, SHARING, PICTURE, RECORDING,...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/lib/itchat/storage/messagequeue.py
lib/itchat/storage/messagequeue.py
import logging try: import Queue as queue except ImportError: import queue from .templates import AttributeDict logger = logging.getLogger('itchat') class Queue(queue.Queue): def put(self, message): queue.Queue.put(self, Message(message)) class Message(AttributeDict): def download(self, file...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/lib/itchat/storage/templates.py
lib/itchat/storage/templates.py
import logging, copy, pickle from weakref import ref from ..returnvalues import ReturnValue from ..utils import update_info_dict logger = logging.getLogger('itchat') class AttributeDict(dict): def __getattr__(self, value): keyName = value[0].upper() + value[1:] try: return self[keyNam...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/lib/itchat/storage/__init__.py
lib/itchat/storage/__init__.py
import os, time, copy from threading import Lock from .messagequeue import Queue from .templates import ( ContactList, AbstractUserDict, User, MassivePlatform, Chatroom, ChatroomMember) def contact_change(fn): def _contact_change(core, *args, **kwargs): with core.storageClass.updateLock: ...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/lib/itchat/components/login.py
lib/itchat/components/login.py
import os import time import re import io import threading import json import xml.dom.minidom import random import traceback import logging try: from httplib import BadStatusLine except ImportError: from http.client import BadStatusLine import requests from pyqrcode import QRCode from .. import config, utils ...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/lib/itchat/components/register.py
lib/itchat/components/register.py
import logging, traceback, sys, threading try: import Queue except ImportError: import queue as Queue from ..log import set_logging from ..utils import test_connect from ..storage import templates logger = logging.getLogger('itchat') def load_register(core): core.auto_login = auto_login core.co...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/lib/itchat/components/__init__.py
lib/itchat/components/__init__.py
from .contact import load_contact from .hotreload import load_hotreload from .login import load_login from .messages import load_messages from .register import load_register def load_components(core): load_contact(core) load_hotreload(core) load_login(core) load_messages(core) load_register(core)
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/lib/itchat/components/messages.py
lib/itchat/components/messages.py
import os, time, re, io import json import mimetypes, hashlib import logging from collections import OrderedDict import requests from .. import config, utils from ..returnvalues import ReturnValue from ..storage import templates from .contact import update_local_uin logger = logging.getLogger('itchat') def load_mes...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/lib/itchat/components/hotreload.py
lib/itchat/components/hotreload.py
import pickle, os import logging import requests from ..config import VERSION from ..returnvalues import ReturnValue from ..storage import templates from .contact import update_local_chatrooms, update_local_friends from .messages import produce_msg logger = logging.getLogger('itchat') def load_hotreload(core): ...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/lib/itchat/components/contact.py
lib/itchat/components/contact.py
import time import re import io import json import copy import logging from .. import config, utils from ..returnvalues import ReturnValue from ..storage import contact_change from ..utils import update_info_dict logger = logging.getLogger('itchat') def load_contact(core): core.update_chatroom = update_chatroom...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/lib/itchat/async_components/login.py
lib/itchat/async_components/login.py
import asyncio import os, time, re, io import threading import json import random import traceback import logging try: from httplib import BadStatusLine except ImportError: from http.client import BadStatusLine import requests # type: ignore from pyqrcode import QRCode from .. import config, utils from ..ret...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/lib/itchat/async_components/register.py
lib/itchat/async_components/register.py
import logging, traceback, sys, threading try: import Queue except ImportError: import queue as Queue # type: ignore from ..log import set_logging from ..utils import test_connect from ..storage import templates logger = logging.getLogger('itchat') def load_register(core): core.auto_login = auto_l...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/lib/itchat/async_components/__init__.py
lib/itchat/async_components/__init__.py
from .contact import load_contact from .hotreload import load_hotreload from .login import load_login from .messages import load_messages from .register import load_register def load_components(core): load_contact(core) load_hotreload(core) load_login(core) load_messages(core) load_register(core)
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/lib/itchat/async_components/messages.py
lib/itchat/async_components/messages.py
import os, time, re, io import json import mimetypes, hashlib import logging from collections import OrderedDict from .. import config, utils from ..returnvalues import ReturnValue from ..storage import templates from .contact import update_local_uin logger = logging.getLogger('itchat') def load_messages(core): ...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/lib/itchat/async_components/hotreload.py
lib/itchat/async_components/hotreload.py
import pickle, os import logging import requests # type: ignore from ..config import VERSION from ..returnvalues import ReturnValue from ..storage import templates from .contact import update_local_chatrooms, update_local_friends from .messages import produce_msg logger = logging.getLogger('itchat') def load_hotre...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/lib/itchat/async_components/contact.py
lib/itchat/async_components/contact.py
import time, re, io import json, copy import logging from .. import config, utils from ..components.contact import accept_friend from ..returnvalues import ReturnValue from ..storage import contact_change from ..utils import update_info_dict logger = logging.getLogger('itchat') def load_contact(core): core.updat...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/channel/channel_factory.py
channel/channel_factory.py
""" channel factory """ from common import const from .channel import Channel def create_channel(channel_type) -> Channel: """ create a channel instance :param channel_type: channel type code :return: channel instance """ ch = Channel() if channel_type == "wx": from channel.wechat....
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/channel/chat_message.py
channel/chat_message.py
""" 本类表示聊天消息,用于对itchat和wechaty的消息进行统一的封装。 填好必填项(群聊6个,非群聊8个),即可接入ChatChannel,并支持插件,参考TerminalChannel ChatMessage msg_id: 消息id (必填) create_time: 消息创建时间 ctype: 消息类型 : ContextType (必填) content: 消息内容, 如果是声音/图片,这里是文件路径 (必填) from_user_id: 发送者id (必填) from_user_nickname: 发送者昵称 to_user_id: 接收者id (必填) to_user_nickname: 接收者昵称 ...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/channel/chat_channel.py
channel/chat_channel.py
import os import re import threading import time from asyncio import CancelledError from concurrent.futures import Future, ThreadPoolExecutor from bridge.context import * from bridge.reply import * from channel.channel import Channel from common.dequeue import Dequeue from common import memory from plugins import * t...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/channel/channel.py
channel/channel.py
""" Message sending channel abstract class """ from bridge.bridge import Bridge from bridge.context import Context from bridge.reply import * class Channel(object): channel_type = "" NOT_SUPPORT_REPLYTYPE = [ReplyType.VOICE, ReplyType.IMAGE] def startup(self): """ init channel ""...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/channel/wechatcom/wechatcomapp_message.py
channel/wechatcom/wechatcomapp_message.py
from wechatpy.enterprise import WeChatClient from bridge.context import ContextType from channel.chat_message import ChatMessage from common.log import logger from common.tmp_dir import TmpDir class WechatComAppMessage(ChatMessage): def __init__(self, msg, client: WeChatClient, is_group=False): super()._...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/channel/wechatcom/wechatcomapp_client.py
channel/wechatcom/wechatcomapp_client.py
# wechatcomapp_client.py import threading import time from wechatpy.enterprise import WeChatClient class WechatComAppClient(WeChatClient): def __init__(self, corp_id, secret, access_token=None, session=None, timeout=None, auto_retry=True): super(WechatComAppClient, self).__init__(corp_id, secret, access_to...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/channel/wechatcom/wechatcomapp_channel.py
channel/wechatcom/wechatcomapp_channel.py
# -*- coding=utf-8 -*- import io import os import time import requests import web from wechatpy.enterprise import create_reply, parse_message from wechatpy.enterprise.crypto import WeChatCrypto from wechatpy.enterprise.exceptions import InvalidCorpIdException from wechatpy.exceptions import InvalidSignatureException, ...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/channel/wechat/wechat_message.py
channel/wechat/wechat_message.py
import re from bridge.context import ContextType from channel.chat_message import ChatMessage from common.log import logger from common.tmp_dir import TmpDir from lib import itchat from lib.itchat.content import * class WechatMessage(ChatMessage): def __init__(self, itchat_msg, is_group=False): super().__...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/channel/wechat/wcf_message.py
channel/wechat/wcf_message.py
# encoding:utf-8 """ wechat channel message """ from bridge.context import ContextType from channel.chat_message import ChatMessage from common.log import logger from wcferry import WxMsg class WechatfMessage(ChatMessage): """ 微信消息封装类 """ def __init__(self, channel, wcf_msg: WxMsg, is_group=False):...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/channel/wechat/wechaty_message.py
channel/wechat/wechaty_message.py
import asyncio import re from wechaty import MessageType from wechaty.user import Message from bridge.context import ContextType from channel.chat_message import ChatMessage from common.log import logger from common.tmp_dir import TmpDir class aobject(object): """Inheriting this class allows you to define an as...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/channel/wechat/wechaty_channel.py
channel/wechat/wechaty_channel.py
# encoding:utf-8 """ wechaty channel Python Wechaty - https://github.com/wechaty/python-wechaty """ import asyncio import base64 import os import time from wechaty import Contact, Wechaty from wechaty.user import Message from wechaty_puppet import FileBox from bridge.context import * from bridge.context import Conte...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/channel/wechat/wcf_channel.py
channel/wechat/wcf_channel.py
# encoding:utf-8 """ wechat channel """ import io import json import os import threading import time from queue import Empty from typing import Any from bridge.context import * from bridge.reply import * from channel.chat_channel import ChatChannel from channel.wechat.wcf_message import WechatfMessage from common.lo...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/channel/wechat/wechat_channel.py
channel/wechat/wechat_channel.py
# encoding:utf-8 """ wechat channel """ import io import json import os import threading import time import requests from bridge.context import * from bridge.reply import * from channel.chat_channel import ChatChannel from channel import chat_channel from channel.wechat.wechat_message import * from common.expired_di...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/channel/feishu/feishu_channel.py
channel/feishu/feishu_channel.py
""" 飞书通道接入 @author Saboteur7 @Date 2023/11/19 """ # -*- coding=utf-8 -*- import uuid import requests import web from channel.feishu.feishu_message import FeishuMessage from bridge.context import Context from bridge.reply import Reply, ReplyType from common.log import logger from common.singleton import singleton fro...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/channel/feishu/feishu_message.py
channel/feishu/feishu_message.py
from bridge.context import ContextType from channel.chat_message import ChatMessage import json import requests from common.log import logger from common.tmp_dir import TmpDir from common import utils class FeishuMessage(ChatMessage): def __init__(self, event: dict, is_group=False, access_token=None): sup...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/channel/dingtalk/dingtalk_message.py
channel/dingtalk/dingtalk_message.py
import os import requests from dingtalk_stream import ChatbotMessage from bridge.context import ContextType from channel.chat_message import ChatMessage # -*- coding=utf-8 -*- from common.log import logger from common.tmp_dir import TmpDir class DingTalkMessage(ChatMessage): def __init__(self, event: ChatbotMes...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/channel/dingtalk/dingtalk_channel.py
channel/dingtalk/dingtalk_channel.py
""" 钉钉通道接入 @author huiwen @Date 2023/11/28 """ import copy import json # -*- coding=utf-8 -*- import logging import time import dingtalk_stream from dingtalk_stream import AckMessage from dingtalk_stream.card_replier import AICardReplier from dingtalk_stream.card_replier import AICardStatus from dingtalk_stream.card_...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/channel/terminal/terminal_channel.py
channel/terminal/terminal_channel.py
import sys from bridge.context import * from bridge.reply import Reply, ReplyType from channel.chat_channel import ChatChannel, check_prefix from channel.chat_message import ChatMessage from common.log import logger from config import conf class TerminalMessage(ChatMessage): def __init__( self, m...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/channel/wework/run.py
channel/wework/run.py
import os import time os.environ['ntwork_LOG'] = "ERROR" import ntwork wework = ntwork.WeWork() def forever(): try: while True: time.sleep(0.1) except KeyboardInterrupt: ntwork.exit_() os._exit(0)
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/channel/wework/wework_channel.py
channel/wework/wework_channel.py
import io import os import random import tempfile import threading os.environ['ntwork_LOG'] = "ERROR" import ntwork import requests import uuid from bridge.context import * from bridge.reply import * from channel.chat_channel import ChatChannel from channel.wework.wework_message import * from channel.wework.wework_mes...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/channel/wework/wework_message.py
channel/wework/wework_message.py
import datetime import json import os import re import time import pilk from bridge.context import ContextType from channel.chat_message import ChatMessage from common.log import logger from ntwork.const import send_type def get_with_retry(get_func, max_retries=5, delay=5): retries = 0 result = None whil...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/channel/wechatmp/passive_reply.py
channel/wechatmp/passive_reply.py
import asyncio import time import web from wechatpy import parse_message from wechatpy.replies import ImageReply, VoiceReply, create_reply import textwrap from bridge.context import * from bridge.reply import * from channel.wechatmp.common import * from channel.wechatmp.wechatmp_channel import WechatMPChannel from cha...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/channel/wechatmp/wechatmp_channel.py
channel/wechatmp/wechatmp_channel.py
# -*- coding: utf-8 -*- import asyncio import imghdr import io import os import threading import time import requests import web from wechatpy.crypto import WeChatCrypto from wechatpy.exceptions import WeChatClientException from collections import defaultdict from bridge.context import * from bridge.reply import * fr...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/channel/wechatmp/wechatmp_client.py
channel/wechatmp/wechatmp_client.py
import threading import time from wechatpy.client import WeChatClient from wechatpy.exceptions import APILimitedException from channel.wechatmp.common import * from common.log import logger class WechatMPClient(WeChatClient): def __init__(self, appid, secret, access_token=None, session=None, timeout=None, auto_...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/channel/wechatmp/common.py
channel/wechatmp/common.py
import web from wechatpy.crypto import WeChatCrypto from wechatpy.exceptions import InvalidSignatureException from wechatpy.utils import check_signature from config import conf MAX_UTF8_LEN = 2048 class WeChatAPIException(Exception): pass def verify_server(data): try: signature = data.signature ...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/channel/wechatmp/wechatmp_message.py
channel/wechatmp/wechatmp_message.py
# -*- coding: utf-8 -*-# from bridge.context import ContextType from channel.chat_message import ChatMessage from common.log import logger from common.tmp_dir import TmpDir class WeChatMPMessage(ChatMessage): def __init__(self, msg, client=None): super().__init__(msg) self.msg_id = msg.id ...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/channel/wechatmp/active_reply.py
channel/wechatmp/active_reply.py
import time import web from wechatpy import parse_message from wechatpy.replies import create_reply from bridge.context import * from bridge.reply import * from channel.wechatmp.common import * from channel.wechatmp.wechatmp_channel import WechatMPChannel from channel.wechatmp.wechatmp_message import WeChatMPMessage ...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
zhayujie/chatgpt-on-wechat
https://github.com/zhayujie/chatgpt-on-wechat/blob/7e12744b8b3b7f42541df6a8eacc38ecec46845e/channel/web/web_channel.py
channel/web/web_channel.py
import sys import time import web import json import uuid from queue import Queue, Empty from bridge.context import * from bridge.reply import Reply, ReplyType from channel.chat_channel import ChatChannel, check_prefix from channel.chat_message import ChatMessage from common.log import logger from common.singleton impo...
python
MIT
7e12744b8b3b7f42541df6a8eacc38ecec46845e
2026-01-04T14:40:46.018222Z
false
google-research/bert
https://github.com/google-research/bert/blob/eedf5716ce1268e56f0a50264a88cafad334ac61/modeling.py
modeling.py
# coding=utf-8 # Copyright 2018 The Google AI Language Team Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by ...
python
Apache-2.0
eedf5716ce1268e56f0a50264a88cafad334ac61
2026-01-04T14:40:51.596425Z
true
google-research/bert
https://github.com/google-research/bert/blob/eedf5716ce1268e56f0a50264a88cafad334ac61/create_pretraining_data.py
create_pretraining_data.py
# coding=utf-8 # Copyright 2018 The Google AI Language Team Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by ...
python
Apache-2.0
eedf5716ce1268e56f0a50264a88cafad334ac61
2026-01-04T14:40:51.596425Z
false
google-research/bert
https://github.com/google-research/bert/blob/eedf5716ce1268e56f0a50264a88cafad334ac61/extract_features.py
extract_features.py
# coding=utf-8 # Copyright 2018 The Google AI Language Team Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by ...
python
Apache-2.0
eedf5716ce1268e56f0a50264a88cafad334ac61
2026-01-04T14:40:51.596425Z
false
google-research/bert
https://github.com/google-research/bert/blob/eedf5716ce1268e56f0a50264a88cafad334ac61/run_classifier_with_tfhub.py
run_classifier_with_tfhub.py
# coding=utf-8 # Copyright 2018 The Google AI Language Team Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by ...
python
Apache-2.0
eedf5716ce1268e56f0a50264a88cafad334ac61
2026-01-04T14:40:51.596425Z
false
google-research/bert
https://github.com/google-research/bert/blob/eedf5716ce1268e56f0a50264a88cafad334ac61/tokenization.py
tokenization.py
# coding=utf-8 # Copyright 2018 The Google AI Language Team Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by ...
python
Apache-2.0
eedf5716ce1268e56f0a50264a88cafad334ac61
2026-01-04T14:40:51.596425Z
false
google-research/bert
https://github.com/google-research/bert/blob/eedf5716ce1268e56f0a50264a88cafad334ac61/run_squad.py
run_squad.py
# coding=utf-8 # Copyright 2018 The Google AI Language Team Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by ...
python
Apache-2.0
eedf5716ce1268e56f0a50264a88cafad334ac61
2026-01-04T14:40:51.596425Z
true
google-research/bert
https://github.com/google-research/bert/blob/eedf5716ce1268e56f0a50264a88cafad334ac61/optimization.py
optimization.py
# coding=utf-8 # Copyright 2018 The Google AI Language Team Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by ...
python
Apache-2.0
eedf5716ce1268e56f0a50264a88cafad334ac61
2026-01-04T14:40:51.596425Z
false
google-research/bert
https://github.com/google-research/bert/blob/eedf5716ce1268e56f0a50264a88cafad334ac61/modeling_test.py
modeling_test.py
# coding=utf-8 # Copyright 2018 The Google AI Language Team Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by ...
python
Apache-2.0
eedf5716ce1268e56f0a50264a88cafad334ac61
2026-01-04T14:40:51.596425Z
false
google-research/bert
https://github.com/google-research/bert/blob/eedf5716ce1268e56f0a50264a88cafad334ac61/tokenization_test.py
tokenization_test.py
# coding=utf-8 # Copyright 2018 The Google AI Language Team Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by ...
python
Apache-2.0
eedf5716ce1268e56f0a50264a88cafad334ac61
2026-01-04T14:40:51.596425Z
false
google-research/bert
https://github.com/google-research/bert/blob/eedf5716ce1268e56f0a50264a88cafad334ac61/__init__.py
__init__.py
# coding=utf-8 # Copyright 2018 The Google AI Language Team Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by ...
python
Apache-2.0
eedf5716ce1268e56f0a50264a88cafad334ac61
2026-01-04T14:40:51.596425Z
false
google-research/bert
https://github.com/google-research/bert/blob/eedf5716ce1268e56f0a50264a88cafad334ac61/optimization_test.py
optimization_test.py
# coding=utf-8 # Copyright 2018 The Google AI Language Team Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by ...
python
Apache-2.0
eedf5716ce1268e56f0a50264a88cafad334ac61
2026-01-04T14:40:51.596425Z
false
google-research/bert
https://github.com/google-research/bert/blob/eedf5716ce1268e56f0a50264a88cafad334ac61/run_pretraining.py
run_pretraining.py
# coding=utf-8 # Copyright 2018 The Google AI Language Team Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by ...
python
Apache-2.0
eedf5716ce1268e56f0a50264a88cafad334ac61
2026-01-04T14:40:51.596425Z
false
google-research/bert
https://github.com/google-research/bert/blob/eedf5716ce1268e56f0a50264a88cafad334ac61/run_classifier.py
run_classifier.py
# coding=utf-8 # Copyright 2018 The Google AI Language Team Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by ...
python
Apache-2.0
eedf5716ce1268e56f0a50264a88cafad334ac61
2026-01-04T14:40:51.596425Z
true
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/scripts/tok_eval.py
scripts/tok_eval.py
""" Evaluate compression ratio of the tokenizer. """ from nanochat.tokenizer import get_tokenizer, RustBPETokenizer from nanochat.dataset import parquets_iter_batched # Random text I got from a random website this morning news_text = r""" (Washington, D.C., July 9, 2025)- Yesterday, Mexico’s National Service of Agro-...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/scripts/chat_sft.py
scripts/chat_sft.py
""" Finetune a base model to be a chat model. Run on one GPU e.g. for debugging: python -m scripts.chat_sft Or torchrun for training: torchrun --standalone --nproc_per_node=8 -m scripts.chat_sft """ import os os.environ["PYTORCH_ALLOC_CONF"] = "expandable_segments:True" import wandb import torch import torch.distr...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/scripts/mid_train.py
scripts/mid_train.py
""" Midtrain the model. Same as pretraining but simpler. Run as: python -m scripts.mid_train Or torchrun for training: torchrun --standalone --nproc_per_node=8 -m scripts.mid_train -- --device_batch_size=16 """ from collections import deque import os os.environ["PYTORCH_ALLOC_CONF"] = "expandable_segments:True" imp...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/scripts/base_eval.py
scripts/base_eval.py
""" Evaluate the CORE metric for a given model. Run on a single GPU: python -m scripts.base_eval Run with torchrun on e.g. 8 GPUs: torchrun --nproc_per_node=8 -m scripts.base_eval The script will print the CORE metric to the console. """ import os import csv import time import json import yaml import shutil import r...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/scripts/chat_eval.py
scripts/chat_eval.py
""" Evaluate the Chat model. All the generic code lives here, and all the evaluation-specific code lives in nanochat directory and is imported from here. Example runs: python -m scripts.chat_eval -a ARC-Easy torchrun --nproc_per_node=8 -m scripts.chat_eval -- -a ARC-Easy """ import argparse from functools import part...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/scripts/base_train.py
scripts/base_train.py
""" Train model. Run as: python base_train.py or distributed as: torchrun --nproc_per_node=8 base_train.py If you are only on CPU/Macbook, you'll want to train a much much smaller LLM. Example: python -m scripts.base_train --depth=4 --max_seq_len=512 --device_batch_size=1 --eval_tokens=512 --core_metric_every=-1 --...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/scripts/tok_train.py
scripts/tok_train.py
""" Train a tokenizer using our own BPE Tokenizer library. In the style of GPT-4 tokenizer. """ import os import time import argparse import torch from nanochat.tokenizer import RustBPETokenizer from nanochat.common import get_base_dir from nanochat.dataset import parquets_iter_batched # ------------------------------...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/scripts/base_loss.py
scripts/base_loss.py
""" Loads a checkpoint, and: - Evaluates the loss on a larger chunk of train/val splits - Samples from the model Example run as: torchrun --standalone --nproc_per_node=8 -m scripts.base_loss """ import os from contextlib import nullcontext import torch from nanochat.checkpoint_manager import load_model from nanochat.c...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/scripts/chat_cli.py
scripts/chat_cli.py
""" New and upgraded chat mode because a lot of the code has changed since the last one. Intended to be run single GPU only atm: python -m scripts.chat_cli -i mid """ import argparse import torch from nanochat.common import compute_init, autodetect_device_type from contextlib import nullcontext from nanochat.engine im...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/scripts/chat_web.py
scripts/chat_web.py
#!/usr/bin/env python3 """ Unified web chat server - serves both UI and API from a single FastAPI instance. Uses data parallelism to distribute requests across multiple GPUs. Each GPU loads a full copy of the model, and incoming requests are distributed to available workers. Launch examples: - single available GPU (...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/scripts/chat_rl.py
scripts/chat_rl.py
""" Reinforcement learning on GSM8K via "GRPO". I put GRPO in quotes because we actually end up with something a lot simpler and more similar to just REINFORCE: 1) Delete trust region, so there is no KL regularization to a reference model 2) We are on policy, so there's no need for PPO ratio+clip. 3) We use GAPO styl...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/tasks/gsm8k.py
tasks/gsm8k.py
""" GSM8K evaluation. https://huggingface.co/datasets/openai/gsm8k Example problem instance: Question: Weng earns $12 an hour for babysitting. Yesterday, she just did 50 minutes of babysitting. How much did she earn? Answer: Weng earns 12/60 = $<<12/60=0.2>>0.2 per minute. Working 50 minutes, she earned 0.2 x 50 = $<...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/tasks/common.py
tasks/common.py
""" Base class for all Tasks. A Task is basically a dataset of conversations, together with some metadata and often also evaluation criteria. Example tasks: MMLU, ARC-Easy, ARC-Challenge, GSM8K, HumanEval, SmolTalk. """ import random class Task: """ Base class of a Task. Allows for lightweight slicing of the ...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/tasks/smoltalk.py
tasks/smoltalk.py
""" SmolTalk by HuggingFace. Good "general" conversational dataset. https://huggingface.co/datasets/HuggingFaceTB/smol-smoltalk We use the "smol" version, which is more appropriate for smaller models. """ from datasets import load_dataset from tasks.common import Task class SmolTalk(Task): """ smol-smoltalk datas...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/tasks/spellingbee.py
tasks/spellingbee.py
""" Task intended to make nanochat better in spelling and counting, for example: "How many r are in strawberry?" -> 3 An interesting part of this task is that we will get the assistant to solve the problem using a combination of manual counting and Python. This is a good problem solving "instinct" to mix into the mod...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/tasks/arc.py
tasks/arc.py
""" The ARC dataset from Allen AI. https://huggingface.co/datasets/allenai/ai2_arc """ from datasets import load_dataset from tasks.common import Task, render_mc class ARC(Task): def __init__(self, subset, split, **kwargs): super().__init__(**kwargs) assert subset in ["ARC-Easy", "ARC-Challenge"]...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/tasks/mmlu.py
tasks/mmlu.py
""" The MMLU dataset. https://huggingface.co/datasets/cais/mmlu """ from datasets import load_dataset from tasks.common import Task, render_mc class MMLU(Task): letters = ('A', 'B', 'C', 'D') groups = ('abstract_algebra', 'anatomy', 'astronomy', 'business_ethics', 'clinical_knowledge', 'college_biology', 'co...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/tasks/humaneval.py
tasks/humaneval.py
""" Evaluate the Chat model on HumanEval dataset. Btw this dataset is a misnomer and has nothing to do with humans. It is a coding benchmark. """ import re from datasets import load_dataset from nanochat.execution import execute_code from tasks.common import Task def extract_imports(prompt): """Extract import sta...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/tasks/customjson.py
tasks/customjson.py
""" CustomJSON task for loading conversations from JSONL files. Each line in the JSONL file should be a JSON array of messages. """ import os import json from tasks.common import Task class CustomJSON(Task): """ Load conversations from a JSONL file. Each line should be a JSON array of message objects with...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/dev/gen_synthetic_data.py
dev/gen_synthetic_data.py
""" Short and crappy script to demonstrate synthetic data generation for customizing your LLM's identity, or any other aspect really. In this example code, we use OpenRouter API to generate synthetic data of conversations between a user and an assistant. We use "Structured Output" feature to get back JSON data from th...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/dev/repackage_data_reference.py
dev/repackage_data_reference.py
""" Repackage the FinewebEdu-100B dataset into shards: - each shard is ~100MB in size (after zstd compression) - parquets are written with row group size of 1000 - shuffle the dataset This will be uploaded to HuggingFace for hosting. The big deal is that our DataLoader will be able to stream the data and cache it alo...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/tests/test_engine.py
tests/test_engine.py
""" Test Engine class. Example run: python -m pytest tests/test_engine.py -v """ import torch from nanochat.engine import KVCache, Engine from dataclasses import dataclass # ----------------------------------------------------------------------------- # Mock classes for testing Engine without loading a real model ...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/nanochat/configurator.py
nanochat/configurator.py
""" Poor Man's Configurator. Probably a terrible idea. Example usage: $ python train.py config/override_file.py --batch_size=32 this will first run config/override_file.py, then override batch_size to 32 The code in this file will be run as follows from e.g. train.py: >>> exec(open('configurator.py').read()) So it's ...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/nanochat/gpt.py
nanochat/gpt.py
""" GPT model (rewrite, a lot simpler) Notable features: - rotary embeddings (and no positional embeddings) - QK norm - untied weights for token embedding and lm_head - relu^2 activation in MLP - norm after token embedding - no learnable params in rmsnorm - no bias in linear layers - Group-Query Attention (GQA) support...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/nanochat/report.py
nanochat/report.py
""" Utilities for generating training report cards. More messy code than usual, will fix. """ import os import re import shutil import subprocess import socket import datetime import platform import psutil import torch def run_command(cmd): """Run a shell command and return output, or None if it fails.""" try...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/nanochat/common.py
nanochat/common.py
""" Common utilities for nanochat. """ import os import re import logging import urllib.request import torch import torch.distributed as dist from filelock import FileLock class ColoredFormatter(logging.Formatter): """Custom formatter that adds colors to log messages.""" # ANSI color codes COLORS = { ...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/nanochat/muon.py
nanochat/muon.py
""" Muon optimizer from Keller et al. Also a lot of borrowing of ideas from modded-nanogpt. """ import torch from torch import Tensor import torch.distributed as dist @torch.compile def zeropower_via_newtonschulz5(G: Tensor, steps: int) -> Tensor: """ Newton-Schulz iteration to compute the zeroth power / ortho...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/nanochat/adamw.py
nanochat/adamw.py
""" Borrowed from modded-nanogpt. By Keller, @vagrawal, et al. Not a general optimizer! But works for our specific use. """ import torch import torch.distributed as dist from torch import Tensor class DistAdamW(torch.optim.Optimizer): """ Distributed AdamW optimizer. In the style of ZeRO-2, i.e. sharded o...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/nanochat/core_eval.py
nanochat/core_eval.py
""" Functions for evaluating the CORE metric, as described in the DCLM paper. https://arxiv.org/abs/2406.11794 TODOs: - All tasks ~match except for squad. We get 31% reference is 37%. Figure out why. """ import random from jinja2 import Template import torch import torch.distributed as dist # -----------------------...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/nanochat/dataset.py
nanochat/dataset.py
""" The base/pretraining dataset is a set of parquet files. This file contains utilities for: - iterating over the parquet files and yielding documents from it - download the files on demand if they are not on disk For details of how the dataset was prepared, see `repackage_data_reference.py`. """ import os import ar...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/nanochat/loss_eval.py
nanochat/loss_eval.py
""" A number of functions that help with evaluating a base model. """ import math import torch import torch.distributed as dist @torch.no_grad() def evaluate_bpb(model, batches, steps, token_bytes): """ Instead of the naive 'mean loss', this function returns the bits per byte (bpb), which is a tokenization...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/nanochat/__init__.py
nanochat/__init__.py
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/nanochat/dataloader.py
nanochat/dataloader.py
from collections import deque import torch import pyarrow.parquet as pq from nanochat.common import get_dist_info from nanochat.dataset import list_parquet_files from nanochat.tokenizer import get_tokenizer def tokenizing_distributed_data_loader_with_state(B, T, split, tokenizer_threads=4, tokenizer_batch_size=128, ...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/nanochat/execution.py
nanochat/execution.py
""" Sandboxed execution utilities for running Python code that comes out of an LLM. Adapted from OpenAI HumanEval code: https://github.com/openai/human-eval/blob/master/human_eval/execution.py What is covered: - Each execution runs in its own process (can be killed if it hangs or crashes) - Execution is limited by a t...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/nanochat/tokenizer.py
nanochat/tokenizer.py
""" BPE Tokenizer in the style of GPT-4. Two implementations are available: 1) HuggingFace Tokenizer that can do both training and inference but is really confusing 2) Our own RustBPE Tokenizer for training and tiktoken for efficient inference """ import os import copy from functools import lru_cache SPECIAL_TOKENS ...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/nanochat/checkpoint_manager.py
nanochat/checkpoint_manager.py
""" Utilities for saving and loading model/optim/state checkpoints. """ import os import re import glob import json import logging import torch from nanochat.common import get_base_dir from nanochat.gpt import GPT, GPTConfig from nanochat.tokenizer import get_tokenizer from nanochat.common import setup_default_logging...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
karpathy/nanochat
https://github.com/karpathy/nanochat/blob/be56d29b87bc51f60c527062389ccd6a14cd0e89/nanochat/engine.py
nanochat/engine.py
""" Engine for efficient inference of our models. Everything works around token sequences: - The user can send token sequences to the engine - The engine returns the next token Notes: - The engine knows nothing about tokenization, it's purely token id sequences. The whole thing is made as efficient as possible. """ ...
python
MIT
be56d29b87bc51f60c527062389ccd6a14cd0e89
2026-01-04T14:40:52.362983Z
false
9001/copyparty
https://github.com/9001/copyparty/blob/364f74a1bd1020a3d7663c453ac5bf1b1408ff8f/setup.py
setup.py
#!/usr/bin/env python3 # coding: utf-8 from __future__ import print_function import os import sys from shutil import rmtree from setuptools import setup, Command _ = """ this probably still works but is no longer in use; pyproject.toml and scripts/make-pypi-release.sh are in charge of packaging wheels now """ NAME =...
python
MIT
364f74a1bd1020a3d7663c453ac5bf1b1408ff8f
2026-01-04T14:40:51.385338Z
false