Skip to content

Feature/ai translator with chat glm6 b int4 #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ openai_api/data/fine_food_reviews_with_embeddings_1k_2146.csv
# files of Vector Stores, e.g. Chroma
*.pkl
*.bin
*.faiss

langchain/openai-translator/flagged/*
langchain/openai-translator/flask_temps/*
33 changes: 33 additions & 0 deletions langchain/jupyter/homework/panxizhi/AutoGPTWebUI/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import gradio as gr
from run_autogpt import LCAutoGPTRunner

def createAutoGPTUI():

with gr.Blocks() as demo:
#create a text box for user input , label is "Your task:"
#create a button to run the model, label is "Run"
#create a output box to display the output and download result file, label is "Output"
gr.Markdown(
"""
# Hello AutoGPT!
### Type your task in the box below and click "Run" to run the model.
""")
with gr.Row() as row:
task = gr.Textbox(lines=3, label="Your task:", min_width=300)
run = gr.Button(label="Run")
output = gr.File(label="Output")

def run_autoGPT(task):
#run the model and return the result
file = LCAutoGPTRunner().run(task)

return file

run.click(run_autoGPT, inputs=[task], outputs=[output])

demo.launch()



if __name__ == "__main__":
createAutoGPTUI()
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
langchain
langchain_experimental
openai
gradio
google-search-results
58 changes: 58 additions & 0 deletions langchain/jupyter/homework/panxizhi/AutoGPTWebUI/run_autogpt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import os
import uuid
import faiss

from langchain.utilities import SerpAPIWrapper
from langchain.agents import Tool
from langchain.embeddings import OpenAIEmbeddings
from langchain.tools.file_management.write import WriteFileTool
from langchain.tools.file_management.read import ReadFileTool
from langchain.vectorstores import FAISS
from langchain.docstore import InMemoryDocstore
from langchain_experimental.autonomous_agents import AutoGPT
from langchain.chat_models import ChatOpenAI

os.environ["SERPAPI_API_KEY"] = "25409e23ca5020b5264e40a5e3594f50a7ef8ee912a35f86e7ef0fde598dbd7c"

class LCAutoGPTRunner:
agent = None

def __init__(self):
# 构造 AutoGPT 的工具集
search = SerpAPIWrapper()
tools = [
Tool(
name="search",
func=search.run,
description="useful for when you need to answer questions about current events. You should ask targeted questions",
),
WriteFileTool(),
ReadFileTool(),
]

embeddings_model = OpenAIEmbeddings()

# OpenAI Embedding 向量维数
embedding_size = 1536
# 使用 Faiss 的 IndexFlatL2 索引
index = faiss.IndexFlatL2(embedding_size)
# 实例化 Faiss 向量数据库
vectorstore = FAISS(embeddings_model.embed_query, index, InMemoryDocstore({}), {})

agent = AutoGPT.from_llm_and_tools(
ai_name="Jarvis",
ai_role="Assistant",
tools=tools,
llm=ChatOpenAI(temperature=0),
memory=vectorstore.as_retriever(), # 实例化 Faiss 的 VectorStoreRetriever
)
agent.chain.verbose = True
self.agent = agent

def run(self, task):
#run the model and return the result
rand = uuid.uuid4()
tasks = [f'{task} Then write file to "result-{rand}.txt"']
result = self.agent.run(tasks)
print(f'AutoGPT result: {result}')
return f"result-{rand}.txt"
Loading