prompt = hub.pull("hwchase17/react")
llm = OpenAI()
tools = load_tools(["serpapi", "llm-math"], llm=llm)
agent = create_react_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
agent_executor.invoke({"input": "How many seconds are in 1:23:45"})
https://github.com/ray-project/langchain-ray这个仓库展示了3个ray和langchain结合的示例,包括源代码、视频讲解、博客文档,对快速认知这两个工具及如何结合使用,非常有帮助。(但不知道出于什么原因,仅不到一年,这个仓库的状态已经是Public archive了。)
让我很有印象的是RAG应用示例。
首先是特征向量化过程(Embedding/Vector Store)。Ray Data提供了并行处理数据能力,将原始PDF文件向量化后存储/索引到FAISS。这个过程如果单纯使用langchain实现,这个过程是小时级的;而引入ray data后这个过程是分钟级的。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-rsocket</artifactId> | |
<version>${spring-boot.version}</version> | |
<exclusions> | |
<exclusion> | |
<groupId>io.netty</groupId> | |
<artifactId>netty-buffer</artifactId> | |
</exclusion> | |
<exclusion> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Using exclusive or self-inverse to find the repeated number in an array | |
// Self-inverse: A ⊕ A = 0 | |
// A XOR B XOR B = A XOR 0 = A | |
int[] a1 = {1, 2, 3, 3}; | |
int[] a2 = {1, 2, 2, 3}; | |
int x1 = a1[0] ^ a1[1] ^ a1[2] ^ a1[3] ^ 1 ^ 2 ^ 3; | |
int x2 = a2[0] ^ a2[1] ^ a2[2] ^ a2[3] ^ 1 ^ 2 ^ 3; | |
System.out.println(x1); | |
System.out.println(x2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void test() throws InterruptedException, ExecutionException { | |
ForkJoinPool customThreadPool = new ForkJoinPool(8); | |
ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("pool-%d").build(); | |
ThreadPoolExecutor executor = new ThreadPoolExecutor(5, Integer.MAX_VALUE, | |
1, TimeUnit.MINUTES, | |
new LinkedBlockingQueue<>(5), | |
threadFactory, | |
new ThreadPoolExecutor.AbortPolicy()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
╰─○ cat .gitconfig | |
[user] | |
name = 六翁 | |
email = lu.hl@***.com | |
[push] | |
default = matching | |
[core] | |
autocrlf = input | |
[color] | |
ui = auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
╰─○ cat .gitconfig | |
[user] | |
name = 六翁 | |
email = lu.hl@***.com | |
[push] | |
default = matching | |
[core] | |
autocrlf = input | |
[color] | |
ui = auto |
#!/usr/bin/env bash
executingPath=$(pwd)
scriptPath=$(cd $(dirname $0);pwd)
scriptParentPath=$(cd $(dirname $0);cd ..; pwd)
scriptName=$(basename $0)
line=$(printf "%-60s")
echo "${line// /#}"
echo "Executing path : $executingPath"
NewerOlder