Skip to content

Commit 5c2a5ab

Browse files
AlexFly666wangyanfei
and
wangyanfei
authored
依赖更新最新版本,验证和优化Openai目录中的代码 (#120)
* 所有依赖更新最新版本 * 【FIX】去掉pip install 使用项目依赖版本,避免版本更新;更新DeepSeek Completions接口调用接口 * 【FIX】/v1/completions调用也即将过期; 更新为 /v1/chat/completions ,使用gpt-4o-mini模型 * 【FIX】智谱模型 Function Calling 和 deepseek-chat 模型 Function Calling 文档地址 * 【FIX】安装必要依赖包【明确版本】;去掉多余的python-magic-bin * 【FIX】去掉pip install 使用项目依赖版本;langchain_chroma已经补充到requirements.txt * 【FIX】去掉pip install 使用项目依赖版本; 新增ChatOpenAI调用 * 【FIX】去掉pip install 使用项目依赖版本; 新增ChatOpenAI调用 * 【新增】langchain 0.3版本,使用RunnableSequence替换LLMChain,并指定 output_key * 【FIX】去掉pip install 使用项目依赖版本 --------- Co-authored-by: wangyanfei <[email protected]>
1 parent e16e12f commit 5c2a5ab

File tree

11 files changed

+2202
-678
lines changed

11 files changed

+2202
-678
lines changed

langchain/jupyter/LCEL/rag.ipynb

+2-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@
161161
}
162162
],
163163
"source": [
164-
"!pip install langchain langchain_community langchain_chroma"
164+
"# 去掉pip install 使用项目依赖版本\n",
165+
"# !pip install langchain langchain_community langchain_chroma\n"
165166
]
166167
},
167168
{

langchain/jupyter/agents/openai_function.ipynb

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"outputs": [],
1717
"source": [
1818
"%%capture --no-stderr\n",
19-
"%pip install -U langchain"
19+
"# 去掉pip install 使用项目依赖版本\n",
20+
"# %pip install -U langchain"
2021
]
2122
},
2223
{

langchain/jupyter/autogpt/autogpt.ipynb

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
}
5454
],
5555
"source": [
56-
"! pip install -U langchain"
56+
"# 去掉pip install 使用项目依赖版本\n",
57+
"# ! pip install -U langchain"
5758
]
5859
},
5960
{

langchain/jupyter/chains/sequential_chain.ipynb

+135-90
Large diffs are not rendered by default.

langchain/jupyter/data_connection/document_loader.ipynb

+4-4
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@
276276
}
277277
],
278278
"source": [
279-
"# 安装必要依赖包\n",
280-
"!pip install arxiv pymupdf"
279+
"# 安装必要依赖包【明确版本】\n",
280+
"!pip install arxiv==2.1.3 pymupdf==1.25.3"
281281
]
282282
},
283283
{
@@ -418,8 +418,8 @@
418418
}
419419
],
420420
"source": [
421-
"! pip install python-magic\n",
422-
"! pip install python-magic-bin"
421+
"# 安装必要依赖包【明确版本】\n",
422+
"! pip install python-magic==0.4.27"
423423
]
424424
},
425425
{

langchain/jupyter/model_io/model.ipynb

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"- Models:以通用接口调用语言模型\n",
1515
"- Output Parser:从模型输出中提取信息,并规范化内容\n",
1616
"\n",
17-
"![](../images/model_io.jpeg)\r\n"
17+
"![](../images/model_io.jpeg)\n"
1818
]
1919
},
2020
{
@@ -60,7 +60,8 @@
6060
}
6161
],
6262
"source": [
63-
"! pip install -U langchain"
63+
"# 去掉pip install 使用项目依赖版本\n",
64+
"# ! pip install -U langchain"
6465
]
6566
},
6667
{

langchain/jupyter/model_io/prompt.ipynb

+163-240
Large diffs are not rendered by default.

openai_api/embedding.ipynb

+1,380-113
Large diffs are not rendered by default.

openai_api/function_call.ipynb

+90-76
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,26 @@
132132
},
133133
{
134134
"cell_type": "code",
135-
"execution_count": 3,
136135
"id": "eb420fcd-1a4d-4cc8-90cf-39a92cf28060",
137-
"metadata": {},
138-
"outputs": [],
136+
"metadata": {
137+
"jupyter": {
138+
"is_executing": true
139+
}
140+
},
139141
"source": [
140142
"# 使用了retry库,指定在请求失败时的重试策略。\n",
141143
"# 这里设定的是指数等待(wait_random_exponential),时间间隔的最大值为40秒,并且最多重试3次(stop_after_attempt(3))。\n",
142144
"# 定义一个函数chat_completion_request,主要用于发送 聊天补全 请求到OpenAI服务器\n",
145+
"\n",
146+
"#### 【新增】\n",
147+
"# 智谱模型 Function Calling\n",
148+
"# 参考: https://www.bigmodel.cn/dev/howuse/functioncall\n",
149+
"\n",
150+
"# deepseek-chat 模型 Function Calling\n",
151+
"# 注意:当前版本 deepseek-chat 模型 Function Calling 功能效果不稳定,会出现循环调用、空回复的情况。\n",
152+
"# 参考: https://api-docs.deepseek.com/zh-cn/guides/function_calling\n",
153+
"\n",
154+
"### 使用 智谱模型 Function Calling 和 deepseek-chat 模型 Function Calling 注意替换模型名称,调用地址,和API KEY\n",
143155
"@retry(wait=wait_random_exponential(multiplier=1, max=40), stop=stop_after_attempt(3))\n",
144156
"def chat_completion_request(messages, functions=None, function_call=None, model=GPT_MODEL):\n",
145157
"\n",
@@ -175,7 +187,9 @@
175187
" print(\"Unable to generate ChatCompletion response\")\n",
176188
" print(f\"Exception: {e}\")\n",
177189
" return e\n"
178-
]
190+
],
191+
"outputs": [],
192+
"execution_count": null
179193
},
180194
{
181195
"cell_type": "code",
@@ -328,12 +342,12 @@
328342
"name": "stdout",
329343
"output_type": "stream",
330344
"text": [
331-
"\u001b[31msystem: Don't make assumptions about what values to plug into functions. Ask for clarification if a user request is ambiguous.\n",
332-
"\u001b[0m\n",
333-
"\u001b[32muser: What's the weather like today\n",
334-
"\u001b[0m\n",
335-
"\u001b[34massistant[content]: Sure, could you please provide me with the location for which you would like to know the current weather?\n",
336-
"\u001b[0m\n"
345+
"\u001B[31msystem: Don't make assumptions about what values to plug into functions. Ask for clarification if a user request is ambiguous.\n",
346+
"\u001B[0m\n",
347+
"\u001B[32muser: What's the weather like today\n",
348+
"\u001B[0m\n",
349+
"\u001B[34massistant[content]: Sure, could you please provide me with the location for which you would like to know the current weather?\n",
350+
"\u001B[0m\n"
337351
]
338352
}
339353
],
@@ -429,16 +443,16 @@
429443
"name": "stdout",
430444
"output_type": "stream",
431445
"text": [
432-
"\u001b[31msystem: Don't make assumptions about what values to plug into functions. Ask for clarification if a user request is ambiguous.\n",
433-
"\u001b[0m\n",
434-
"\u001b[32muser: What's the weather like today\n",
435-
"\u001b[0m\n",
436-
"\u001b[34massistant[content]: Sure, could you please provide me with the location for which you would like to know the current weather?\n",
437-
"\u001b[0m\n",
438-
"\u001b[32muser: I'm in Shanghai, China.\n",
439-
"\u001b[0m\n",
440-
"\u001b[34massistant[function_call]: {'name': 'get_current_weather', 'arguments': '{\"location\":\"Shanghai, China\",\"format\":\"celsius\"}'}\n",
441-
"\u001b[0m\n"
446+
"\u001B[31msystem: Don't make assumptions about what values to plug into functions. Ask for clarification if a user request is ambiguous.\n",
447+
"\u001B[0m\n",
448+
"\u001B[32muser: What's the weather like today\n",
449+
"\u001B[0m\n",
450+
"\u001B[34massistant[content]: Sure, could you please provide me with the location for which you would like to know the current weather?\n",
451+
"\u001B[0m\n",
452+
"\u001B[32muser: I'm in Shanghai, China.\n",
453+
"\u001B[0m\n",
454+
"\u001B[34massistant[function_call]: {'name': 'get_current_weather', 'arguments': '{\"location\":\"Shanghai, China\",\"format\":\"celsius\"}'}\n",
455+
"\u001B[0m\n"
442456
]
443457
}
444458
],
@@ -488,12 +502,12 @@
488502
"name": "stdout",
489503
"output_type": "stream",
490504
"text": [
491-
"\u001b[31msystem: Don't make assumptions about what values to plug into functions. Ask for clarification if a user request is ambiguous.\n",
492-
"\u001b[0m\n",
493-
"\u001b[32muser: what is the weather going to be like in Shanghai, China over the next x days\n",
494-
"\u001b[0m\n",
495-
"\u001b[34massistant[content]: Sure! Please provide the number of days you would like to know the weather forecast for in Shanghai, China.\n",
496-
"\u001b[0m\n"
505+
"\u001B[31msystem: Don't make assumptions about what values to plug into functions. Ask for clarification if a user request is ambiguous.\n",
506+
"\u001B[0m\n",
507+
"\u001B[32muser: what is the weather going to be like in Shanghai, China over the next x days\n",
508+
"\u001B[0m\n",
509+
"\u001B[34massistant[content]: Sure! Please provide the number of days you would like to know the weather forecast for in Shanghai, China.\n",
510+
"\u001B[0m\n"
497511
]
498512
}
499513
],
@@ -555,16 +569,16 @@
555569
"name": "stdout",
556570
"output_type": "stream",
557571
"text": [
558-
"\u001b[31msystem: Don't make assumptions about what values to plug into functions. Ask for clarification if a user request is ambiguous.\n",
559-
"\u001b[0m\n",
560-
"\u001b[32muser: what is the weather going to be like in Shanghai, China over the next x days\n",
561-
"\u001b[0m\n",
562-
"\u001b[34massistant[content]: Sure! Please provide the number of days you would like to know the weather forecast for in Shanghai, China.\n",
563-
"\u001b[0m\n",
564-
"\u001b[32muser: 5 days\n",
565-
"\u001b[0m\n",
566-
"\u001b[34massistant[function_call]: {'name': 'get_n_day_weather_forecast', 'arguments': '{\"location\":\"Shanghai, China\",\"format\":\"celsius\",\"num_days\":5}'}\n",
567-
"\u001b[0m\n"
572+
"\u001B[31msystem: Don't make assumptions about what values to plug into functions. Ask for clarification if a user request is ambiguous.\n",
573+
"\u001B[0m\n",
574+
"\u001B[32muser: what is the weather going to be like in Shanghai, China over the next x days\n",
575+
"\u001B[0m\n",
576+
"\u001B[34massistant[content]: Sure! Please provide the number of days you would like to know the weather forecast for in Shanghai, China.\n",
577+
"\u001B[0m\n",
578+
"\u001B[32muser: 5 days\n",
579+
"\u001B[0m\n",
580+
"\u001B[34massistant[function_call]: {'name': 'get_n_day_weather_forecast', 'arguments': '{\"location\":\"Shanghai, China\",\"format\":\"celsius\",\"num_days\":5}'}\n",
581+
"\u001B[0m\n"
568582
]
569583
}
570584
],
@@ -620,12 +634,12 @@
620634
"name": "stdout",
621635
"output_type": "stream",
622636
"text": [
623-
"\u001b[31msystem: Don't make assumptions about what values to plug into functions. Ask for clarification if a user request is ambiguous.\n",
624-
"\u001b[0m\n",
625-
"\u001b[32muser: Give me a weather report for San Diego, USA.\n",
626-
"\u001b[0m\n",
627-
"\u001b[34massistant[function_call]: {'name': 'get_n_day_weather_forecast', 'arguments': '{\"location\":\"San Diego, USA\",\"format\":\"celsius\",\"num_days\":1}'}\n",
628-
"\u001b[0m\n"
637+
"\u001B[31msystem: Don't make assumptions about what values to plug into functions. Ask for clarification if a user request is ambiguous.\n",
638+
"\u001B[0m\n",
639+
"\u001B[32muser: Give me a weather report for San Diego, USA.\n",
640+
"\u001B[0m\n",
641+
"\u001B[34massistant[function_call]: {'name': 'get_n_day_weather_forecast', 'arguments': '{\"location\":\"San Diego, USA\",\"format\":\"celsius\",\"num_days\":1}'}\n",
642+
"\u001B[0m\n"
629643
]
630644
}
631645
],
@@ -678,12 +692,12 @@
678692
"name": "stdout",
679693
"output_type": "stream",
680694
"text": [
681-
"\u001b[31msystem: Don't make assumptions about what values to plug into functions. Ask for clarification if a user request is ambiguous.\n",
682-
"\u001b[0m\n",
683-
"\u001b[32muser: Give me a weather report for San Diego, USA.\n",
684-
"\u001b[0m\n",
685-
"\u001b[34massistant[function_call]: {'name': 'get_current_weather', 'arguments': '{\"location\":\"San Diego, USA\",\"format\":\"celsius\"}'}\n",
686-
"\u001b[0m\n"
695+
"\u001B[31msystem: Don't make assumptions about what values to plug into functions. Ask for clarification if a user request is ambiguous.\n",
696+
"\u001B[0m\n",
697+
"\u001B[32muser: Give me a weather report for San Diego, USA.\n",
698+
"\u001B[0m\n",
699+
"\u001B[34massistant[function_call]: {'name': 'get_current_weather', 'arguments': '{\"location\":\"San Diego, USA\",\"format\":\"celsius\"}'}\n",
700+
"\u001B[0m\n"
687701
]
688702
}
689703
],
@@ -745,12 +759,12 @@
745759
"name": "stdout",
746760
"output_type": "stream",
747761
"text": [
748-
"\u001b[31msystem: Don't make assumptions about what values to plug into functions. Ask for clarification if a user request is ambiguous.\n",
749-
"\u001b[0m\n",
750-
"\u001b[32muser: Give me the current weather (use Celcius) for Toronto, Canada.\n",
751-
"\u001b[0m\n",
752-
"\u001b[34massistant[content]: Sure! Let me retrieve the current weather for Toronto, Canada in Celsius.\n",
753-
"\u001b[0m\n"
762+
"\u001B[31msystem: Don't make assumptions about what values to plug into functions. Ask for clarification if a user request is ambiguous.\n",
763+
"\u001B[0m\n",
764+
"\u001B[32muser: Give me the current weather (use Celcius) for Toronto, Canada.\n",
765+
"\u001B[0m\n",
766+
"\u001B[34massistant[content]: Sure! Let me retrieve the current weather for Toronto, Canada in Celsius.\n",
767+
"\u001B[0m\n"
754768
]
755769
}
756770
],
@@ -1105,14 +1119,14 @@
11051119
"name": "stdout",
11061120
"output_type": "stream",
11071121
"text": [
1108-
"\u001b[31msystem: Answer user questions by generating SQL queries against the Chinook Music Database.\n",
1109-
"\u001b[0m\n",
1110-
"\u001b[32muser: Hi, who are the top 5 artists by number of tracks?\n",
1111-
"\u001b[0m\n",
1112-
"\u001b[34massistant[function_call]: {'name': 'ask_database', 'arguments': '{\"query\":\"SELECT artists.Name, COUNT(tracks.TrackId) AS TrackCount\\\\nFROM artists\\\\nJOIN albums ON artists.ArtistId = albums.ArtistId\\\\nJOIN tracks ON albums.AlbumId = tracks.AlbumId\\\\nGROUP BY artists.Name\\\\nORDER BY TrackCount DESC\\\\nLIMIT 5;\"}'}\n",
1113-
"\u001b[0m\n",
1114-
"\u001b[35mfunction (ask_database): [('Iron Maiden', 213), ('U2', 135), ('Led Zeppelin', 114), ('Metallica', 112), ('Lost', 92)]\n",
1115-
"\u001b[0m\n"
1122+
"\u001B[31msystem: Answer user questions by generating SQL queries against the Chinook Music Database.\n",
1123+
"\u001B[0m\n",
1124+
"\u001B[32muser: Hi, who are the top 5 artists by number of tracks?\n",
1125+
"\u001B[0m\n",
1126+
"\u001B[34massistant[function_call]: {'name': 'ask_database', 'arguments': '{\"query\":\"SELECT artists.Name, COUNT(tracks.TrackId) AS TrackCount\\\\nFROM artists\\\\nJOIN albums ON artists.ArtistId = albums.ArtistId\\\\nJOIN tracks ON albums.AlbumId = tracks.AlbumId\\\\nGROUP BY artists.Name\\\\nORDER BY TrackCount DESC\\\\nLIMIT 5;\"}'}\n",
1127+
"\u001B[0m\n",
1128+
"\u001B[35mfunction (ask_database): [('Iron Maiden', 213), ('U2', 135), ('Led Zeppelin', 114), ('Metallica', 112), ('Lost', 92)]\n",
1129+
"\u001B[0m\n"
11161130
]
11171131
}
11181132
],
@@ -1240,20 +1254,20 @@
12401254
"name": "stdout",
12411255
"output_type": "stream",
12421256
"text": [
1243-
"\u001b[31msystem: Answer user questions by generating SQL queries against the Chinook Music Database.\n",
1244-
"\u001b[0m\n",
1245-
"\u001b[32muser: Hi, who are the top 5 artists by number of tracks?\n",
1246-
"\u001b[0m\n",
1247-
"\u001b[34massistant[function_call]: {'name': 'ask_database', 'arguments': '{\"query\":\"SELECT artists.Name, COUNT(tracks.TrackId) AS TrackCount\\\\nFROM artists\\\\nJOIN albums ON artists.ArtistId = albums.ArtistId\\\\nJOIN tracks ON albums.AlbumId = tracks.AlbumId\\\\nGROUP BY artists.Name\\\\nORDER BY TrackCount DESC\\\\nLIMIT 5;\"}'}\n",
1248-
"\u001b[0m\n",
1249-
"\u001b[35mfunction (ask_database): [('Iron Maiden', 213), ('U2', 135), ('Led Zeppelin', 114), ('Metallica', 112), ('Lost', 92)]\n",
1250-
"\u001b[0m\n",
1251-
"\u001b[32muser: What is the name of the album with the most tracks?\n",
1252-
"\u001b[0m\n",
1253-
"\u001b[34massistant[function_call]: {'name': 'ask_database', 'arguments': '{\"query\":\"SELECT albums.Title, COUNT(tracks.TrackId) AS TrackCount\\\\nFROM albums\\\\nJOIN tracks ON albums.AlbumId = tracks.AlbumId\\\\nGROUP BY albums.Title\\\\nORDER BY TrackCount DESC\\\\nLIMIT 1;\"}'}\n",
1254-
"\u001b[0m\n",
1255-
"\u001b[35mfunction (ask_database): [('Greatest Hits', 57)]\n",
1256-
"\u001b[0m\n"
1257+
"\u001B[31msystem: Answer user questions by generating SQL queries against the Chinook Music Database.\n",
1258+
"\u001B[0m\n",
1259+
"\u001B[32muser: Hi, who are the top 5 artists by number of tracks?\n",
1260+
"\u001B[0m\n",
1261+
"\u001B[34massistant[function_call]: {'name': 'ask_database', 'arguments': '{\"query\":\"SELECT artists.Name, COUNT(tracks.TrackId) AS TrackCount\\\\nFROM artists\\\\nJOIN albums ON artists.ArtistId = albums.ArtistId\\\\nJOIN tracks ON albums.AlbumId = tracks.AlbumId\\\\nGROUP BY artists.Name\\\\nORDER BY TrackCount DESC\\\\nLIMIT 5;\"}'}\n",
1262+
"\u001B[0m\n",
1263+
"\u001B[35mfunction (ask_database): [('Iron Maiden', 213), ('U2', 135), ('Led Zeppelin', 114), ('Metallica', 112), ('Lost', 92)]\n",
1264+
"\u001B[0m\n",
1265+
"\u001B[32muser: What is the name of the album with the most tracks?\n",
1266+
"\u001B[0m\n",
1267+
"\u001B[34massistant[function_call]: {'name': 'ask_database', 'arguments': '{\"query\":\"SELECT albums.Title, COUNT(tracks.TrackId) AS TrackCount\\\\nFROM albums\\\\nJOIN tracks ON albums.AlbumId = tracks.AlbumId\\\\nGROUP BY albums.Title\\\\nORDER BY TrackCount DESC\\\\nLIMIT 1;\"}'}\n",
1268+
"\u001B[0m\n",
1269+
"\u001B[35mfunction (ask_database): [('Greatest Hits', 57)]\n",
1270+
"\u001B[0m\n"
12571271
]
12581272
}
12591273
],

