4 |
--------------------------------------------------------------------------------
/clip-search/README.md:
--------------------------------------------------------------------------------
1 | # CLIP Search
2 | * [使用OpenAI CLIP进行文本到图像和图像到图像的搜索](https://mp.weixin.qq.com/s?__biz=MzkyMTQ5MjYyMg==&mid=2247495123&idx=1&sn=c2932fc2a415a71a2ca60d3b56a651f0&chksm=c1806032f6f7e924035c09d856d052bd60b9c1357ae7bb91e96514c00f583a15310a07b59881&token=260081155&lang=zh_CN#rd)
3 |
4 |
--------------------------------------------------------------------------------
/chromadb_tutorials/pets/Health Care for Pets.txt:
--------------------------------------------------------------------------------
1 | Routine health care is crucial for pets to live long, happy lives. Regular vet check-ups help catch potential issues early and keep vaccinations up to date. Dental care is also essential to prevent diseases in pets, especially in dogs and cats. Regular grooming, parasite control, and weight management are other important aspects of pet health care.
--------------------------------------------------------------------------------
/chromadb_tutorials/pets/Training and Behaviour of Pets.txt:
--------------------------------------------------------------------------------
1 | Training is essential for a harmonious life with pets, particularly for dogs. It helps pets understand their boundaries and makes cohabitation easier for both pets and owners. Training should be based on positive reinforcement. Understanding pet behavior is also important, as changes in behavior can often be a sign of underlying health issues.
--------------------------------------------------------------------------------
/chromadb_tutorials/pets/The Emotional Bond Between Humans and Pets.txt:
--------------------------------------------------------------------------------
1 | Pets offer more than just companionship; they provide emotional support, reduce stress, and can even help their owners lead healthier lives. The bond between pets and their owners is strong, and many people consider their pets as part of the family. This bond can be especially important in times of personal or societal stress, providing comfort and consistency.
--------------------------------------------------------------------------------
/chromadb_tutorials/pets/Different Types of Pet Animals.txt:
--------------------------------------------------------------------------------
1 | Pet animals come in all shapes and sizes, each suited to different lifestyles and home environments. Dogs and cats are the most common, known for their companionship and unique personalities. Small mammals like hamsters, guinea pigs, and rabbits are often chosen for their low maintenance needs. Birds offer beauty and song, and reptiles like turtles and lizards can make intriguing pets. Even fish, with their calming presence, can be wonderful pets.
2 |
--------------------------------------------------------------------------------
/chromadb_tutorials/pets/Nutrition Needs of Pet Animals.txt:
--------------------------------------------------------------------------------
1 | Proper nutrition is vital for the health and wellbeing of pets. Dogs and cats require a balanced diet that includes proteins, carbohydrates, and fats. Some may even have specific dietary needs based on their breed or age. Birds typically thrive on a diet of seeds, fruits, and vegetables, while reptiles have diverse diets ranging from live insects to fresh produce. Fish diets depend greatly on the species, with some needing live food and others subsisting on flakes or pellets.
--------------------------------------------------------------------------------
/langchain-tutorials/LangChain_Chatbot_with_Pinecone/utils.py:
--------------------------------------------------------------------------------
1 | from sentence_transformers import SentenceTransformer
2 | import pinecone
3 | import openai
4 | import streamlit as st
5 | openai.api_key = ""
6 | model = SentenceTransformer('all-MiniLM-L6-v2')
7 |
8 | pinecone.init(api_key='', environment='us-east-1-aws')
9 | index = pinecone.Index('langchain-chatbot')
10 |
11 | def find_match(input):
12 | input_em = model.encode(input).tolist()
13 | result = index.query(input_em, top_k=2, includeMetadata=True)
14 | return result['matches'][0]['metadata']['text']+"\n"+result['matches'][1]['metadata']['text']
15 |
16 | def query_refiner(conversation, query):
17 |
18 | response = openai.Completion.create(
19 | model="text-davinci-003",
20 | prompt=f"给出以下用户查询和对话记录,制定一个最相关的问题,从知识库中为用户提供一个答案.\n\n对话记录: \n{conversation}\n\n用户查询: {query}\n\n优化查询:",
21 | temperature=0.7,
22 | max_tokens=256,
23 | top_p=1,
24 | frequency_penalty=0,
25 | presence_penalty=0
26 | )
27 | return response['choices'][0]['text']
28 |
29 | def get_conversation_string():
30 | conversation_string = ""
31 | for i in range(len(st.session_state['responses'])-1):
32 |
33 | conversation_string += "Human: "+st.session_state['requests'][i] + "\n"
34 | conversation_string += "Bot: "+ st.session_state['responses'][i+1] + "\n"
35 | return conversation_string
36 |
--------------------------------------------------------------------------------
/langchain-tutorials/LangChain_Chatbot_with_Pinecone/main.py:
--------------------------------------------------------------------------------
1 | from langchain.chat_models import ChatOpenAI
2 | from langchain.chains import ConversationChain
3 | from langchain.chains.conversation.memory import ConversationBufferWindowMemory
4 | from langchain.prompts import (
5 | SystemMessagePromptTemplate,
6 | HumanMessagePromptTemplate,
7 | ChatPromptTemplate,
8 | MessagesPlaceholder
9 | )
10 | import streamlit as st
11 | from streamlit_chat import message
12 | from utils import *
13 |
14 | st.subheader("使用Langchain、ChatGPT、Pinecone和Streamlit构建的的聊天机器人")
15 |
16 | if 'responses' not in st.session_state:
17 | st.session_state['responses'] = ["How can I assist you?"]
18 |
19 | if 'requests' not in st.session_state:
20 | st.session_state['requests'] = []
21 |
22 | llm = ChatOpenAI(model_name="gpt-3.5-turbo", openai_api_key="")
23 |
24 | if 'buffer_memory' not in st.session_state:
25 | st.session_state.buffer_memory=ConversationBufferWindowMemory(k=3,return_messages=True)
26 |
27 |
28 | system_msg_template = SystemMessagePromptTemplate.from_template(template="""利用所提供的上下文信息,尽可能真实地回答问题、
29 | 如果答案不在下面的文字中,请说 '我不知道'""")
30 |
31 |
32 | human_msg_template = HumanMessagePromptTemplate.from_template(template="{input}")
33 |
34 | prompt_template = ChatPromptTemplate.from_messages([system_msg_template, MessagesPlaceholder(variable_name="history"), human_msg_template])
35 |
36 | conversation = ConversationChain(memory=st.session_state.buffer_memory, prompt=prompt_template, llm=llm, verbose=True)
37 |
38 |
39 |
40 |
41 | # container for chat history
42 | response_container = st.container()
43 | # container for text box
44 | textcontainer = st.container()
45 |
46 |
47 | with textcontainer:
48 | query = st.text_input("Query: ", key="input")
49 | if query:
50 | with st.spinner("typing..."):
51 | conversation_string = get_conversation_string()
52 | # st.code(conversation_string)
53 | refined_query = query_refiner(conversation_string, query)
54 | st.subheader("Refined Query:")
55 | st.write(refined_query)
56 | context = find_match(refined_query)
57 | # print(context)
58 | response = conversation.predict(input=f"Context:\n {context} \n\n Query:\n{query}")
59 | st.session_state.requests.append(query)
60 | st.session_state.responses.append(response)
61 | with response_container:
62 | if st.session_state['responses']:
63 |
64 | for i in range(len(st.session_state['responses'])):
65 | message(st.session_state['responses'][i],key=str(i))
66 | if i < len(st.session_state['requests']):
67 | message(st.session_state["requests"][i], is_user=True,key=str(i)+ '_user')
68 |
69 |
70 |
--------------------------------------------------------------------------------
/embedding/Generate_Examples_for_Embedding_Training.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "nbformat": 4,
3 | "nbformat_minor": 0,
4 | "metadata": {
5 | "colab": {
6 | "provenance": [],
7 | "include_colab_link": true
8 | },
9 | "kernelspec": {
10 | "name": "python3",
11 | "display_name": "Python 3"
12 | },
13 | "language_info": {
14 | "name": "python"
15 | }
16 | },
17 | "cells": [
18 | {
19 | "cell_type": "markdown",
20 | "metadata": {
21 | "id": "view-in-github",
22 | "colab_type": "text"
23 | },
24 | "source": [
25 | "| \n", 349 | " | title | \n", 350 | "description | \n", 351 | "cluster | \n", 352 | "topic_title | \n", 353 | "
|---|---|---|---|---|
| 11 | \n", 358 | "龙舟竞渡华亭湖!松江区第十三届端午龙舟赛上午开赛_郊野 - 新民网 | \n", 359 | "龙舟竞渡华亭湖!松江区第十三届端午龙舟赛上午开赛_郊野 新民网 | \n", 360 | "1 | \n", 361 | "\"粽情端午:龙舟竞渡、非遗手工技艺和粽子包制活动丰富多彩\" | \n", 362 | "
| 17 | \n", 365 | "端午假期首日长三角铁路迎来客流高峰预计发送旅客340万人次 - 无锡新传媒 | \n", 366 | "端午假期首日长三角铁路迎来客流高峰预计发送旅客340万人次 无锡新传媒 | \n", 367 | "1 | \n", 368 | "\"粽情端午:龙舟竞渡、非遗手工技艺和粽子包制活动丰富多彩\" | \n", 369 | "
| 19 | \n", 372 | "看演出体验非遗手工技艺北京西城端午活动精彩纷呈 - beijing.qianlong.com | \n", 373 | "看演出体验非遗手工技艺北京西城端午活动精彩纷呈 beijing.qianlong.com | \n", 374 | "1 | \n", 375 | "\"粽情端午:龙舟竞渡、非遗手工技艺和粽子包制活动丰富多彩\" | \n", 376 | "
| 24 | \n", 379 | "《颂·黄钟大吕》在国家大剧院音乐厅上演 - China Daily | \n", 380 | "《颂·黄钟大吕》在国家大剧院音乐厅上演 China Daily | \n", 381 | "1 | \n", 382 | "\"粽情端午:龙舟竞渡、非遗手工技艺和粽子包制活动丰富多彩\" | \n", 383 | "
| 27 | \n", 386 | "龙舟竞渡正端午长三角龙舟邀请赛在金山山阳镇举行_新民社会 - 新民网 | \n", 387 | "龙舟竞渡正端午长三角龙舟邀请赛在金山山阳镇举行_新民社会 新民网 | \n", 388 | "1 | \n", 389 | "\"粽情端午:龙舟竞渡、非遗手工技艺和粽子包制活动丰富多彩\" | \n", 390 | "
{paragraph.strip()}
' for paragraph in chapter_content.split('\\n') if paragraph.strip())\n", 167 | "\n", 168 | " epub_chapter.content = f'