远兮 commited on
Commit
3de6db3
·
1 Parent(s): 56ac16d
app.py CHANGED
@@ -2,10 +2,12 @@ import gradio as gr
2
  from langchain.llms import OpenAI
3
  from langchain.llms import PromptLayerOpenAI
4
 
 
5
  def chatOpenAI(input):
6
  llm = OpenAI(temperature=0.9)
7
  return llm(input)
8
 
 
9
  def promptLayer(input):
10
  llm = PromptLayerOpenAI(pl_tags=["LangChainGo"])
11
  return llm(input)
@@ -14,4 +16,4 @@ def promptLayer(input):
14
  with gr.Blocks() as demo:
15
  gr.Markdown("# LangChain Test,LLM跑步上车。")
16
  gr.Interface(fn=promptLayer, inputs="text", outputs="text")
17
- demo.launch()
 
2
  from langchain.llms import OpenAI
3
  from langchain.llms import PromptLayerOpenAI
4
 
5
+
6
  def chatOpenAI(input):
7
  llm = OpenAI(temperature=0.9)
8
  return llm(input)
9
 
10
+
11
  def promptLayer(input):
12
  llm = PromptLayerOpenAI(pl_tags=["LangChainGo"])
13
  return llm(input)
 
16
  with gr.Blocks() as demo:
17
  gr.Markdown("# LangChain Test,LLM跑步上车。")
18
  gr.Interface(fn=promptLayer, inputs="text", outputs="text")
19
+ demo.launch()
data/llm_test.csv CHANGED
@@ -1,6 +1,8 @@
1
  name,age,city,mark
2
- 张三,100,河北,kk
3
  赵四,19,河北,kk
4
  赵五,100,河北,kk
5
  赵六,19,河北,kk
6
  王五,19,河北,kk
 
 
 
1
  name,age,city,mark
2
+ 张三,212,河北,kk
3
  赵四,19,河北,kk
4
  赵五,100,河北,kk
5
  赵六,19,河北,kk
6
  王五,19,河北,kk
7
+ ,name,age,city,mark
8
+ 0,张三,2345,河北,kk
index_bilibili.ipynb CHANGED
@@ -2,7 +2,7 @@
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
- "execution_count": null,
6
  "metadata": {},
7
  "outputs": [],
8
  "source": [
@@ -11,7 +11,7 @@
11
  },
