Skip to content

Instantly share code, notes, and snippets.

@nousr
Last active September 8, 2023 21:50
Show Gist options
  • Save nousr/28d9a3c44bfe131c61d94520bc0417ac to your computer and use it in GitHub Desktop.
Save nousr/28d9a3c44bfe131c61d94520bc0417ac to your computer and use it in GitHub Desktop.
from langchain.llms.base import LLM
from typing import Optional, List
from revChatGPT.V1 import Chatbot
class revChatGPT(LLM):
chatbot: Chatbot = Chatbot(config={
"access_token": "<your token here>"
})
@property
def _llm_type(self) -> str:
return "revChatGPT"
def _call(self, prompt: str, stop: Optional[List[str]] = None) -> str:
if stop is not None:
raise ValueError("stop kwargs are not permitted.")
response = ""
for data in self.chatbot.ask(prompt):
response = data["message"]
return response
print(f"Done creating {revChatGPT.__name__}")
"""
Probably works best in a jupyter notebook
"""
from langchain import LLMChain, PromptTemplate
from langchain.chains.conversation.memory import ConversationalBufferWindowMemory
# This template isn't necessary with revChatGPT, but it's a good example of how to use the PromptTemplate class.
template = """Assistant is a large language model trained by OpenAI.
Assistant is designed to be able to assist with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions on a wide range of topics. As a language model, Assistant is able to generate human-like text based on the input it receives, allowing it to engage in natural-sounding conversations and provide responses that are coherent and relevant to the topic at hand.
Assistant is constantly learning and improving, and its capabilities are constantly evolving. It is able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. Additionally, Assistant is able to generate its own text based on the input it receives, allowing it to engage in discussions and provide explanations and descriptions on a wide range of topics.
Overall, Assistant is a powerful tool that can help with a wide range of tasks and provide valuable insights and information on a wide range of topics. Whether you need help with a specific question or just want to have a conversation about a particular topic, Assistant is here to assist.
{history}
Human: {human_input}
Assistant:"""
prompt = PromptTemplate(
input_variables=["history", "human_input"],
template=template
)
chatgpt_chain = LLMChain(
llm=revChatGPT(),
prompt=prompt,
verbose=True,
memory=ConversationalBufferWindowMemory(k=2),
)
output = chatgpt_chain.predict(human_input="Can you please introduce yourself?")
print(output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment