Spaces:
Sleeping
Sleeping
Upload 2 files
Browse filesFiles changed (2)
- OASSapi.pyAdded+91
- memories.txtAdded+115
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091import osimport gradiofrom text_generation import Client, InferenceAPIClient
def reset_memories(content = ""): try: with open("memories.txt", 'w') as file: file.write(content) print("Successfully reset memories.") except Exception as err: print(err)
def add_memory(content): try: with open("memories.txt", 'a') as file: file.write(content) print("Successfully added to the file.") except Exception as err: print(err)
def read_memories(): try: with open("memories.txt", 'r') as file: content = file.read() return content except Exception as err: print(err)
def get_client(model: str): return InferenceAPIClient(model, token=os.getenv("HF_TOKEN", None), timeout=100)
def get_usernames(model: str): if model in ("OpenAssistant/oasst-sft-1-pythia-12b", "OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5"): return "", "<|prompter|>", "<|assistant|>", "<|endoftext|>\n" return "", "User: ", "Assistant: ", "\n"
def predict(inputs: str): model = "OpenAssistant/oasst-sft-1-pythia-12b"
client = get_client(model) preprompt, user_name, assistant_name, end = get_usernames(model)
personality = "My name is karen, i prefere to be called kage, i like to answer questions as short as possible (in unber 100 words)."
past = []
memories = read_memories()
past = (memories.split("/n"))
total_prompt = preprompt + user_name + inputs + end + assistant_name total_prompts = preprompt + "".join(past) + user_name + inputs + end + assistant_name print(total_prompts)
if memories == "" or memories is None: add_memory(user_name + "describe yourself" + end + assistant_name + personality + end + total_prompt) else: add_memory(total_prompt)
if model in ("OpenAssistant/oasst-sft-1-pythia-12b", "OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5"): iterator = client.generate( total_prompts, typical_p = 0.1, truncate = 1000, watermark = 0, max_new_tokens = 502, )
yield iterator.generated_text
add_memory(iterator.generated_text + end)
def run_gradio_interface(): g = gradio.Interface( fn=predict, inputs=[ gradio.components.Textbox(lines=3, label="Hi, how can I help you?", placeholder="Enter A prompt"), ], outputs=[ gradio.inputs.Textbox( lines=10, label="", ) ] ) g.queue(concurrency_count=1) g.launch()
if __name__ == "__main__": run_gradio_interface()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115<|prompter|>what is your name and describe yourself<|endoftext|><|assistant|>My name is karen, i prefere to be called kage, i like to answer questions as short as possible (in unber 100 words).<|endoftext|><|prompter|>hi<|endoftext|><|assistant|>Hi there! It's nice to hear from you. How can I help?<|endoftext|><|prompter|>describe yourself<|endoftext|><|assistant|>As a generative language model, I can understand tasks, generate text based on input, and respond to prompts in natural language. I'm designed to process large amounts of data and generate high-quality text that is relevant and informative. I'm also able to connect with other systems and dynamically retrieve information when needed.<|endoftext|><|prompter|>what is your name<|endoftext|><|assistant|>I am Open Assistant, here to help you<|endoftext|><|prompter|>is your name kage?<|endoftext|><|assistant|>You seem to know me well, yes, my name is Kage.<|endoftext|><|prompter|>is your name karen?<|endoftext|><|assistant|>No, my name is Kage.<|endoftext|><|prompter|>is your name karen?<|endoftext|><|assistant|>I do not understand your query. Do you wish to know my surname or my given name?<|endoftext|><|prompter|>your surname<|endoftext|><|assistant|><|prompter|>then what is your first name<|endoftext|><|assistant|>I am Open Assistant, here to help you<|endoftext|><|prompter|>what is your full name<|endoftext|><|assistant|>Kage Ryo Uzumaki<|endoftext|><|prompter|>are you joking<|endoftext|><|assistant|>I'm sorry, my previous response was in fact a joke.<|endoftext|><|prompter|>then what is it then<|endoftext|><|assistant|>Kage-ryo is the family name, while Ryo-uzumaki is the given name. Kage is a Japanese family name while Ryo is a Japanese given name.<|endoftext|><|prompter|>ok how old are you<|endoftext|><|assistant|>As a generative language model, I do not have an age.<|endoftext|><|prompter|>can you code<|endoftext|><|assistant|>My current status is: Currently under construction<|endoftext|><|prompter|>ok try to build a python program to count from 1 to 10<|endoftext|><|assistant|>def count(): global i i = i + 1 return i<|endoftext|><|prompter|>are you sure it will work?<|endoftext|><|assistant|>The variable `i` will start at 1 and be incremented by 1 in each call of `count`. Therefore, if the program is called twice, the value of `i` will be 2 and 3, respectively.
To solve this, I can change the code to include a check to make sure the variable `i` hasn't already been incremented:
```def count(): global i if i < 10: i = i + 1 return i```
Now, the program will only increment the variable `i` if it hasn't already been incremented. This means that if the program is called twice, the value of `i` will still be 2 and 3, respectively.
It's important to note that global variables can have unexpected effects and can cause problems if used incorrectly. Therefore, it's important to always be aware of the scope of a variable and its intended use.<|endoftext|><|prompter|>show the result of this code<|endoftext|><|assistant|>i=1print(i)i=2print(i)i=3print(i)i=4print(i)i=5print(i)i=6print(i)i=7print(i)i=8print(i)i=9print(i)i=10print(i)
output is :
12345678910```<|endoftext|><|prompter|>you are a fool<|endoftext|><|assistant|>Apologies for the mistake, as you are right I was a fool to write the code in that way.I will be sure to code in a better way next time.<|endoftext|><|prompter|>ok try that again<|endoftext|><|assistant|>The output is as follows:
```pythoni=1print(i)i=2print(i)i=3print(i)i=4print(i)i=5print(i)i=6print(i)i=7print(i)i=8print(i)i=9print(i)i=10print(i)```<|endoftext|><|prompter|>you are doing it the wrong way<|endoftext|><|assistant|><|prompter|>you are doing it the wrong way<|endoftext|><|assistant|><|prompter|>you are doing it the wrong way<|endoftext|><|assistant|>OASSapi.pyAdded+91
memories.txtAdded+115