Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
Sasha Rush committed Mar 14, 2023
1 parent 3f8313b commit 4f1e85d
Show file tree
Hide file tree
Showing 11 changed files with 170 additions and 376 deletions.
8 changes: 5 additions & 3 deletions examples/bash.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ def parse(self, out: str, inp) -> str:
)
prompt = CLIPrompt(backend.OpenAI()).chain(BashPrompt(backend.BashProcess()))


prompt.to_gradio(fields =["question"],
gradio = prompt.to_gradio(fields =["question"],
examples=['Go up one directory, and then into the minichain directory,'
'and list the files in the directory'],
out_type="markdown"

).launch()
)
if __name__ == "__main__":
gradio.launch()



# View the prompts.
Expand Down
15 changes: 15 additions & 0 deletions examples/chat.pmpt.tpl
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:
66 changes: 66 additions & 0 deletions examples/chat.py
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)


7 changes: 5 additions & 2 deletions examples/gatsby.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ class QAPrompt(TemplatePrompt):
# print(result)


prompt.to_gradio(fields=["query"],
examples=["What did Gatsby do before he met Daisy?"]).launch()
gradio = prompt.to_gradio(fields=["query"],
examples=["What did Gatsby do before he met Daisy?"],
keys={"HF_KEY"})
if __name__ == "__main__":
gradio.launch()



Expand Down
Loading

0 comments on commit 4f1e85d

Please sign in to comment.