Building applications with LLMs through composability https://github.com/hwchase17/langchain

liuyuqi-dellpc 5e6a898f12 Merge branch 'master' of https://git.yoqi.me/ai/langchain 1 year ago
docs a3221bd70b 0 1 year ago
README.md b853ee23e5 Update 'README.md' 1 year ago

README.md

langchain

LangChain 为常见应用程序提供标准接口、大量集成和端到端链

文档: https://python.langchain.com/en/latest/ecosystem.html

中文文档:

pip install langchain
pip install openai
from langchain.vectorstores import FAISS
from langchain import HuggingFaceHub
from langchain.docstore import InMemoryDocstore
from langchain import LLMChain, PromptTemplate
from langchain.llms import BaseLLM
from langchain.vectorstores.base import VectorStore
from langchain.chains.base import Chain
from langchain.experimental import BabyAGI


embeddings_model = HuggingFaceEmbedding.newEmbeddingFunction

embedding_size = 1536
index = faiss.IndexFlatL2(embedding_size)

vectorstore = FAISS(embeddings_model, index, InMemoryDocstore({}), {})

verbose = False

int_max_iterations = input("Enter the maximum number of iterations: (Suggest from 3 and 5) ")
max_iterations = int(int_max_iterations)

max_iterations: Optional[int] =   max_iterations
baby_agi = BabyAGI.from_llm(
    llm=llm, vectorstore=vectorstore, verbose=verbose, max_iterations=max_iterations
)

选择 chatgpt或 HuggingChat

from langchain.agents import create_csv_agent
from langchain.utilities import PythonREPL

CG_TOKEN = input("Insert chatgpt token >>> ")
os.environ["CHATGPT_TOKEN"] = CG_TOKEN
start_chat = input("Do you want start a chat from existing chat? (y/n): ") # ask if you want start a chat from existing chat
if start_chat == "y":
    chat_id = input("Insert chat-id (chat.openai.com/c/(IS THIS ->)58XXXX0f-XXXX-XXXX-XXXX-faXXXXd2b50f)  ->") # ask the chat id
    llm= ChatGPTAPI.ChatGPT(token=os.environ["CHATGPT_TOKEN"], conversation=chat_id)
else:
    # llm= ChatGPTAPI.ChatGPT(token=os.environ["CHATGPT_TOKEN"])
    llm=HuggingChatAPI.HuggingChat() 
agent = create_csv_agent(llm=llm, tool=PythonREPL(), path=path_csv, verbose=True)
prompt = input("(Enter your task or question) >> ")
while prompt != "exit":
    agent.run(prompt)
    prompt = input("(Enter your task or question) >> ")