前军教程网

中小站长与DIV+CSS网页布局开发技术人员的首选CSS学习平台

Spring Boot集成antlr实现词法和语法分析

1.什么是antlr?

Antlr4 是一款强大的语法生成器工具,可用于读取、处理、执行和翻译结构化的文本或二进制文件。基本上是当前 Java 语言中使用最为广泛的语法生成器工具。Twitter搜索使用ANTLR进行语法分析,每天处理超过20亿次查询;Hadoop生态系统中的Hive、Pig、数据仓库和分析系统所使用的语言都用到了ANTLR;Lex Machina将ANTLR用于分析法律文本;Oracle公司在SQL开发者IDE和迁移工具中使用了ANTLR;NetBeans公司的IDE使用ANTLR来解析C++;Hibernate对象-关系映射框架(ORM)使用ANTLR来处理HQL语言

产品设计师常用网站-(建议收藏)

一、2D、3D模型下载网站(包含机械标准件和电子元器件)

Note-18.Arduino uno 和 cnc shield 使用GRBL

CNC扩展板基本功能和步进驱动

  • CNC扩展板基本功能
    • A轴可以根据需求设定为独立工作模式或者同步XYZ中的一轴。
  • A4988驱动:注意en引脚对应CNC扩展版上的en引脚,否则会烧毁驱动

基于 Gradio 手撸 ollama 模型聊天界面

由于最近在测试各种开源模型性能,在终端测试下载下来的ollama 模型交互较为不方便,搬运工基于Gradio 手撸一个可以启动各种大模型的聊天界面;聊天交互界实现效果如下:

现将实战代码分享如下:

# -*- coding: utf-8 -*-
import gradio as gr
import ollama
from typing import List, Tuple

model_name_dict = {
    "qwen2.5:32b": "qwen2.5:32b",
    "qwen2.5:72b": "qwen2.5:72b",
    "qwen2.5-coder": "qwen2.5-coder:32b",
    "qwq-32b": "qwq:32b-preview-q8_0",
}


# LLMAsServer 模型即服务, 启动聊天界面
class LLMAsServer:
    def __init__(self, model_name: str = model_name_dict["qwen2.5:32b"], is_stream=False):
        self.model_name = model_name
        self.is_stream = is_stream

    def generate(self, text: str):
        stream = ollama.generate(
            stream=self.is_stream,
            model=self.model_name,
            prompt=text,
        )
        response = ""
        if self.is_stream:
            for chunk in stream:
                response += chunk["response"]
        else:
            response = stream["response"]
        return response

    # api_generate 流式输出
    def _api_generate(self, chat_history: List):
        text = chat_history[-1]["content"]
        response = self.generate(text)
        yield chat_history + [{"role": "assistant", "content": response}]

    @staticmethod
    def _handle_user_message(user_message: str, history: list):
        """Handle the user submitted message. Clear message box and append to the history."""
        new_history = history + [{"role": "user", "content": user_message}]
        return '', new_history

    @staticmethod
    def _reset_chat() -> tuple:
        """Reset the agent's chat history. And clear all dialogue boxes."""
        return "", []

    def run(self):
        custom_css = """
            #box {
                height: 500px;
                overflow-y: scroll !important;
            }
            #clear-button {
                background-color: blue !important;
                color: white !important; /* Optional: Set text color to white for better contrast */
                border: none !important; /* Optional: Remove default border */
                border-radius: 2px !important; /* Optional: Add rounded corners */
                height: 150px !important; /* Set the height of the Textbox */
            }
            #message-input {
                width: 100% !important; /* Make the Textbox take up the full available width */
                max-width: calc(100% - 50px) !important; /* Adjust for the ClearButton's width */
                height: 150px !important; /* Increase the height to 50px */
            }
            #submit-button {
                background-color: green !important;
            }
            textarea{
                height: 100px !important; /* Ensure the inner container takes up the full height */
                border-radius: 5px !important; /* Optional: Add rounded corners */
                border-color: red !important; 
                border-style: solid !important; 
            }
            
        """
        demo = gr.Blocks(
            theme=gr.themes.Default(
                primary_hue="red",
                secondary_hue="pink"),
            # css="#box { height: 420px; overflow-y: scroll !important}",
            css=custom_css,
        )
        with demo:
            gr.Markdown(
                "# AI Chat \n"
                "### This Application  is Powered by The LLM Model {} \n".format(self.model_name.upper()),
            )
            chat_window = gr.Chatbot(
                label="Message History",
                scale=5,
                type='messages',
                elem_id="chatbot-container"
            )
            with gr.Row():
                message_input = gr.Textbox(label="Input", placeholder="Type your message here...", scale=5,
                                           elem_id="message-input")
                clear = gr.ClearButton(elem_id="clear-button")
            submit_button = gr.Button("Submit", elem_id="submit-button")

            submit_button.click(
                fn=self._handle_user_message,
                inputs=[message_input, chat_window],
                outputs=[message_input, chat_window]
            ).then(
                fn=self._api_generate,
                inputs=chat_window,
                outputs=chat_window
            )

            message_input.submit(
                self._handle_user_message,
                inputs=[message_input, chat_window],
                outputs=[message_input, chat_window],
            ).then(
                self._api_generate,
                chat_window,
                chat_window,
            )
            clear.click(self._reset_chat, None, [message_input, chat_window])

        demo.launch(show_error=True, share=False, server_port=7861)