12
  {
13
  "cell_type": "code",
14
- "execution_count": 15,
15
  "metadata": {},
16
  "outputs": [],
17
  "source": [
@@ -20,29 +20,35 @@
20
  },
21
  {
22
  "cell_type": "code",
23
- "execution_count": 16,
24
  "metadata": {},
25
  "outputs": [],
26
  "source": [
27
  "loader = BiliBiliLoader(\n",
28
- " [\"https://www.bilibili.com/video/BV1xt411o7Xu/\"]\n",
29
  ")"
30
  ]
31
  },
32
  {
33
  "cell_type": "code",
34
- "execution_count": 17,
35
  "metadata": {},
36
  "outputs": [
37
  {
38
- "data": {
39
- "text/plain": [
40
- "[Document(page_content='\\n Video Title: 【B站黑科技】如何给视频最快速加上字幕(CC字幕/外挂字幕功能介绍、教程,快速做字幕制作),\\n description: 目前手机端最新版已经支持该功能了,\\n有一些讲得不好的地方请指正,包涵一下吧~\\n如果有帮到你可以帮我的视频点一下推荐嘛~感谢观看~\\n\\n Transcript: 哈喽大家好,我是莫多 字幕是让很多up主头疼的问题 有字幕的视频可以增加许多观感体验 但是如果逐字逐句打字幕 会消耗大量的精力 今天在无意之中看到了B站推出的新功能 外挂/CC(closed caption)字幕功能 这个功能可以说是非常贴心了 因为所有人都可以根据自己喜好 随意拖动字幕 包括字体、大小,亦或是关闭字幕 因为在帮助界面里面没有找到具体的使用说明 我简单琢磨了一下 把我使用的心得分享一下吧 我们经常可以看到 会有野生的字幕君帮忙打字幕 但是以弹幕做字幕的话难免会有对不准的问题存在 我先给大家演示一下最简单制作字幕的方法 因为现在暂时没有办法 给别人的视频添加字幕 然后我就以我的视频为例吧 在字幕功能里面选择添加字幕 弹出的窗口里面 选择编辑 我们可以在播放的时候一边播放 一边插入字幕 这里可以看到 这里有个按钮是 我们可以以文档的方式上传字幕 目前常见支持的字幕格式貌似只有ASS 而其他常见字幕格式 如SRT,SSA,SUP还不能够支持 那么要怎样才能既快速又高效制作字幕呢? 这里我向各个UP主推荐一个非常好用的软件 它的名字叫做 (现在是收费软件)\\n人人译视界 (现在是收费软件)\\n因为它可以将我们 (现在是收费软件)\\n上传视频做成字幕 (现在是收费软件)\\n而且每段字幕都卡好时间点 (现在是收费软件)\\n大大减小了打字幕的时间 (现在是收费软件)\\n而且目前这是一款免费软件 (现在是收费软件)\\n不过就算以后收费了我也会非常乐意使用它 因为它集齐了听译和做字幕两个功能 对视频创作者来说有了这款软件 简直是如虎添翼呀 现在我给大家简单做个例子 我先把视频 当然音频也可以 拖到这款软件里面 然后点击AI听译 点击中译英 然后再点击(仅上传音频 ) 当然日语什么的也可以 但是最好是你已经做好了视频里面 不带背景音乐(BGM)的 这样它识别会更容易 然后选择只上传音频文件 然后选择AI听译 然后过一段时间他就会 开始上传 再过一段时间的话他就会 提示你转换完成 如果说有个别错别字话可以自己调整一下 (像我闽南口音比较重的话就要改很多字233) 然后这边分栏有许多功能 主要使用的是拆分和合并 拆分字幕和合并字幕 主要是合并为单行 (还有删除操作,选中字幕→Delete键) 如果你上传的 是中文视频的话AI听译里面 选择中译英 后面就是全选所有字幕(Ctrl+A) 点击清除译文就好了 (可以通过窗口左上角视频播放调整字幕) 调整好后导出字幕 选择ASS格式 当然我现在没有仔细做(主要是做个例子) ASS格式 这里就先导入到桌面上吧 (注意,这里选项→文本编码→选择UTF~16LE) (否则上传可能显示时间不合法) 因为会有一点点兼容的问题 我们还需要用记事本打开这个文档 然后将里面的这个部分 用替换功能把它替换掉 编辑→替换 将这个替换为空→全部替换 这里表示的应该是一个回车符的意思 但是播放器是不会显示出来的 B站上的外挂字幕功能的话就会显示 所以需要去掉 以后如果这个功能改进的话我也会在字幕里备注的 这时候(保存一下)便可以上传到B站上了 浏览一下如果没什么问题的话便可以提交了 或者是保存草稿 最后简单总结一下 内嵌和外挂字幕的优缺点吧 内嵌字幕的优点是样式多 但不能按照观众的每个人喜好去设置 外挂字幕的优点是 可以自由开启或关闭字幕 也可以���据每个人 自己的喜好来选择 特别是对一些生肉视频 有特殊需求者可以下载不带字幕的原视频 同时也不影响其他人观看体验 (还可以不带字幕截图) 对于B站推出的这个新功能我是非常支持的 好的 本次的视频就到这里了 有的内容讲得不太好 希望大家多多包涵 喜欢的朋友可以点个推荐吧 谢谢观看(❁´ω`❁)\\n ', metadata={'bvid': 'BV1xt411o7Xu', 'aid': 34218168, 'videos': 1, 'tid': 122, 'tname': '野生技能协会', 'copyright': 1, 'pic': 'http://i0.hdslb.com/bfs/archive/c6d6d31048b587b00e9b87b586cc083ddfaa2106.jpg', 'title': '【B站黑科技】如何给视频最快速加上字幕(CC字幕/外挂字幕功能介绍、教程,快速做字幕制作)', 'pubdate': 1540029603, 'ctime': 1540019978, 'desc': '目前手机端最新版已经支持该功能了,\\n有一些讲得不好的地方请指正,包涵一下吧~\\n如果有帮到你可以帮我的视频点一下推荐嘛~感谢观看~', 'desc_v2': [{'raw_text': '目前手机端最新版已经支持该功能了,\\n有一些讲得不好的地方请指正,包涵一下吧~\\n如果有帮到你可以帮我的视频点一下推荐嘛~感谢观看~', 'type': 1, 'biz_id': 0}], 'state': 0, 'duration': 408, 'rights': {'bp': 0, 'elec': 0, 'download': 1, 'movie': 0, 'pay': 0, 'hd5': 0, 'no_reprint': 1, 'autoplay': 1, 'ugc_pay': 0, 'is_cooperation': 0, 'ugc_pay_preview': 0, 'no_background': 0, 'clean_mode': 0, 'is_stein_gate': 0, 'is_360': 0, 'no_share': 0, 'arc_pay': 0, 'free_watch': 0}, 'owner': {'mid': 1865692, 'name': '莫多是攻', 'face': 'http://i1.hdslb.com/bfs/face/83d880d545cc9dcf948a7ce4204477aadf275cd7.jpg'}, 'stat': {'aid': 34218168, 'view': 125606, 'danmaku': 170, 'reply': 327, 'favorite': 3701, 'coin': 1017, 'share': 494, 'now_rank': 0, 'his_rank': 0, 'like': 2631, 'dislike': 0, 'evaluation': '', 'argue_msg': ''}, 'dynamic': '#经验分享##视频教程##教学视频#', 'cid': 59939848, 'dimension': {'width': 1920, 'height': 1080, 'rotate': 0}, 'premiere': None, 'teenage_mode': 0, 'is_chargeable_season': False, 'is_story': False, 'no_cache': False, 'pages': [{'cid': 59939848, 'page': 1, 'from': 'vupload', 'part': 'P1', 'duration': 408, 'vid': '', 'weblink': '', 'dimension': {'width': 1920, 'height': 1080, 'rotate': 0}}], 'is_season_display': False, 'user_garb': {'url_image_ani_cut': ''}, 'honor_reply': {}, 'like_icon': '', 'need_jump_bv': False, 'url': 'https://www.bilibili.com/video/BV1xt411o7Xu/'})]"
41
- ]
42
- },
43
- "execution_count": 17,
44
- "metadata": {},
45
- "output_type": "execute_result"
 
 
 
 
 
 
46
  }
47
  ],
48
  "source": [
 
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
+ "execution_count": 5,
6
  "metadata": {},
7
  "outputs": [],
8
  "source": [
 
11
  },
12
  {
13
  "cell_type": "code",
14
+ "execution_count": 6,
15
  "metadata": {},
16
  "outputs": [],
17
  "source": [
 
20
  },
21
  {
22
  "cell_type": "code",
23
+ "execution_count": 7,
24
  "metadata": {},
25
  "outputs": [],
26
  "source": [
27
  "loader = BiliBiliLoader(\n",
28
+ " [\"https://www.bilibili.com/video/BV1DP411m7TR/\"]\n",
29
  ")"
30
  ]
31
  },
32
  {
33
  "cell_type": "code",
34
+ "execution_count": 8,
35
  "metadata": {},
36
  "outputs": [
37
  {
38
+ "ename": "RuntimeError",
39
+ "evalue": "This event loop is already running",
40
+ "output_type": "error",
41
+ "traceback": [
42
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
43
+ "\u001b[0;31mRuntimeError\u001b[0m Traceback (most recent call last)",
44
+ "Cell \u001b[0;32mIn[8], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m loader\u001b[39m.\u001b[39;49mload()\n",
45
+ "File \u001b[0;32m~/anaconda3/lib/python3.10/site-packages/langchain/document_loaders/bilibili.py:23\u001b[0m, in \u001b[0;36mBiliBiliLoader.load\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 21\u001b[0m results \u001b[39m=\u001b[39m []\n\u001b[1;32m 22\u001b[0m \u001b[39mfor\u001b[39;00m url \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mvideo_urls:\n\u001b[0;32m---> 23\u001b[0m transcript, video_info \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_get_bilibili_subs_and_info(url)\n\u001b[1;32m 24\u001b[0m doc \u001b[39m=\u001b[39m Document(page_content\u001b[39m=\u001b[39mtranscript, metadata\u001b[39m=\u001b[39mvideo_info)\n\u001b[1;32m 25\u001b[0m results\u001b[39m.\u001b[39mappend(doc)\n",
46
+ "File \u001b[0;32m~/anaconda3/lib/python3.10/site-packages/langchain/document_loaders/bilibili.py:51\u001b[0m, in \u001b[0;36mBiliBiliLoader._get_bilibili_subs_and_info\u001b[0;34m(self, url)\u001b[0m\n\u001b[1;32m 48\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m 49\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39m{\u001b[39;00murl\u001b[39m}\u001b[39;00m\u001b[39m is not bilibili url.\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[0;32m---> 51\u001b[0m video_info \u001b[39m=\u001b[39m sync(v\u001b[39m.\u001b[39;49mget_info())\n\u001b[1;32m 52\u001b[0m video_info\u001b[39m.\u001b[39mupdate({\u001b[39m\"\u001b[39m\u001b[39murl\u001b[39m\u001b[39m\"\u001b[39m: url})\n\u001b[1;32m 54\u001b[0m \u001b[39m# Get subtitle url\u001b[39;00m\n",
47
+ "File \u001b[0;32m~/anaconda3/lib/python3.10/site-packages/bilibili_api/utils/sync.py:24\u001b[0m, in \u001b[0;36msync\u001b[0;34m(coroutine)\u001b[0m\n\u001b[1;32m 22\u001b[0m __ensure_event_loop()\n\u001b[1;32m 23\u001b[0m loop \u001b[39m=\u001b[39m asyncio\u001b[39m.\u001b[39mget_event_loop()\n\u001b[0;32m---> 24\u001b[0m \u001b[39mreturn\u001b[39;00m loop\u001b[39m.\u001b[39;49mrun_until_complete(coroutine)\n",
48
+ "File \u001b[0;32m~/anaconda3/lib/python3.10/asyncio/base_events.py:625\u001b[0m, in \u001b[0;36mBaseEventLoop.run_until_complete\u001b[0;34m(self, future)\u001b[0m\n\u001b[1;32m 614\u001b[0m \u001b[39m\u001b[39m\u001b[39m\"\"\"Run until the Future is done.\u001b[39;00m\n\u001b[1;32m 615\u001b[0m \n\u001b[1;32m 616\u001b[0m \u001b[39mIf the argument is a coroutine, it is wrapped in a Task.\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 622\u001b[0m \u001b[39mReturn the Future's result, or raise its exception.\u001b[39;00m\n\u001b[1;32m 623\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 624\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_check_closed()\n\u001b[0;32m--> 625\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_check_running()\n\u001b[1;32m 627\u001b[0m new_task \u001b[39m=\u001b[39m \u001b[39mnot\u001b[39;00m futures\u001b[39m.\u001b[39misfuture(future)\n\u001b[1;32m 628\u001b[0m future \u001b[39m=\u001b[39m tasks\u001b[39m.\u001b[39mensure_future(future, loop\u001b[39m=\u001b[39m\u001b[39mself\u001b[39m)\n",
49
+ "File \u001b[0;32m~/anaconda3/lib/python3.10/asyncio/base_events.py:584\u001b[0m, in \u001b[0;36mBaseEventLoop._check_running\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 582\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m_check_running\u001b[39m(\u001b[39mself\u001b[39m):\n\u001b[1;32m 583\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mis_running():\n\u001b[0;32m--> 584\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mRuntimeError\u001b[39;00m(\u001b[39m'\u001b[39m\u001b[39mThis event loop is already running\u001b[39m\u001b[39m'\u001b[39m)\n\u001b[1;32m 585\u001b[0m \u001b[39mif\u001b[39;00m events\u001b[39m.\u001b[39m_get_running_loop() \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[1;32m 586\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mRuntimeError\u001b[39;00m(\n\u001b[1;32m 587\u001b[0m \u001b[39m'\u001b[39m\u001b[39mCannot run the event loop while another loop is running\u001b[39m\u001b[39m'\u001b[39m)\n",
50
+ "\u001b[0;31mRuntimeError\u001b[0m: This event loop is already running"
51
+ ]
52
  }
53
  ],
54
  "source": [
llms_asyncio.py CHANGED
@@ -3,6 +3,7 @@ import asyncio
3
 
4
  from langchain.llms import OpenAI
5
 
 
6
  def generate_serially():
7
  llm = OpenAI(temperature=0.9)
8
  for _ in range(10):
@@ -23,11 +24,12 @@ async def generate_concurrently():
23
 
24
  s = time.perf_counter()
25
  # If running this outside of Jupyter, use asyncio.run(generate_concurrently())
26
- generate_concurrently()
27
  elapsed = time.perf_counter() - s
28
- print('\033[1m' + f"Concurrent executed in {elapsed:0.2f} seconds." + '\033[0m')
 
29
 
30
  s = time.perf_counter()
31
  generate_serially()
32
  elapsed = time.perf_counter() - s
33
- print('\033[1m' + f"Serial executed in {elapsed:0.2f} seconds." + '\033[0m')
 
3
 
4
  from langchain.llms import OpenAI
5
 
6
+
7
  def generate_serially():
8
  llm = OpenAI(temperature=0.9)
9
  for _ in range(10):
 
24
 
25
  s = time.perf_counter()
26
  # If running this outside of Jupyter, use asyncio.run(generate_concurrently())
27
+ generate_concurrently()
28
  elapsed = time.perf_counter() - s
29
+ print('\033[1m' +
30
+ f"Concurrent executed in {elapsed:0.2f} seconds." + '\033[0m')
31
 
32
  s = time.perf_counter()
33
  generate_serially()
34
  elapsed = time.perf_counter() - s
35
+ print('\033[1m' + f"Serial executed in {elapsed:0.2f} seconds." + '\033[0m')
openai_chat_prompt_template.py CHANGED
@@ -15,11 +15,13 @@ human_template = "{text}"
15
  human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)
16
 
17
  # 这里是使用chat请求,返回BaseMessage。
18
- chat_prompt = ChatPromptTemplate.from_messages([system_message_prompt, human_message_prompt])
19
- result = chat(chat_prompt.format_prompt(input_language="中文", output_language="英语", text="我想请假").to_messages())
 
 
20
  print(result.content)
21
 
22
  # 这里是使用chain请求,返回str, 带有聊天模型的chain。
23
  chain = LLMChain(llm=chat, prompt=chat_prompt)
24
  result = chain.run(input_language="中文", output_language="英语", text="我想请假")
25
- print(result)
 
15
  human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)
16
 
17
  # 这里是使用chat请求,返回BaseMessage。
18
+ chat_prompt = ChatPromptTemplate.from_messages(
19
+ [system_message_prompt, human_message_prompt])
20
+ result = chat(chat_prompt.format_prompt(input_language="中文",
21
+ output_language="英语", text="我想请假").to_messages())
22
  print(result.content)
23
 
24
  # 这里是使用chain请求,返回str, 带有聊天模型的chain。
25
  chain = LLMChain(llm=chat, prompt=chat_prompt)
26
  result = chain.run(input_language="中文", output_language="英语", text="我想请假")
27
+ print(result)
redis/test_common.ipynb ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 13,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "import redis\n",
10
+ "\n",
11
+ "conn_pool = redis.ConnectionPool(host='10.254.13.87', port='6379', max_connections=10)"
12
+ ]
13
+ },
14
+ {
15
+ "cell_type": "code",
16
+ "execution_count": 14,
17
+ "metadata": {},
18
+ "outputs": [
19
+ {
20
+ "name": "stdout",
21
+ "output_type": "stream",
22
+ "text": [
23
+ "[b'user', b'test_hello', b'www.biancheng.net', b'test_list', b'test_hash', b'test_set', b'fans:num', b'user:id:01:username']\n"
24
+ ]
25
+ }
26
+ ],
27
+ "source": [
28
+ "r = redis.Redis(connection_pool=conn_pool)\n",
29
+ "key_list = r.keys('*')\n",
30
+ "print(key_list)"
31
+ ]
32
+ },
33
+ {
34
+ "cell_type": "code",
35
+ "execution_count": 15,
36
+ "metadata": {},
37
+ "outputs": [
38
+ {
39
+ "name": "stdout",
40
+ "output_type": "stream",
41
+ "text": [
42
+ "user b'hash'\n",
43
+ "test_hello b'string'\n",
44
+ "www.biancheng.net b'string'\n",
45
+ "test_list b'list'\n",
46
+ "test_hash b'hash'\n",
47
+ "test_set b'set'\n",
48
+ "fans:num b'string'\n",
49
+ "user:id:01:username b'string'\n"
50
+ ]
51
+ }
52
+ ],
53
+ "source": [
54
+ "for key in key_list:\n",
55
+ " keyStr = key.decode()\n",
56
+ " print(keyStr, r.type(keyStr))"
57
+ ]
58
+ },
59
+ {
60
+ "cell_type": "code",
61
+ "execution_count": 19,
62
+ "metadata": {},
63
+ "outputs": [
64
+ {
65
+ "name": "stdout",
66
+ "output_type": "stream",
67
+ "text": [
68
+ "b'hash'\n",
69
+ "1\n",
70
+ "0\n"
71
+ ]
72
+ }
73
+ ],
74
+ "source": [
75
+ "print(r.type('user'))\n",
76
+ "print(r.exists('test_hello'))\n",
77
+ "print(r.exists('user1'))"
78
+ ]
79
+ },
80
+ {
81
+ "cell_type": "code",
82
+ "execution_count": 24,
83
+ "metadata": {},
84
+ "outputs": [
85
+ {
86
+ "name": "stdout",
87
+ "output_type": "stream",
88
+ "text": [
89
+ "0\n",
90
+ "0\n"
91
+ ]
92
+ }
93
+ ],
94
+ "source": [
95
+ "delete_result = r.delete('test_hello', 'test_hell2')\n",
96
+ "print(delete_result)\n",
97
+ "print(r.exists('test_hello'))"
98
+ ]
99
+ }
100
+ ],
101
+ "metadata": {
102
+ "kernelspec": {
103
+ "display_name": "base",
104
+ "language": "python",
105
+ "name": "python3"
106
+ },
107
+ "language_info": {
108
+ "codemirror_mode": {
109
+ "name": "ipython",
110
+ "version": 3
111
+ },
112
+ "file_extension": ".py",
113
+ "mimetype": "text/x-python",
114
+ "name": "python",
115
+ "nbconvert_exporter": "python",
116
+ "pygments_lexer": "ipython3",
117
+ "version": "3.10.10"
118
+ },
119
+ "orig_nbformat": 4
120
+ },
121
+ "nbformat": 4,
122
+ "nbformat_minor": 2
123
+ }
redis/test_string.ipynb ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "import redis\n",
10
+ "\n",
11
+ "r = redis.Redis(host='10.254.13.87', port='6379', db=0)"
12
+ ]
13
+ },
14
+ {
15
+ "cell_type": "code",
16
+ "execution_count": 2,
17
+ "metadata": {},
18
+ "outputs": [
19
+ {
20
+ "name": "stdout",
21
+ "output_type": "stream",
22
+ "text": [
23
+ "b'math'\n"
24
+ ]
25
+ }
26
+ ],
27
+ "source": [
28
+ "r.set('subject', 'math')\n",
29
+ "print(r.get('subject'))"
30
+ ]
31
+ },
32
+ {
33
+ "cell_type": "code",
34
+ "execution_count": 3,
35
+ "metadata": {},
36
+ "outputs": [
37
+ {
38
+ "name": "stdout",
39
+ "output_type": "stream",
40
+ "text": [
41
+ "[b'lizhen', b'123']\n",
42
+ "6\n"
43
+ ]
44
+ }
45
+ ],
46
+ "source": [
47
+ "r.mset({'username': 'lizhen', 'password': '123'})\n",
48
+ "print(r.mget('username', 'password'))\n",
49
+ "print(r.strlen('username'))"
50
+ ]
51
+ },
52
+ {
53
+ "cell_type": "code",
54
+ "execution_count": 7,
55
+ "metadata": {},
56
+ "outputs": [
57
+ {
58
+ "name": "stdout",
59
+ "output_type": "stream",
60
+ "text": [
61
+ "b'18'\n",
62
+ "b'20'\n",
63
+ "b'17'\n",
64
+ "b'18'\n",
65
+ "b'17'\n",
66
+ "19.19999999999999929\n",
67
+ "9.19999999999999929\n"
68
+ ]
69
+ }
70
+ ],
71
+ "source": [
72
+ "r.set('age','18')\n",
73
+ "print(r.get('age'))\n",
74
+ "r.incrby('age', 2)\n",
75
+ "print(r.get('age'))\n",
76
+ "r.decrby('age', 3)\n",
77
+ "print(r.get('age'))\n",
78
+ "r.incr('age')\n",
79
+ "print(r.get('age'))\n",
80
+ "r.decr('age')\n",
81
+ "print(r.get('age'))\n",
82
+ "r.incrbyfloat('age', 2.2)\n",
83
+ "print(r.get('age').decode())\n",
84
+ "r.incrbyfloat('age', -10)\n",
85
+ "print(r.get('age').decode())"
86
+ ]
87
+ }
88
+ ],
89
+ "metadata": {
90
+ "kernelspec": {
91
+ "display_name": "base",
92
+ "language": "python",
93
+ "name": "python3"
94
+ },
95
+ "language_info": {
96
+ "codemirror_mode": {
97
+ "name": "ipython",
98
+ "version": 3
99
+ },
100
+ "file_extension": ".py",
101
+ "mimetype": "text/x-python",
102
+ "name": "python",
103
+ "nbconvert_exporter": "python",
104
+ "pygments_lexer": "ipython3",
105
+ "version": "3.10.10"
106
+ },
107
+ "orig_nbformat": 4
108
+ },
109
+ "nbformat": 4,
110
+ "nbformat_minor": 2
111
+ }
test_csv/test_pandas.ipynb CHANGED
@@ -2,55 +2,97 @@
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
- "execution_count": 4,
6
  "metadata": {},
