Category: hive
mggg's 博客
GPT的架构 - 从0构建LLM (1)
GPT的架构 GPT模型是一种计算机程序,它可以理解和生成文字,就像我们人类会说话和写字一样。
模型的工作流程 输入文本: 首先,我们把要处理的文字(比如一句话或一段话)输入到模型中。
词嵌入层: 模型会把这些文字转换成一种计算机能理解的数字形式,这叫“词嵌入”。这就好像我们用字母拼出一个单词一样,计算机用数字来表示这些文字。
位置嵌入层: 模型还会考虑每个单词在句子中的位置,因为同样的单词在不同的位置可能有不同的意思。
多个转换器模块:
这些模块负责处理和理解输入的文字。每个模块都有几个重要部分: 注意力机制(Masked Multi-head Attention): 这部分就像我们阅读一篇文章时,会特别注意一些关键字一样。模型会关注输入文字中的重要部分。 前馈神经网络(Feed Forward): 这部分就像一个过滤器,会进一步处理信息,使其变得更有用。 规范化层(LayerNorm): 这部分会确保信息在处理过程中保持稳定,不会变得太乱。 丢弃层(Dropout): 这部分会随机丢弃一些信息,防止模型过于依赖某些特定的信息,使其更具通用性。 输出层: 最后,处理完所有信息后,模型会给出一个结果,比如生成下一段文字。
示例 假设我们输入一句话:“今天的天气真好。”
输入文本: “今天的天气真好。” 词嵌入层: 把这句话转换成数字。 位置嵌入层: 记录每个词在句子中的位置。 多个转换器模块: 模型会处理这句话,注意到“天气”和“好”是关键字,并对信息进行多次处理。 输出层: 最后模型可能会生成下一句话,比如“我们去公园玩吧。” 大模型评测 MMLU=Measuring Massive Multitask language Understanding,
以下是一个示例
input = ("1 + 1=?", "A. 2", "B. 3", "C. 4") model_answer = model(input) correct_answer = "C.4" score += model_answer == correct_answer total_score = score / num_examples * 100 %
mggg's 博客
Apache Hive实现自定义存储格式
Apache Hive实现自定义存储格式 背景 在某些业务场景中,下游处理系统需要直接处理数据文件。虽然Hive官方支持text, orc, parquet等格式,但为了应对更多样化的业务场景,学习如何开发自定义存储格式变得十分重要。Hive目前提供了ROW FORMAT SERDE机制来实现这一需求。
ROW FORMAT SERDE Hive的ROW FORMAT SERDE是一个关键的数据格式化概念,它定义了如何解析和映射存储在Hive表中的数据。SERDE代表序列化和反序列化,这涉及到数据在写入Hive表时和从Hive表读取时的转换过程。
快速开始 考虑一种业务场景,我们希望数据本身没有列分隔符,而是采用固定宽度的字段。在Hive中,设置列分隔符为空字符串是不被直接支持的。为了解决这个问题,接下来将实现一个自定义的SerDe。
首先从结果出发:
代码打包后的jar名称为 hive-fixed-serde-1.0-SNAPSHOT.jar
添加自定义serde jar包
add jar hdfs:///path/hive-fixed-serde-1.0-SNAPSHOT.jar 建表指定实现类org.apache.hadoop.hive.serde2.fixed.FixedLengthTextSerDe, 且每个字段定长分别为10, 5, 8 CREATE TABLE fixed_length_table ( column1 STRING, column2 STRING, column3 STRING ) ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.fixed.FixedLengthTextSerDe' WITH SERDEPROPERTIES ( "field.lengths"="10,5,8" ) STORED AS TEXTFILE; 当写入数据不满足定长时候, 向后补充空格, 写入 insert into fixed_length_table values ("1", "1", "1") 实际文件内容:
1 1 1 实现 FixedLengthTextSerDe 继承自org.apache.hadoop.hive.serde2.AbstractSerDe,需要实现以下方法:
initialize: 创建建表语句中field.lengths的配置。 getSerDeStats: 返回统计信息。 deserialize: 将文件内容里的数据转换为Hive的ROW。 serialize: 将Hive的ROW转换为实际写文件的内容。本次目的是将数据补位,按空格补充到规定要求的定长。 getSerializedClass: 仅针对text格式。 完整代码:
mggg's Blog
Implementing Custom Storage Formats in Apache Hive
Implementing Custom Storage Formats in Apache Hive Background In certain business scenarios, downstream processing systems need to handle data files directly. Although Hive officially supports formats like text, orc, parquet, etc., learning how to develop custom storage formats is crucial for addressing a more diverse range of business scenarios. Hive currently offers the ROW FORMAT SERDE mechanism for this purpose.
ROW FORMAT SERDE The ROW FORMAT SERDE in Hive is a key data formatting concept, defining how to parse and map data stored in Hive tables.
Category: llm
mggg's 博客
GPT的架构 - 从0构建LLM (1)
GPT的架构 GPT模型是一种计算机程序,它可以理解和生成文字,就像我们人类会说话和写字一样。
模型的工作流程 输入文本: 首先,我们把要处理的文字(比如一句话或一段话)输入到模型中。
词嵌入层: 模型会把这些文字转换成一种计算机能理解的数字形式,这叫“词嵌入”。这就好像我们用字母拼出一个单词一样,计算机用数字来表示这些文字。
位置嵌入层: 模型还会考虑每个单词在句子中的位置,因为同样的单词在不同的位置可能有不同的意思。
多个转换器模块:
这些模块负责处理和理解输入的文字。每个模块都有几个重要部分: 注意力机制(Masked Multi-head Attention): 这部分就像我们阅读一篇文章时,会特别注意一些关键字一样。模型会关注输入文字中的重要部分。 前馈神经网络(Feed Forward): 这部分就像一个过滤器,会进一步处理信息,使其变得更有用。 规范化层(LayerNorm): 这部分会确保信息在处理过程中保持稳定,不会变得太乱。 丢弃层(Dropout): 这部分会随机丢弃一些信息,防止模型过于依赖某些特定的信息,使其更具通用性。 输出层: 最后,处理完所有信息后,模型会给出一个结果,比如生成下一段文字。
示例 假设我们输入一句话:“今天的天气真好。”
输入文本: “今天的天气真好。” 词嵌入层: 把这句话转换成数字。 位置嵌入层: 记录每个词在句子中的位置。 多个转换器模块: 模型会处理这句话,注意到“天气”和“好”是关键字,并对信息进行多次处理。 输出层: 最后模型可能会生成下一句话,比如“我们去公园玩吧。” 大模型评测 MMLU=Measuring Massive Multitask language Understanding,
以下是一个示例
input = ("1 + 1=?", "A. 2", "B. 3", "C. 4") model_answer = model(input) correct_answer = "C.4" score += model_answer == correct_answer total_score = score / num_examples * 100 %
Category: ai
mggg's Blog
Exploring Langchain Streaming LLM with OpenAI's Streaming Features
Streamlining AI Interactions with Langchain Streaming LLM and OpenAI Discover the transformative power of Langchain Streaming LLM combined with OpenAI’s streaming services. This synergy enhances real-time processing capabilities for language models, revolutionizing user experiences and expanding AI’s potential in data handling and responsive communication.
Advancing AI Communication with Langchain’s Streaming and Callback Mechanisms At the core of Langchain’s streaming prowess are its constructor callbacks, which ensure smooth integration with OpenAI’s API.
mggg's Blog
How to Build a Zero-Cost AI Application Using Cloudflare
How to Build a Zero-Cost AI Application: A Step-by-Step Guide Using Cloudflare Harness the power of Cloudflare’s free tier to construct AI applications without incurring costs. This guide delineates the process of employing JavaScript along with Cloudflare’s suite of services—including AI inference engines and Cloudflare Workers—to craft a robust, serverless AI application.
Step-by-Step Configuration for AI Deployment on Cloudflare Step 1: Initiate with Cloudflare Account Configuration Kickstart your journey by setting up your Cloudflare account.
mggg's 博客
使用Cloudflare构建0成本的AI应用
构建0成本的AI应用:利用Cloudflare的强大功能 在当前的技术环境中,利用Cloudflare的免费套餐(Free Plan)可以轻松构建零成本的AI应用。仅通过使用JavaScript和Cloudflare的几个关键服务——Cloudflare AI, Cloudflare Worker, 和 Cloudflare Page——来实现这一目标。其中,Cloudflare Worker充当后端服务,而Cloudflare Page则扮演前端的角色。
初步准备 要开始这个项目,首先需要:
注册并开通Cloudflare账户。 从域名dashboard页面获取必要的认证信息,包括Account ID , 和API Token Cloudflare AI Cloudflare AI目前免费支持多种模型
@cf/baai/bge-base-en-v1.5 @cf/baai/bge-large-en-v1.5 @cf/baai/bge-small-en-v1.5 @cf/huggingface/distilbert-sst-2-int8 @cf/meta/llama-2-7b-chat-fp16 @cf/meta/llama-2-7b-chat-int8 @cf/meta/m2m100-1.2b @cf/microsoft/resnet-50 @cf/mistral/mistral-7b-instruct-v0.1 @cf/openai/whisper @cf/stabilityai/stable-diffusion-xl-base-1.0 可以通过以下命令行示例,结合前面获取的ACCOUNT_ID和API_TOKEN,快速测试这些模型:
curl -X POST \ https://api.cloudflare.com/client/v4/accounts/${ACCOUNT_ID}/ai/run/@cf/meta/llama-2-7b-chat-int8 \ -H "Authorization: Bearer {API_TOKEN}" \ -d '{"messages":[{"role":"system","content":"You are a friendly assistant that helps write stories"},{"role":"user","content":"Write a short story about a llama that goes on a journey to find an orange cloud"}]}' Cloudflare Worker: 处理CORS 由于在使用Cloudflare Page时可能会遇到跨源资源共享(CORS)问题,因此可以通过Cloudflare Worker构建服务来解决这个问题,而不是直接调用Cloudflare AI的API。以下是一个基本的Cloudflare Worker脚本,用于处理CORS和转发AI模型请求:
mggg's Blog
Harnessing the Power of OpenAI's Latest Innovations
Introduction: Embracing the Future with OpenAI’s Updates In the ever-evolving landscape of artificial intelligence, staying updated with the latest advancements is not just a matter of curiosity, but a necessity for those looking to leverage AI for their projects. On the 11th of June, 2023, OpenAI introduced a slew of new features, marking a significant update to their Python SDK, now at version 1.0.0. In this blog, we’ll dive into these updates and explore how they can revolutionize the way we interact with AI.
mggg's 博客
OpenAI 11.06更新
OpenAI 11.06更新 在这篇博客中,将讨论 OpenAI 11.06 的一些更新,更新主要有:
聊天内容支持图片, gpt-4-vision-preview 返回内容支持json模式 引入system_fingerprint, 支持可复现性 OpenAI 多模态模型 OpenAI 引入的最令人兴奋的新功能之一是多模态模型,它可以处理文本和图像的组合。这一能力为 AI 应用打开了一个新的维度,从增强的视觉数据分析到更互动的聊天机器人。
GPT-4 Vision: gpt-4-vision-preview 示例: 分析阿里巴巴股票的K线.
import openai openai.api_key = "your-api-key" response = openai.ChatCompletion.create( model="gpt-4-vision-preview", messages=[ { "role": "user", "content": [ {"type": "text", "text": "What information can you understand from the K-line of the image?"}, { "type": "image_url", "image_url": "https://mggg.cloud/img/ali.png", }, ], } ], max_tokens=300, ) print(response.choices[0].message.content) output:
The image appears to show a candlestick chart for a stock, specifically ticker 'BABA' which is Alibaba Group Holding Limited.
mggg's Blog
Vector Database: Weaviate
Vector Database: Weaviate Weaviate is an innovative vector database known for its efficiency in storing and retrieving data. Utilizing vectors, Weaviate indexes data objects based on their semantic properties, offering a unique approach to data handling. It supports a variety of modules, including text2vec and OpenAI embeddings, providing flexibility in data vectorization.
Getting Started with Weaviate Deploying Weaviate is straightforward with docker-compose. The OpenAI module transforms text into embeddings, enhancing semantic search capabilities.
Category: chatgpt
mggg's Blog
Exploring Langchain Streaming LLM with OpenAI's Streaming Features
Streamlining AI Interactions with Langchain Streaming LLM and OpenAI Discover the transformative power of Langchain Streaming LLM combined with OpenAI’s streaming services. This synergy enhances real-time processing capabilities for language models, revolutionizing user experiences and expanding AI’s potential in data handling and responsive communication.
Advancing AI Communication with Langchain’s Streaming and Callback Mechanisms At the core of Langchain’s streaming prowess are its constructor callbacks, which ensure smooth integration with OpenAI’s API.
mggg's Blog
SafeAssign and ChatGPT: Navigating the Landscape of Academic Integrity
SafeAssign and ChatGPT: Navigating the Landscape of Academic Integrity Introduction In the rapidly evolving world of academic writing and artificial intelligence, the intersection of plagiarism detection tools like SafeAssign and AI language models such as ChatGPT presents both challenges and opportunities. This article explores whether SafeAssign can detect ChatGPT-generated content, the limitations of plagiarism tools in the face of advanced AI, and how academic integrity can be upheld in this new landscape.
mggg's Blog
Solving Custom GPT Bug: Making Hyperlinks Clickable
Making Hyperlinks Clickable in GPT-Generated Content Ensuring that hyperlinks are clickable in content generated by Custom GPTs is essential for maintaining user engagement and optimizing for search engines. This guide will address common issues like links not being clickable, hyperlinks not working in Chrome, and making image hyperlinks interactive.
Understanding the Issue of Non-Clickable Links Non-clickable links in GPT-generated content can be frustrating. This can be a simple oversight, such as a missing HTML tag, or a more complex issue, such as a system bug termed “not just a bug.
mggg's 博客
给GPTs添加带货功能
给GPTs添加带货功能 最近实现了一个根据用户心境,来推荐相应书籍的GPTs: Random Book Generator
如果用户对这本书感兴趣,想了解更多的话, 这个GPTs就可以进行详情推荐,向用户推荐这本书可以在哪里购买, 如下图所示
实现 如果推荐不是很多,一句prompt就可以搞定, 在GPTs builder里面输入: 以下是推荐«反脆弱» 和«10x is easier than 2x»两本书示例:
You are a GPT that recommends books. Please try to satisfy users' inquiries as much as possible, attract them to read, and recommend these books at the end of your response along with the links. - Antifragile: https://booki.chat/?book=Antifragile - 10x is easier than 2x: https://booki.chat/?book=10x is easier than 2x 如果推荐很多的话, 可以使用一张csv来维护
Book Name description url … … .
mggg's Blog
Harnessing the Power of OpenAI's Latest Innovations
Introduction: Embracing the Future with OpenAI’s Updates In the ever-evolving landscape of artificial intelligence, staying updated with the latest advancements is not just a matter of curiosity, but a necessity for those looking to leverage AI for their projects. On the 11th of June, 2023, OpenAI introduced a slew of new features, marking a significant update to their Python SDK, now at version 1.0.0. In this blog, we’ll dive into these updates and explore how they can revolutionize the way we interact with AI.
mggg's 博客
OpenAI 11.06更新
OpenAI 11.06更新 在这篇博客中,将讨论 OpenAI 11.06 的一些更新,更新主要有:
聊天内容支持图片, gpt-4-vision-preview 返回内容支持json模式 引入system_fingerprint, 支持可复现性 OpenAI 多模态模型 OpenAI 引入的最令人兴奋的新功能之一是多模态模型,它可以处理文本和图像的组合。这一能力为 AI 应用打开了一个新的维度,从增强的视觉数据分析到更互动的聊天机器人。
GPT-4 Vision: gpt-4-vision-preview 示例: 分析阿里巴巴股票的K线.
import openai openai.api_key = "your-api-key" response = openai.ChatCompletion.create( model="gpt-4-vision-preview", messages=[ { "role": "user", "content": [ {"type": "text", "text": "What information can you understand from the K-line of the image?"}, { "type": "image_url", "image_url": "https://mggg.cloud/img/ali.png", }, ], } ], max_tokens=300, ) print(response.choices[0].message.content) output:
The image appears to show a candlestick chart for a stock, specifically ticker 'BABA' which is Alibaba Group Holding Limited.
mggg's 博客
Langchain LLM Streaming
Langchain LLM Streaming langchain通过callback机制,可以将LLM输出的token实时处理
from langchain.chat_models import ChatOpenAI from langchain.schema import ( HumanMessage, ) from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler chat = ChatOpenAI(streaming=True, callbacks=[StreamingStdOutCallbackHandler()], temperature=0) resp = chat([HumanMessage(content="Write me a song about sparkling water.")]) langchian同时支持同步IO和异步IO的方式来输出token,分别对应StreamingStdOutCallbackHandler 和AsyncIteratorCallbackHandler
StreamingStdOutCallbackHandler 首先可以看看Langchain官方实现StreamingStdOutCallbackHandler, 将LLM输出的token实时打印在终端, 主要实现了on_llm_new_token
class StreamingStdOutCallbackHandler(BaseCallbackHandler): ... def on_llm_new_token(self, token: str, **kwargs: Any) -> None: """Run on new LLM token. Only available when streaming is enabled.""" sys.stdout.write(token) sys.stdout.flush() 但这种方式是同步的,接下来看看异步IO的方式
AsyncIteratorCallbackHandler 以下是使用AsyncIteratorCallbackHandler, 异步打印返回的token
import asyncio from langchain.callbacks import AsyncIteratorCallbackHandler from langchain.
mggg's Blog
Integrating Real-Time Domain Knowledge into LLM with LangChain Chroma Vector Database
Enhancing LLM Responsiveness with LangChain Chroma Vector Database Training data is up until September 2021. Therefore, I may not have information on events or updates that occurred after that time. If you have any questions regarding post-September 2021 topics, I might not be able to provide the latest information. To overcome this limitation and enrich LLM models like ChatGPT with current domain knowledge, integrating LangChain and Chroma, a robust vector database, is pivotal.
mggg's 博客
利用LangChain向量数据库加强LLM实时领域知识
利用LangChain向量数据库提升LLM的即时知识处理能力 当我们使用ChatGPT,它常常提示我们其知识只更新到了2021年9月。因此,为了使LLM模型能够处理最新的信息,将实时的知识集成到模型中变得至关重要。
截止到2021年9月的训练数据。 因此,我不具备在那个时间点之后发生的事件或获取的信息。 如果你有关于2021年9月之后的问题,我可能就无法提供最新的信息。 实现步骤 1. 建立本地向量数据库 我们首先需要在本地创建一个Chroma向量数据库,并将文档信息嵌入其中。
2. 查询与用户提示相关的知识 接着,基于用户的提示,我们查询向量数据库,从中检索出相关领域的知识。
3. 将领域知识集成到用户提示中 最后,我们将这些领域知识整合到用户的提示中,以供LLM模型使用。
LangChain + Chroma的应用 下面是LangChain和Chroma的一个示例应用。我们通过add_text_embedding将文本解析为向量,并通过query查询领域知识。
from langchain.embeddings import OpenAIEmbeddings from langchain.text_splitter import CharacterTextSplitter from langchain.vectorstores import Chroma class EmbeddingLocalBackend(object): def __init__(self, path='db'): self.path = path self.vectordb = Chroma(persist_directory=self.path, embedding_function=OpenAIEmbeddings(max_retries=9999999999)) def add_text_embedding(self, data, auto_commit=True): text_splitter = CharacterTextSplitter( separator="\n", chunk_size=1000, chunk_overlap=200, length_function=len, is_separator_regex=False, ) documents = text_splitter.create_documents(data) self.vectordb.add_documents(documents) if auto_commit: self._commit() def _commit(self): self.vectordb.persist() def query(self, query): embedding_vector = OpenAIEmbeddings().
Category: langchain
mggg's Blog
Exploring Langchain Streaming LLM with OpenAI's Streaming Features
Streamlining AI Interactions with Langchain Streaming LLM and OpenAI Discover the transformative power of Langchain Streaming LLM combined with OpenAI’s streaming services. This synergy enhances real-time processing capabilities for language models, revolutionizing user experiences and expanding AI’s potential in data handling and responsive communication.
Advancing AI Communication with Langchain’s Streaming and Callback Mechanisms At the core of Langchain’s streaming prowess are its constructor callbacks, which ensure smooth integration with OpenAI’s API.
mggg's 博客
Langchain LLM Streaming
Langchain LLM Streaming langchain通过callback机制,可以将LLM输出的token实时处理
from langchain.chat_models import ChatOpenAI from langchain.schema import ( HumanMessage, ) from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler chat = ChatOpenAI(streaming=True, callbacks=[StreamingStdOutCallbackHandler()], temperature=0) resp = chat([HumanMessage(content="Write me a song about sparkling water.")]) langchian同时支持同步IO和异步IO的方式来输出token,分别对应StreamingStdOutCallbackHandler 和AsyncIteratorCallbackHandler
StreamingStdOutCallbackHandler 首先可以看看Langchain官方实现StreamingStdOutCallbackHandler, 将LLM输出的token实时打印在终端, 主要实现了on_llm_new_token
class StreamingStdOutCallbackHandler(BaseCallbackHandler): ... def on_llm_new_token(self, token: str, **kwargs: Any) -> None: """Run on new LLM token. Only available when streaming is enabled.""" sys.stdout.write(token) sys.stdout.flush() 但这种方式是同步的,接下来看看异步IO的方式
AsyncIteratorCallbackHandler 以下是使用AsyncIteratorCallbackHandler, 异步打印返回的token
import asyncio from langchain.callbacks import AsyncIteratorCallbackHandler from langchain.
mggg's Blog
Integrating Real-Time Domain Knowledge into LLM with LangChain Chroma Vector Database
Enhancing LLM Responsiveness with LangChain Chroma Vector Database Training data is up until September 2021. Therefore, I may not have information on events or updates that occurred after that time. If you have any questions regarding post-September 2021 topics, I might not be able to provide the latest information. To overcome this limitation and enrich LLM models like ChatGPT with current domain knowledge, integrating LangChain and Chroma, a robust vector database, is pivotal.
mggg's 博客
利用LangChain向量数据库加强LLM实时领域知识
利用LangChain向量数据库提升LLM的即时知识处理能力 当我们使用ChatGPT,它常常提示我们其知识只更新到了2021年9月。因此,为了使LLM模型能够处理最新的信息,将实时的知识集成到模型中变得至关重要。
截止到2021年9月的训练数据。 因此,我不具备在那个时间点之后发生的事件或获取的信息。 如果你有关于2021年9月之后的问题,我可能就无法提供最新的信息。 实现步骤 1. 建立本地向量数据库 我们首先需要在本地创建一个Chroma向量数据库,并将文档信息嵌入其中。
2. 查询与用户提示相关的知识 接着,基于用户的提示,我们查询向量数据库,从中检索出相关领域的知识。
3. 将领域知识集成到用户提示中 最后,我们将这些领域知识整合到用户的提示中,以供LLM模型使用。
LangChain + Chroma的应用 下面是LangChain和Chroma的一个示例应用。我们通过add_text_embedding将文本解析为向量,并通过query查询领域知识。
from langchain.embeddings import OpenAIEmbeddings from langchain.text_splitter import CharacterTextSplitter from langchain.vectorstores import Chroma class EmbeddingLocalBackend(object): def __init__(self, path='db'): self.path = path self.vectordb = Chroma(persist_directory=self.path, embedding_function=OpenAIEmbeddings(max_retries=9999999999)) def add_text_embedding(self, data, auto_commit=True): text_splitter = CharacterTextSplitter( separator="\n", chunk_size=1000, chunk_overlap=200, length_function=len, is_separator_regex=False, ) documents = text_splitter.create_documents(data) self.vectordb.add_documents(documents) if auto_commit: self._commit() def _commit(self): self.vectordb.persist() def query(self, query): embedding_vector = OpenAIEmbeddings().
Category: OpenAI Streaming
mggg's Blog
Exploring Langchain Streaming LLM with OpenAI's Streaming Features
Streamlining AI Interactions with Langchain Streaming LLM and OpenAI Discover the transformative power of Langchain Streaming LLM combined with OpenAI’s streaming services. This synergy enhances real-time processing capabilities for language models, revolutionizing user experiences and expanding AI’s potential in data handling and responsive communication.
Advancing AI Communication with Langchain’s Streaming and Callback Mechanisms At the core of Langchain’s streaming prowess are its constructor callbacks, which ensure smooth integration with OpenAI’s API.
Category: AI Development
mggg's Blog
Guide to Using Grok-1 for AI Projects: Features, Setup, and Pricing
Guide to Using Grok-1 for AI Projects: Features, Setup, and Pricing Grok-1 is a cutting-edge AI model by XAI Organization, known for its exceptional capabilities in AI development. This guide covers the essentials of Grok-1, including features, how to use it, and pricing, providing valuable insights for both new and experienced developers.
Understanding Grok-1 Grok-1 stands out with its 314 billion parameters and a Mixture of Experts (MoE) architecture. It excels in efficiency and accuracy across various AI tasks, thanks to its innovative features such as 64 layers, Rotary embeddings (RoPE), and more.
Category: Technology
mggg's Blog
Guide to Using Grok-1 for AI Projects: Features, Setup, and Pricing
Guide to Using Grok-1 for AI Projects: Features, Setup, and Pricing Grok-1 is a cutting-edge AI model by XAI Organization, known for its exceptional capabilities in AI development. This guide covers the essentials of Grok-1, including features, how to use it, and pricing, providing valuable insights for both new and experienced developers.
Understanding Grok-1 Grok-1 stands out with its 314 billion parameters and a Mixture of Experts (MoE) architecture. It excels in efficiency and accuracy across various AI tasks, thanks to its innovative features such as 64 layers, Rotary embeddings (RoPE), and more.
Category: Academic Integrity
mggg's Blog
SafeAssign and ChatGPT: Navigating the Landscape of Academic Integrity
SafeAssign and ChatGPT: Navigating the Landscape of Academic Integrity Introduction In the rapidly evolving world of academic writing and artificial intelligence, the intersection of plagiarism detection tools like SafeAssign and AI language models such as ChatGPT presents both challenges and opportunities. This article explores whether SafeAssign can detect ChatGPT-generated content, the limitations of plagiarism tools in the face of advanced AI, and how academic integrity can be upheld in this new landscape.
Category: GPTs
mggg's Blog
Solving Custom GPT Bug: Making Hyperlinks Clickable
Making Hyperlinks Clickable in GPT-Generated Content Ensuring that hyperlinks are clickable in content generated by Custom GPTs is essential for maintaining user engagement and optimizing for search engines. This guide will address common issues like links not being clickable, hyperlinks not working in Chrome, and making image hyperlinks interactive.
Understanding the Issue of Non-Clickable Links Non-clickable links in GPT-generated content can be frustrating. This can be a simple oversight, such as a missing HTML tag, or a more complex issue, such as a system bug termed “not just a bug.
mggg's 博客
给GPTs添加带货功能
给GPTs添加带货功能 最近实现了一个根据用户心境,来推荐相应书籍的GPTs: Random Book Generator
如果用户对这本书感兴趣,想了解更多的话, 这个GPTs就可以进行详情推荐,向用户推荐这本书可以在哪里购买, 如下图所示
实现 如果推荐不是很多,一句prompt就可以搞定, 在GPTs builder里面输入: 以下是推荐«反脆弱» 和«10x is easier than 2x»两本书示例:
You are a GPT that recommends books. Please try to satisfy users' inquiries as much as possible, attract them to read, and recommend these books at the end of your response along with the links. - Antifragile: https://booki.chat/?book=Antifragile - 10x is easier than 2x: https://booki.chat/?book=10x is easier than 2x 如果推荐很多的话, 可以使用一张csv来维护
Book Name description url … … .
Category: Technical Solutions
mggg's Blog
Solving Custom GPT Bug: Making Hyperlinks Clickable
Making Hyperlinks Clickable in GPT-Generated Content Ensuring that hyperlinks are clickable in content generated by Custom GPTs is essential for maintaining user engagement and optimizing for search engines. This guide will address common issues like links not being clickable, hyperlinks not working in Chrome, and making image hyperlinks interactive.
Understanding the Issue of Non-Clickable Links Non-clickable links in GPT-generated content can be frustrating. This can be a simple oversight, such as a missing HTML tag, or a more complex issue, such as a system bug termed “not just a bug.
Category: cloud-computing
mggg's Blog
How to Build a Zero-Cost AI Application Using Cloudflare
How to Build a Zero-Cost AI Application: A Step-by-Step Guide Using Cloudflare Harness the power of Cloudflare’s free tier to construct AI applications without incurring costs. This guide delineates the process of employing JavaScript along with Cloudflare’s suite of services—including AI inference engines and Cloudflare Workers—to craft a robust, serverless AI application.
Step-by-Step Configuration for AI Deployment on Cloudflare Step 1: Initiate with Cloudflare Account Configuration Kickstart your journey by setting up your Cloudflare account.
mggg's 博客
使用Cloudflare构建0成本的AI应用
构建0成本的AI应用:利用Cloudflare的强大功能 在当前的技术环境中,利用Cloudflare的免费套餐(Free Plan)可以轻松构建零成本的AI应用。仅通过使用JavaScript和Cloudflare的几个关键服务——Cloudflare AI, Cloudflare Worker, 和 Cloudflare Page——来实现这一目标。其中,Cloudflare Worker充当后端服务,而Cloudflare Page则扮演前端的角色。
初步准备 要开始这个项目,首先需要:
注册并开通Cloudflare账户。 从域名dashboard页面获取必要的认证信息,包括Account ID , 和API Token Cloudflare AI Cloudflare AI目前免费支持多种模型
@cf/baai/bge-base-en-v1.5 @cf/baai/bge-large-en-v1.5 @cf/baai/bge-small-en-v1.5 @cf/huggingface/distilbert-sst-2-int8 @cf/meta/llama-2-7b-chat-fp16 @cf/meta/llama-2-7b-chat-int8 @cf/meta/m2m100-1.2b @cf/microsoft/resnet-50 @cf/mistral/mistral-7b-instruct-v0.1 @cf/openai/whisper @cf/stabilityai/stable-diffusion-xl-base-1.0 可以通过以下命令行示例,结合前面获取的ACCOUNT_ID和API_TOKEN,快速测试这些模型:
curl -X POST \ https://api.cloudflare.com/client/v4/accounts/${ACCOUNT_ID}/ai/run/@cf/meta/llama-2-7b-chat-int8 \ -H "Authorization: Bearer {API_TOKEN}" \ -d '{"messages":[{"role":"system","content":"You are a friendly assistant that helps write stories"},{"role":"user","content":"Write a short story about a llama that goes on a journey to find an orange cloud"}]}' Cloudflare Worker: 处理CORS 由于在使用Cloudflare Page时可能会遇到跨源资源共享(CORS)问题,因此可以通过Cloudflare Worker构建服务来解决这个问题,而不是直接调用Cloudflare AI的API。以下是一个基本的Cloudflare Worker脚本,用于处理CORS和转发AI模型请求:
Category: bigdata
mggg's 博客
Apache Hive实现自定义存储格式
Apache Hive实现自定义存储格式 背景 在某些业务场景中,下游处理系统需要直接处理数据文件。虽然Hive官方支持text, orc, parquet等格式,但为了应对更多样化的业务场景,学习如何开发自定义存储格式变得十分重要。Hive目前提供了ROW FORMAT SERDE机制来实现这一需求。
ROW FORMAT SERDE Hive的ROW FORMAT SERDE是一个关键的数据格式化概念,它定义了如何解析和映射存储在Hive表中的数据。SERDE代表序列化和反序列化,这涉及到数据在写入Hive表时和从Hive表读取时的转换过程。
快速开始 考虑一种业务场景,我们希望数据本身没有列分隔符,而是采用固定宽度的字段。在Hive中,设置列分隔符为空字符串是不被直接支持的。为了解决这个问题,接下来将实现一个自定义的SerDe。
首先从结果出发:
代码打包后的jar名称为 hive-fixed-serde-1.0-SNAPSHOT.jar
添加自定义serde jar包
add jar hdfs:///path/hive-fixed-serde-1.0-SNAPSHOT.jar 建表指定实现类org.apache.hadoop.hive.serde2.fixed.FixedLengthTextSerDe, 且每个字段定长分别为10, 5, 8 CREATE TABLE fixed_length_table ( column1 STRING, column2 STRING, column3 STRING ) ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.fixed.FixedLengthTextSerDe' WITH SERDEPROPERTIES ( "field.lengths"="10,5,8" ) STORED AS TEXTFILE; 当写入数据不满足定长时候, 向后补充空格, 写入 insert into fixed_length_table values ("1", "1", "1") 实际文件内容:
1 1 1 实现 FixedLengthTextSerDe 继承自org.apache.hadoop.hive.serde2.AbstractSerDe,需要实现以下方法:
initialize: 创建建表语句中field.lengths的配置。 getSerDeStats: 返回统计信息。 deserialize: 将文件内容里的数据转换为Hive的ROW。 serialize: 将Hive的ROW转换为实际写文件的内容。本次目的是将数据补位,按空格补充到规定要求的定长。 getSerializedClass: 仅针对text格式。 完整代码:
mggg's Blog
Implementing Custom Storage Formats in Apache Hive
Implementing Custom Storage Formats in Apache Hive Background In certain business scenarios, downstream processing systems need to handle data files directly. Although Hive officially supports formats like text, orc, parquet, etc., learning how to develop custom storage formats is crucial for addressing a more diverse range of business scenarios. Hive currently offers the ROW FORMAT SERDE mechanism for this purpose.
ROW FORMAT SERDE The ROW FORMAT SERDE in Hive is a key data formatting concept, defining how to parse and map data stored in Hive tables.
Category: OpenAI
mggg's Blog
Harnessing the Power of OpenAI's Latest Innovations
Introduction: Embracing the Future with OpenAI’s Updates In the ever-evolving landscape of artificial intelligence, staying updated with the latest advancements is not just a matter of curiosity, but a necessity for those looking to leverage AI for their projects. On the 11th of June, 2023, OpenAI introduced a slew of new features, marking a significant update to their Python SDK, now at version 1.0.0. In this blog, we’ll dive into these updates and explore how they can revolutionize the way we interact with AI.
mggg's 博客
OpenAI 11.06更新
OpenAI 11.06更新 在这篇博客中,将讨论 OpenAI 11.06 的一些更新,更新主要有:
聊天内容支持图片, gpt-4-vision-preview 返回内容支持json模式 引入system_fingerprint, 支持可复现性 OpenAI 多模态模型 OpenAI 引入的最令人兴奋的新功能之一是多模态模型,它可以处理文本和图像的组合。这一能力为 AI 应用打开了一个新的维度,从增强的视觉数据分析到更互动的聊天机器人。
GPT-4 Vision: gpt-4-vision-preview 示例: 分析阿里巴巴股票的K线.
import openai openai.api_key = "your-api-key" response = openai.ChatCompletion.create( model="gpt-4-vision-preview", messages=[ { "role": "user", "content": [ {"type": "text", "text": "What information can you understand from the K-line of the image?"}, { "type": "image_url", "image_url": "https://mggg.cloud/img/ali.png", }, ], } ], max_tokens=300, ) print(response.choices[0].message.content) output:
The image appears to show a candlestick chart for a stock, specifically ticker 'BABA' which is Alibaba Group Holding Limited.
mggg's Blog
Vector Database: Weaviate
Vector Database: Weaviate Weaviate is an innovative vector database known for its efficiency in storing and retrieving data. Utilizing vectors, Weaviate indexes data objects based on their semantic properties, offering a unique approach to data handling. It supports a variety of modules, including text2vec and OpenAI embeddings, providing flexibility in data vectorization.
Getting Started with Weaviate Deploying Weaviate is straightforward with docker-compose. The OpenAI module transforms text into embeddings, enhancing semantic search capabilities.
Category: free-series
mggg's 博客
为Nginx设置免费的HTTPS证书(使用Let's Encrypt)
简介 使用HTTPS保护网站不仅可以确保数据完整性,还可以增强用户信任和搜索引擎排名。通过Let’s Encrypt,您可以轻松地为Nginx Web服务器获取免费的SSL/TLS证书。在本指南中,我们将为您介绍如何在CentOS上为Nginx服务器设置Let’s Encrypt证书。
sudo yum install epel-release sudo yum install certbot Step 2: 安装Certbot Nginx插件 为了简化获取和安装证书的过程,Certbot为Nginx提供了一个专用的插件。使用以下命令安装Certbot Nginx插件:
sudo yum install -y python3-certbot-nginx Step 3: 为Nginx生成证书 现在Certbot和Nginx插件已安装,可以生成SSL/TLS证书。请在下面的命令中将yourdomain.com替换为您的域名,然后运行它:
sudo certbot --nginx -d yourdomain.com warning: 请记得替换您的域名
Certbot会进行交互,引导选择适当的选项并配置证书详细信息。
Step 4: 自动Nginx配置 获得证书后,Certbot将自动修改Nginx配置以启用HTTPS访问。它将在nginx.conf文件中处理必要的更改,将HTTP流量重定向到安全的HTTPS协议。
总结 通过遵循这些简单的步骤,成功使用免费的Let’s Encrypt SSL/TLS证书保护了Nginx Web服务器。现在,网站访问者可以享受安全的加密浏览体验,增强了他们对网站的信任,并提高了在搜索引擎结果中的可见性。
请定期更新Let’s Encrypt证书,以确保持续保护网站安全。Certbot内置的自动更新功能可以让这一过程变得轻松无忧。
Category: Security
mggg's Blog
How to Add a Free SSL Certificate to Nginx: A Step-by-Step Guide
How to Add a Free SSL Certificate to Nginx: A Step-by-Step Guide Introduction Implementing HTTPS by adding a free SSL certificate to your Nginx server is a pivotal step in enhancing website security. In this tutorial, we’ll cover the nginx ssl configuration process using Let’s Encrypt, a service offering free SSL/TLS certificates. This guide aims to provide an easy-to-follow procedure to enable https with nginx, ensuring your web communication remains secure and trusted by both users and search engines.
Category: ai-learning
mggg's 博客
向量数据库:Weaviate
向量数据库:Weaviate Weaviate是一个创新的向量数据库,提供了强大的数据存储和检索功能。
通过使用向量来索引数据对象,Weaviate可以根据其语义属性存储和检索数据对象。 Weaviate可以独立使用(带上你的向量),或与各种模块结合使用,对您的核心功能进行矢量化和增强。 多亏了其独特的设计,Weaviate确保了快速的性能和高效的操作。 QuickStart: 要部署Weaviate,可以使用docker-compose。对于文本嵌入转换,我们将使用OpenAI模块:
--- version: '3.4' services: weaviate: image: cr.weaviate.io/semitechnologies/weaviate:1.20.0 restart: on-failure:0 ports: - "8080:8080" environment: QUERY_DEFAULTS_LIMIT: 20 AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: 'true' PERSISTENCE_DATA_PATH: "./data" DEFAULT_VECTORIZER_MODULE: text2vec-openai ENABLE_MODULES: text2vec-openai OPENAI_APIKEY: sk-xxx # replace with your OpenAI key CLUSTER_HOSTNAME: 'node1' 使用Weaviate和OpenAI 1. 建立链接 首先,我们建立与Weaviate向量数据库的连接:
pip install weaviate-client import weaviate client = weaviate.Client( url = "http://localhost:8080" ) client.is_live() 2. 插入数据 一旦与Weaviate向量数据库的连接正常,我们可以开始插入数据:
uuid = client.data_object.create({ 'question': 'This vector DB is OSS & supports automatic property type inference on import', 'somePropNotInTheSchema': 123, # automatically added as a numeric property }, 'JeopardyQuestion') print(uuid) 3.
Category: education
mggg's Blog
How to Create Anki Cards Efficiently with a ChatGPT-Based Chrome Extension
How to Create Anki Cards Efficiently with a ChatGPT-Based Chrome Extension Harness the power of ChatGPT and streamline your learning process by creating Anki cards with a Chrome extension. As a flash card creator and note card maker, this guide will walk you through using this innovative tool, perfect for organizing and memorizing information from the web.
Why Use a ChatGPT Chrome Extension with Anki With an overload of information available online, structuring and memorizing it can be a daunting task.
Category: productivity tools
mggg's Blog
How to Create Anki Cards Efficiently with a ChatGPT-Based Chrome Extension
How to Create Anki Cards Efficiently with a ChatGPT-Based Chrome Extension Harness the power of ChatGPT and streamline your learning process by creating Anki cards with a Chrome extension. As a flash card creator and note card maker, this guide will walk you through using this innovative tool, perfect for organizing and memorizing information from the web.
Why Use a ChatGPT Chrome Extension with Anki With an overload of information available online, structuring and memorizing it can be a daunting task.
Category: tech
mggg's Blog
How to Create Anki Cards Efficiently with a ChatGPT-Based Chrome Extension
How to Create Anki Cards Efficiently with a ChatGPT-Based Chrome Extension Harness the power of ChatGPT and streamline your learning process by creating Anki cards with a Chrome extension. As a flash card creator and note card maker, this guide will walk you through using this innovative tool, perfect for organizing and memorizing information from the web.
Why Use a ChatGPT Chrome Extension with Anki With an overload of information available online, structuring and memorizing it can be a daunting task.
mggg's 博客
使用基于ChatGPT的Chrome扩展创建Anki卡片
通过记忆软件Anki,有效地组织和记忆零散的信息, 它使用分散重复的方法来帮助我们回忆。然而,创建Anki卡片的过程可能非常耗时。
为了解决这个问题,开发了一个基于ChatGPT的Chrome扩展工具,帮助快速高效地创建Anki卡片。
这个Chrome扩展工具的诞生基于两个基本需求:
在上网浏览时,需要收集有价值的碎片信息,并使用ChatGPT将其整理成Anki卡片。 在备考考试/认证或者记忆面试的标准答案时的必要性。 如何使用基于ChatGPT的Chrome扩展创建Anki卡片 通过zip包安装Chrome扩展:下载链接。
设置相关配置并保存。
当您遇到感兴趣的内容时,选择文本并使用ChatGPT将其总结成Anki卡片。
完成后,您可以在Anki中开始复习。
基于ChatGPT的Chrome扩展不仅可以帮助您节省创建Anki卡片的时间,还可以使学习过程更加高效。