文章

20 creative hashtags/tools

 Let's brainstorm 20 creative hashtags/tools for a bot, keeping in mind the #search example for RAG (Retrieval Augmented Generation) via a search engine. I'll focus on functionalities that extend the bot's capabilities beyond basic conversational AI. Here are 20 hashtags/tools, categorized for clarity: Information & Research Tools: #search: (As you mentioned) Triggers a web search (Google, Bing, etc.) for real-time information retrieval and RAG. #wiki: Accesses Wikipedia for concise, structured information on a given topic. Ideal for quick facts and overviews. #define: Provides definitions, synonyms, and antonyms from a dictionary or lexical database. #news: Fetches recent headlines and summaries from a specified news source or general news feed. #journal: Accesses academic databases (e.g., PubMed, JSTOR, ArXiv) to find research papers and scholarly articles. Creative & Generation Tools: #imagine: Generates images based on a textual description using a...

cursor editor default CLI (not powershell, use terminal)

Ctrl + ,  command prompt

conda export requirements.txt

 conda list -e > requirements.txt conda install --yes --file requirements.txt

Chain Types: Stuff, Refine, Map reduce, Map re-rank

圖片
 Langchain 提供了幾種「文件 chain」來處理和 LLM 互動多份文件。每種 chain 類型都有其優缺點,適用於不同的使用場景。 1. Stuff (填充) 概念: 最直接的方法。它會將所有文件直接「塞」或插入到 LLM 的提示中。 理想用途: 文件較小且每次只使用少量文件的應用,確保總 token 數在 LLM 的上下文限制內。 優點: 只需一次 API 呼叫。 所有數據一次性處理。 缺點: 受限於 LLM 的最大上下文長度;如果文件 token 超出此限制,將會失敗。 2. Refine (精煉) 概念: 透過循環處理輸入文件並迭代更新其答案來構建回應。對於每個文件,它將當前文件、非文件輸入以及最新的中間答案一起傳遞給 LLM chain,以獲得一個新的、精煉的答案。 理想用途: 需要分析的文件數量超出模型上下文範圍的任務,因為它會逐一處理文件。 優點: 與 Map Reduce 相比,能保持更相關的上下文,因為它會根據每個新文件精煉答案。 缺點: 涉及許多相互依賴的 LLM 呼叫,因為每個文件都需要單獨的互動。 3. Map Reduce (映射歸納) 概念: 兩階段過程: 映射 (Map) 階段: 單獨將一個 LLM chain 應用於每個文件,並將 chain 的輸出視為一個新文件。 歸納 (Reduce) 階段: 將所有這些新生成的文件傳遞給一個單獨的「組合文件 chain」,以產生一個單一的最終輸出。 理想用途: 總結大量文件,特別是當文件內容超出 LLM 上下文限制時。 優點: 透過分塊處理文件,可擴展到處理更大的文件。 可並行處理,可能加快處理速度。 缺點: 需要多次 API 呼叫(每個「映射」步驟一次,然後「歸納」步驟一次)。 在歸納階段可能會丟失信息,因為單個文件摘要會被組合。 4. Map Re-rank (映射重排) 概念: 在每個文件上運行一個初始提示,該提示不僅嘗試完成任務,還為其答案的確定性提供一個「分數」。系統隨後只返回得分最高的回應。 理想用途: 回答單一答案問題,當需要最相關或最有信心的答案,而不是全面總結或信息組合時。 優點: 對大量文件有良好的擴展性。 更適合需要單一明確答案的任務...

《Langchain Python 完整教程》建議主題列表

  《Langchain Python 完整教程》建議主題列表 第一章:Langchain 導論 什麼是 Langchain? Langchain 的核心理念與優勢 Langchain 生態系統概覽 (LangSmith, LangServe, LangGraph) 安裝與環境設定 (Python, Jupyter Notebook, API 金鑰) 第二章:大型語言模型 (LLM) 基礎 LLM 的基本原理 不同類型的 LLM (OpenAI GPT 系列, Hugging Face Hub 模型等) 在 Langchain 中集成和使用 LLM 模型參數詳解 (temperature, max_tokens 等) 第三章:提示工程 (Prompt Engineering) 什麼是提示 (Prompt)? 設計高效提示的技巧 Langchain 中的提示模板 (Prompt Templates) 少量樣本提示 (Few-shot Prompting) 第四章:鏈 (Chains) – 串聯你的思考 鏈的基本概念與運作方式 簡單順序鏈 (Simple Sequential Chains) LLMChain 詳解 路由鏈 (Router Chains) 與轉換鏈 (Transformation Chains) 第五章:索引 (Indexes) 與檢索器 (Retrievers) – 讓 LLM 擁有記憶 文本嵌入 (Embeddings) 詳解 向量數據庫 (Vector Stores) 的選擇與應用 (Chroma, FAISS 等) 不同類型的檢索器 (Retrievers) 文本分割 (Text Splitters) 的策略 第六章:記憶 (Memory) – 賦予應用程序上下文感知能力 記憶在對話系統中的重要性 不同類型的記憶模塊 (ConversationBufferMemory, ConversationSummaryMemory 等) 如何在鏈和代理中使用記憶 管理和持久化記憶 第七章:代理 (Agents) – 讓 LLM 擁有行動力 代理的基本原理與組件 (工具, 代理執行器) 內建工具 (Tools) 的使用 (搜索引擎, ...

Langchain RunnableParallel

 https://medium.com/seaniap/%E5%BE%9E%E7%B0%A1%E5%96%AE%E5%88%B0%E8%A4%87%E9%9B%9C-%E8%A7%A3%E9%8E%96-lcel-%E6%B5%81%E7%A8%8B%E9%8F%88%E6%8A%80%E8%A1%93-1-2911dd0bce3f # 引入語言模型 from langchain_openai import ChatOpenAI # 引入PromptTemplate from langchain_core.prompts import ChatPromptTemplate, PromptTemplate from langchain_core.output_parsers import StrOutputParser from langchain_core.runnables import RunnableParallel # 建立 OpenAI 物件 chat_model = ChatOpenAI(model= "gpt-3.5-turbo" , api_key= "<your_api_key_here>" ) str_parser = StrOutputParser() prompt1 = ChatPromptTemplate.from_template( '{city} 位於哪個國家?' ) chain1 = prompt1 | chat_model | str_parser # 建立第二個 PromptTemplate prompt2 = ChatPromptTemplate.from_template( '在 {city} 的人都如何用餐?' ) chain2 = prompt2 | chat_model | str_parser country_and_style_chain = RunnableParallel( country=chain1, style=chain2 ) result = country_and_lang_chain.invoke({ 'city' : '東京' }) print (result)