jupyter ai 结合local llm 实现思路

参考链接:

jupyter ai develop 开发文档

https://jupyter-ai.readthedocs.io/en/latest/developers/index.html

langchain custom LLM 开发文档

https://python.langchain.com/v0.1/docs/modules/model_io/llms/custom_llm/

stackoverflow :intergrate Local LLM with jupyter ai question

https://stackoverflow.com/questions/78989389/jupyterai-local-llm-integration/78989646#78989646

作者krassowski blog ,关于jupyter lab 有117个post

https://stackoverflow.com/users/6646912/krassowski

====================================

思路

1。Briefly, define the CustomLLM with something like:

python 复制代码
from typing import Any, Dict, Iterator, List, Mapping, Optional

from langchain_core.callbacks.manager import CallbackManagerForLLMRun
from langchain_core.language_models.llms import LLM
from langchain_core.outputs import GenerationChunk


class CustomLLM(LLM):

    def _call(
        self,
        prompt: str,
        stop: Optional[List[str]] = None,
        run_manager: Optional[CallbackManagerForLLMRun] = None,
        **kwargs: Any,
    ) -> str:
        payload = ... # TODO: pass `prompt` to payload here
        # TODO: define `headers`
        response = requests.request(method="POST", url="10.1xx.1xx.50:8084/generate", headers=headers, data=payload)
        return response.text  # TODO: change it accordingly

    @property
    def _llm_type(self) -> str:
        return "custom"

2。 create MyProvider

python 复制代码
# my_package/my_provider.py
from jupyter_ai_magics import BaseProvider


class MyProvider(BaseProvider, CustomLLM):
    id = "my_provider"
    name = "My Provider"
    model_id_key = "model"
    models = [
        "your_model"
    ]
    def __init__(self, **kwargs):
        model_id = kwargs.get("model_id")
        # you can use `model_id` in `CustomLLM` to change models within provider
        super().__init__(**kwargs)

3。define an entrypoint 程序入口,配置pyproject.toml

python 复制代码
# my_package/pyproject.toml
[project]
name = "my_package"
version = "0.0.1"

[project.entry-points."jupyter_ai.model_providers"]
my-provider = "my_provider:MyProvider"

=================================

部署

bash 复制代码
cd mypackage/
pip install -e .
相关推荐
阿坡RPA8 小时前
手搓MCP客户端&服务端:从零到实战极速了解MCP是什么?
人工智能·aigc
用户27784491049938 小时前
借助DeepSeek智能生成测试用例:从提示词到Excel表格的全流程实践
人工智能·python
机器之心8 小时前
刚刚,DeepSeek公布推理时Scaling新论文,R2要来了?
人工智能
算AI10 小时前
人工智能+牙科:临床应用中的几个问题
人工智能·算法
凯子坚持 c11 小时前
基于飞桨框架3.0本地DeepSeek-R1蒸馏版部署实战
人工智能·paddlepaddle
你觉得20511 小时前
哈尔滨工业大学DeepSeek公开课:探索大模型原理、技术与应用从GPT到DeepSeek|附视频与讲义下载方法
大数据·人工智能·python·gpt·学习·机器学习·aigc
8K超高清12 小时前
中国8K摄像机:科技赋能文化传承新图景
大数据·人工智能·科技·物联网·智能硬件
hyshhhh12 小时前
【算法岗面试题】深度学习中如何防止过拟合?
网络·人工智能·深度学习·神经网络·算法·计算机视觉
薛定谔的猫-菜鸟程序员12 小时前
零基础玩转深度神经网络大模型:从Hello World到AI炼金术-详解版(含:Conda 全面使用指南)
人工智能·神经网络·dnn
币之互联万物12 小时前
2025 AI智能数字农业研讨会在苏州启幕,科技助农与数据兴业成焦点
人工智能·科技