forked from srush/MiniChain
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sasha Rush
committed
Mar 14, 2023
1 parent
3f8313b
commit 4f1e85d
Showing
11 changed files
with
170 additions
and
376 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
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. | ||
|
||
{% for d in memory %} | ||
Human: {{d[0]}} | ||
AI: {{d[1]}} | ||
{% endfor %} | ||
|
||
Human: {{human_input}} | ||
Assistant: |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
|
||
|
||
import warnings | ||
from dataclasses import dataclass | ||
from typing import List, Tuple | ||
import minichain | ||
|
||
# + tags=["hide_inp"] | ||
warnings.filterwarnings("ignore") | ||
# - | ||
|
||
|
||
# Generic stateful Memory | ||
|
||
MEMORY = 2 | ||
|
||
@dataclass | ||
class State: | ||
memory: List[Tuple[str, str]] | ||
human_input: str = "" | ||
|
||
def push(self, response: str) -> "State": | ||
memory = self.memory if len(self.memory) < MEMORY else self.memory[1:] | ||
return State(memory + [(self.human_input, response)]) | ||
|
||
# Chat prompt with memory | ||
|
||
class ChatPrompt(minichain.TemplatePrompt): | ||
template_file = "chatgpt.pmpt.tpl" | ||
def parse(self, out: str, inp: State) -> State: | ||
result = out.split("Assistant:")[-1] | ||
return inp.push(result) | ||
|
||
# class Human(minichain.Prompt): | ||
# def parse(self, out: str, inp: State) -> State: | ||
# return inp.human_input = out | ||
|
||
|
||
with minichain.start_chain("chat") as backend: | ||
prompt = ChatPrompt(backend.OpenAI()) | ||
state = State([]) | ||
|
||
|
||
examples = [ | ||
"I want you to act as a Linux terminal. I will type commands and you will reply with what the terminal should show. I want you to only reply with the terminal output inside one unique code block, and nothing else. Do not write explanations. Do not type commands unless I instruct you to do so. When I need to tell you something in English I will do so by putting text inside curly brackets {like this}. My first command is pwd.", | ||
"ls ~", | ||
"cd ~", | ||
"{Please make a file jokes.txt inside and put some jokes inside}", | ||
"""echo -e "x=lambda y:y*5+3;print('Result:' + str(x(6)))" > run.py && python3 run.py""", | ||
"""echo -e "print(list(filter(lambda x: all(x%d for d in range(2,x)),range(2,3**10)))[:10])" > run.py && python3 run.py""", | ||
"""echo -e "echo 'Hello from Docker" > entrypoint.sh && echo -e "FROM ubuntu:20.04\nCOPY entrypoint.sh entrypoint.sh\nENTRYPOINT [\"/bin/sh\",\"entrypoint.sh\"]">Dockerfile && docker build . -t my_docker_image && docker run -t my_docker_image""", | ||
"nvidia-smi" | ||
] | ||
|
||
gradio = prompt.to_gradio(fields= ["human_input"], | ||
initial_state= state, | ||
examples=examples, | ||
out_type="json" | ||
) | ||
if __name__ == "__main__": | ||
gradio.launch() | ||
|
||
# for i in range(len(fake_human)): | ||
# human.chain(prompt) | ||
|
||
|
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
Oops, something went wrong.