if __name__ == "__main__":
    server = LLMAsServer(model_name=model_name_dict["qwen2.5-coder"])
    server.run()

免费办公软件LibreOffice 4.3.3正式版下载

IT之家(www.ithome.com):免费办公软件LibreOffice 4.3.3正式版下载

IT之家10月30日消息,知名文档基金会TDF正式发布旗下免费办公软件LibreOffice 4.3.3正式版,带来多项新特性以及功能改进,推荐老用户升级安装体验。

软件简介:LibreOffice是一套功能强大,面向个人生产的免费开源办公软件,支持Windows、Macintosh以及Linux平台。本次套件为用户提供了6个特色功能的应用程序,用来处理日常的文档处理和数据管理,包括:Writer, Calc, Impress, Draw, Math和Base。该六款特色应用分别可以用来处理文档、电子表格、幻灯片演示、图像处理、数学公式编写以及数据库管理。

不想用Microsoft EXCEL,你有这几个流行备选

不是只有国人才不用正版的Ms Office,笔者最近在浏览英国政府官方网站的时候,发现公开的政府文件使用的并不是Ms word而是开源的Openoffice Writer.

如果你不想用Microsoft Word,那么你可能听说没听说过的如下也是非常流行的

WPS 这个不用说,都很熟悉,不过离生产力还有好大一截

http://www.wps.cn

OpenOffice Calc 开源软件,免费,Linux操作系统的默认选择,不过连英国政府都用,为什么不用

CSS属性值函数(3)clamp()限值函数

函数简介

clamp() 函数的作用是把一个值限制在一个上限和下限之间,当这个值超过最小值和最大值的范围时,在最小值和最大值之间选择一个值使用(低于最小值就用最小值,高于最大值就用最大值,就如卡钳一样)。它接收三个参数:最小值、首选值、最大值,当属性值在最小值与最大值之间时,用首选值(即第二个参数)。

clamp() 允许被用在 <length>、<frequency>、<angle>、<time>、<percentage>、<number>、<integer> 中。

最全从输入URL到浏览器显示页面都发生了什么前端浏览器渲染流程

面试中常被问到的问题,此问题包含web开发中从前端到后端到运维的绝大多数知识,主要考察面试者知识的广度。本文会根据作者了解的程度增加不断更新,不足之处欢迎评论区补充。

Vue3框架搭建

目录

  • 二十一、项目搭建规范1、创建项目2、代码规范a、.editorconfig(编辑器编辑风格)b、prettier(代码格式化风格)c、eslint(代码风格检测工具)d、git Husky(提交前代码格式化风格)e、commitizen(提交信息格式化风格)f、commitlint(提交信息风格检测工具)3、项目结构a、vue.config.jsb、vue-routerc、vuexd、element-pluse、axiosf、环境变量g、tsconfig.jsonh、shims-vue.d.ts

Cursor体验——口算题卡轻松生成

最近家里小朋友的口算题卡做完了,本想着再买一些,可转念一想,让Cursor帮我写一个不是更有乐趣吗?

说干就干,需求也不复杂,也不用漂亮的界面,能出题就行,那就用html+js实现吧。

打开cursor,随便选个目录,ctrl+i呼出composer,告诉它“生成一个calc.html,用js生成100以内,两个数字的加减乘除算式生成,每行生成三个算式,共200行,尽量随机,不要重复”

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言