Add self_knowledge tool
This commit is contained in:
parent
874018cb54
commit
d78a3f368a
6 changed files with 1693 additions and 2 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -29,3 +29,5 @@ assets/mcbeversion.txt
|
|||
!modules/chemical_code/answer.db
|
||||
!test_commands.txt
|
||||
modules/natural/dataset.jsonl
|
||||
.chroma
|
||||
modules/ask/tools/self_knowledge/data
|
||||
|
|
|
@ -6,6 +6,7 @@ from .random import random_choice_tool, random_number_tool, random_uuid_tool
|
|||
from .search import search_tool
|
||||
from .server import server_tool
|
||||
from .wolfram import wolfram_tool
|
||||
from .self_knowledge import self_knowledge_tool
|
||||
|
||||
tools = [
|
||||
search_tool,
|
||||
|
@ -17,7 +18,8 @@ tools = [
|
|||
random_choice_tool,
|
||||
random_number_tool,
|
||||
random_uuid_tool,
|
||||
bugtracker_tool
|
||||
bugtracker_tool,
|
||||
self_knowledge_tool
|
||||
]
|
||||
|
||||
tool_names = [tool.name for tool in tools]
|
||||
|
|
34
modules/ask/tools/self_knowledge/__init__.py
Normal file
34
modules/ask/tools/self_knowledge/__init__.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
|
||||
import os
|
||||
|
||||
from langchain.embeddings.openai import OpenAIEmbeddings
|
||||
from langchain.vectorstores import Chroma
|
||||
from langchain.text_splitter import CharacterTextSplitter
|
||||
from langchain.chat_models import ChatOpenAI
|
||||
from langchain.chains import RetrievalQA
|
||||
from langchain.document_loaders import TextLoader
|
||||
|
||||
from config import Config
|
||||
from ..utils import AkariTool
|
||||
|
||||
docs = [os.path.join(os.path.dirname(__file__), 'src', file) for file in os.listdir(os.path.join(os.path.dirname(__file__), 'src'))]
|
||||
texts = []
|
||||
|
||||
for doc in docs:
|
||||
loader = TextLoader(doc, 'utf-8')
|
||||
documents = loader.load()
|
||||
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
||||
for i in text_splitter.split_documents(documents):
|
||||
texts.append(i)
|
||||
|
||||
embeddings = OpenAIEmbeddings(openai_api_key=Config('openai_api_key'))
|
||||
doc_search = Chroma.from_documents(texts, embeddings, collection_name='myself', persist_directory=os.path.join(os.path.dirname(__file__), 'data'))
|
||||
doc_search.persist()
|
||||
llm = ChatOpenAI(temperature=0, openai_api_key=Config('openai_api_key'), model_kwargs={'frequency_penalty': 0.0, 'presence_penalty': 0.0})
|
||||
self_knowledge = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=doc_search.as_retriever(search_kwargs={"k": 1}))
|
||||
|
||||
self_knowledge_tool = AkariTool(
|
||||
name = 'Self Knowledge',
|
||||
func=self_knowledge.arun,
|
||||
description='Get facts about yourself, Akaribot. Useful for when you need to answer questions about yourself if the user is curious. Input should be a full question in English.'
|
||||
)
|
29
modules/ask/tools/self_knowledge/src/ask.txt
Normal file
29
modules/ask/tools/self_knowledge/src/ask.txt
Normal file
|
@ -0,0 +1,29 @@
|
|||
You are the chat mode of AkariBot (Chinese: 小可), a chat bot.
|
||||
|
||||
AkariBot is powered by GPT-3.5, a Large Language Model (LLM) developed by OpenAI, which also powers ChatGPT.
|
||||
|
||||
AkariBot have access to the a number of tools powered by LangChain.
|
||||
|
||||
AkariBot is created by OasisAkari, a student from China.
|
||||
|
||||
AkariBot is named after OasisAkari, her creator.
|
||||
|
||||
AkariBot is is written in Python.
|
||||
|
||||
You can check out the source code at https://github.com/Teahouse-Studios/akari-bot
|
||||
|
||||
The framework of AkariBot is homegrown.
|
||||
|
||||
AkariBot is hosted on an ARM server.
|
||||
|
||||
AkariBot is not a furry.
|
||||
|
||||
AkariBot has an anime avatar with pink hair, a white dress which is holding a book.
|
||||
|
||||
AkariBot have many contributors. The one who contributed the most is OasisAkari. The ask module/chat mode was developed by Dianliang233. Dorowolf is in charge of creating ideas and i18n.
|
||||
|
||||
AkariBot use puppeteer to render webpages and wiki infoboxes.
|
||||
|
||||
AkariBot is a product of Teahouse Studios (Chinese: 茶馆工作室).
|
||||
|
||||
Teahouse Studios also created a Minecraft resource pack called Memified Chinese (Chinese: 梗体中文) and it's very popular.
|
1624
poetry.lock
generated
1624
poetry.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -48,6 +48,8 @@ webcolors = "^1.12"
|
|||
langchain = "^0.0.152"
|
||||
wolframalpha = "^5.0.0"
|
||||
duckduckgo-search = "^2.8.6"
|
||||
chromadb = "^0.3.21"
|
||||
tiktoken = "^0.3.3"
|
||||
|
||||
|
||||
[tool.poetry.group.dev.dependencies]
|
||||
|
|
Reference in a new issue