7
  "outputs": [],
8
  "source": [
9
- "from langchain.document_loaders.csv_loader import CSVLoader\n",
10
- "from langchain.docstore.document import Document"
11
  ]
12
  },
13
  {
14
  "cell_type": "code",
15
- "execution_count": 5,
16
  "metadata": {},
17
  "outputs": [],
18
  "source": [
19
- "loader = CSVLoader(file_path='data/llm_test.csv')\n",
 
 
 
 
 
 
20
  "\n",
21
- "csv = loader.load()"
 
22
  ]
23
  },
24
  {
25
  "cell_type": "code",
26
  "execution_count": 6,
27
  "metadata": {},
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  "outputs": [
29
  {
30
- "ename": "TypeError",
31
- "evalue": "__init__() takes exactly 1 positional argument (3 given)",
32
- "output_type": "error",
33
- "traceback": [
34
- "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
35
- "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
36
- "Cell \u001b[0;32mIn[6], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m new_document \u001b[39m=\u001b[39m Document(\u001b[39m\"\u001b[39;49m\u001b[39mllm test by lizhen\u001b[39;49m\u001b[39m\"\u001b[39;49m, {\u001b[39m\"\u001b[39;49m\u001b[39ma\u001b[39;49m\u001b[39m\"\u001b[39;49m: \u001b[39m\"\u001b[39;49m\u001b[39m1\u001b[39;49m\u001b[39m\"\u001b[39;49m, \u001b[39m\"\u001b[39;49m\u001b[39mb\u001b[39;49m\u001b[39m\"\u001b[39;49m: \u001b[39m\"\u001b[39;49m\u001b[39m2\u001b[39;49m\u001b[39m\"\u001b[39;49m, \u001b[39m\"\u001b[39;49m\u001b[39mc\u001b[39;49m\u001b[39m\"\u001b[39;49m: \u001b[39m\"\u001b[39;49m\u001b[39m3\u001b[39;49m\u001b[39m\"\u001b[39;49m})\n\u001b[1;32m 2\u001b[0m csv\u001b[39m.\u001b[39minsert(new_document)\n",
37
- "File \u001b[0;32m~/anaconda3/lib/python3.10/site-packages/pydantic/main.py:332\u001b[0m, in \u001b[0;36mpydantic.main.BaseModel.__init__\u001b[0;34m()\u001b[0m\n",
38
- "\u001b[0;31mTypeError\u001b[0m: __init__() takes exactly 1 positional argument (3 given)"
39
  ]
40
  }
41
  ],
42
  "source": [
43
- "new_document = Document(page_content='\\ufeff日期: 20230312\\nsn: 703052302050002380\\n是否内测用户: 0\\nquery_sentence: 帮我批改这些练习题\\ndomain: 1000726\\ndomain释义: null\\ndomain_support: 1\\nresult_support: 1\\nintent_support: 1\\nquery_intent: 1\\n: ' metadata={'source': 'data/xbxb.csv', 'row': 0})\n",
44
- "csv.insert(new_document)"
 
 
 
 
 
 
 
45
  ]
46
  },
