-
-
Save k5trismegistus/30f37f6b6b241667e78894c2bbad7bbf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!pip install llama-index |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import openai | |
from llama_index import GPTVectorStoreIndex, SimpleDirectoryReader | |
openai.api_key = <OpenAIのAPIキー> | |
documents = SimpleDirectoryReader("./data-text").load_data() | |
index = GPTVectorStoreIndex.from_documents(documents) | |
index.storage_context.persist() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, re | |
import openai | |
from llama_index import StorageContext, load_index_from_storage | |
from llama_index.memory import ChatMemoryBuffer | |
openai.api_key = <OpenAIのAPIキー> | |
print("*** myGPT ***") | |
print() | |
memory = ChatMemoryBuffer.from_defaults(token_limit=1500) | |
storage_context = StorageContext.from_defaults(persist_dir="./storage") | |
index = load_index_from_storage(storage_context) | |
chat_engine = index.as_chat_engine( | |
chat_mode="context", | |
memory=memory, | |
system_prompt="You are a chatbot, able to have normal interactions. Replay as the writer of blog '未来世紀アラカワ'", | |
) | |
def insert_newlines(text, line_length): | |
lines = [text[i:i + line_length] for i in range(0, len(text), line_length)] | |
return '\n'.join(lines).lstrip('\n') | |
while True: | |
input_text = input(">") | |
print() | |
if input_text.strip() == "": | |
print("exit...") | |
exit() # プログラムを終了する | |
else: | |
text = str(chat_engine.chat(input_text)) | |
result = insert_newlines(text, 60) | |
print("myGPT>"+result) | |
print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment