Below you will find pages that utilize the taxonomy term “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
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().