47
  {
48
  "cell_type": "code",
49
- "execution_count": null,
50
  "metadata": {},
51
- "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
52
  "source": [
53
- "print(data)"
 
54
  ]
55
  }
56
  ],
 
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
+ "execution_count": 1,
6
  "metadata": {},
7
  "outputs": [],
8
  "source": [
9
+ "import pandas as pd"
 
10
  ]
11
  },
12
  {
13
  "cell_type": "code",
14
+ "execution_count": 7,
15
  "metadata": {},
16
  "outputs": [],
17
  "source": [
18
+ "# 定义要写入的数据\n",
19
+ "data = [\n",
20
+ " ['王五', '19', '河北', 'kk']\n",
21
+ "]\n",
22
+ "\n",
23
+ "# 创建DataFrame对象\n",
24
+ "df = pd.DataFrame(data, columns=['name', 'age', 'city', 'mark'])\n",
25
  "\n",
26
+ "# 将DataFrame写入CSV文件\n",
27
+ "df.to_csv('../data/llm_test.csv', index=False, mode='a', header=False)\n"
28
  ]
29
  },
30
  {
31
  "cell_type": "code",
32
  "execution_count": 6,
33
  "metadata": {},
34
+ "outputs": [],
35
+ "source": [
36
+ "# 读取CSV文件到DataFrame\n",
37
+ "df = pd.read_csv('../data/llm_test.csv')\n",
38
+ "# 修改特定行列的数据\n",
39
+ "row_index = 0 # 要修改的行索引,除去表头,从0开始\n",
40
+ "column_name = 'age' # 要修改的列名\n",
41
+ "new_value = '2345' # 修改后的值\n",
42
+ "\n",
43
+ "df.loc[row_index, column_name] = new_value\n",
44
+ "# 将修改后的DataFrame写回到CSV文件\n",
45
+ "df.to_csv('../data/llm_test.csv', index=True)"
46
+ ]
47
+ },
48
+ {
49
+ "cell_type": "code",
50
+ "execution_count": 20,
51
+ "metadata": {},
52
  "outputs": [
53
  {
54
+ "name": "stdout",
55
+ "output_type": "stream",
56
+ "text": [
57
+ "name 2\n",
58
+ "age 2\n",
59
+ "city 2\n",
60
+ "mark 2\n",
61
+ "dtype: int64\n"
 
62
  ]
63
  }
64
  ],
65
  "source": [
66
+ "# 读取CSV文件到DataFrame\n",
67
+ "df = pd.read_csv('../data/llm_test.csv')\n",
68
+ "\n",
69
+ "# 查找满足特定条件的行数据\n",
70
+ "condition = df['age'] == 100 # 以Column1列为例,查找值为'Value1'的行\n",
71
+ "filtered_data = df[condition]\n",
72
+ "\n",
73
+ "# 打印查找结果\n",
74
+ "print(filtered_data)\n"
75
  ]
76
  },
77
  {
78
  "cell_type": "code",
79
+ "execution_count": 4,
80
  "metadata": {},
81
+ "outputs": [
82
+ {
83
+ "name": "stdout",
84
+ "output_type": "stream",
85
+ "text": [
86
+ " name age city mark\n",
87
+ "0 张三 100 河北 kk\n",
88
+ "1 赵四 19 河北 kk\n",
89
+ "2 赵五 100 河北 kk\n"
90
+ ]
91
+ }
92
+ ],
93
  "source": [
94
+ "df = pd.read_csv('../data/llm_test.csv').head(3)\n",
95
+ "print(df)"
96
  ]
97
  }
98
  ],