openai_api/models.ipynb

+403-133
Large diffs are not rendered by default.

requirements.txt

+18-17
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
openai==1.30.1
2-
langchain==0.2.0
3-
langchain-openai==0.1.7
4-
langchain-core==0.2.1
5-
langchain-community==0.2.0
6-
langchain-experimental==0.0.59
7-
langchain-text-splitters==0.2.0
8-
langsmith==0.1.65
9-
chromadb==0.4.24
10-
faiss-cpu==1.8.0
11-
gradio==4.22.0
12-
unstructured==0.12.6
1+
openai==1.61.1
2+
langchain==0.3.19
3+
langchain-openai==0.3.7
4+
langchain-core==0.3.40
5+
langchain-community==0.3.18
6+
langchain-experimental==0.3.4
7+
langchain_chroma==0.2.2
8+
langchain-text-splitters==0.3.6
9+
langsmith==0.3.11
10+
chromadb==0.6.3
11+
faiss-cpu==1.10.0
12+
gradio==5.20.0
13+
unstructured==0.16.23
1314
google-search-results==2.4.2
14-
tiktoken==0.7.0
15+
tiktoken==0.9.0
1516
docarray==0.40.0
16-
matplotlib==3.8.3
17-
plotly==5.20.0
17+
matplotlib==3.10.0
18+
plotly==5.24.1
1819
numpy==1.26.4
19-
scikit-learn==1.5.0
20-
pandas==2.2.1
20+
scikit-learn==1.6.1
21+
pandas==2.2.2

0 commit comments

Comments
 (0)