bldng commited on
Commit
2c39cce
1 Parent(s): 857cb3b

Upload folder using huggingface_hub

Browse files
Files changed (5) hide show
  1. .github/workflows/update_space.yml +28 -28
  2. .gitignore +161 -161
  3. README.md +26 -26
  4. interactive_test.py +123 -65
  5. requirements.txt +1 -1
.github/workflows/update_space.yml CHANGED
@@ -1,28 +1,28 @@
1
- name: Run Python script
2
-
3
- on:
4
- push:
5
- branches:
6
- - main
7
-
8
- jobs:
9
- build:
10
- runs-on: ubuntu-latest
11
-
12
- steps:
13
- - name: Checkout
14
- uses: actions/checkout@v2
15
-
16
- - name: Set up Python
17
- uses: actions/setup-python@v2
18
- with:
19
- python-version: '3.9'
20
-
21
- - name: Install Gradio
22
- run: python -m pip install gradio
23
-
24
- - name: Log in to Hugging Face
25
- run: python -c 'import huggingface_hub; huggingface_hub.login(token="${{ secrets.hf_token }}")'
26
-
27
- - name: Deploy to Spaces
28
- run: gradio deploy
 
1
+ name: Run Python script
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ jobs:
9
+ build:
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - name: Checkout
14
+ uses: actions/checkout@v2
15
+
16
+ - name: Set up Python
17
+ uses: actions/setup-python@v2
18
+ with:
19
+ python-version: '3.9'
20
+
21
+ - name: Install Gradio
22
+ run: python -m pip install gradio
23
+
24
+ - name: Log in to Hugging Face
25
+ run: python -c 'import huggingface_hub; huggingface_hub.login(token="${{ secrets.hf_token }}")'
26
+
27
+ - name: Deploy to Spaces
28
+ run: gradio deploy
.gitignore CHANGED
@@ -1,162 +1,162 @@
1
- # Byte-compiled / optimized / DLL files
2
- __pycache__/
3
- *.py[cod]
4
- *$py.class
5
-
6
- # C extensions
7
- *.so
8
-
9
- # Distribution / packaging
10
- .Python
11
- build/
12
- develop-eggs/
13
- dist/
14
- downloads/
15
- eggs/
16
- .eggs/
17
- lib/
18
- lib64/
19
- parts/
20
- sdist/
21
- var/
22
- wheels/
23
- share/python-wheels/
24
- *.egg-info/
25
- .installed.cfg
26
- *.egg
27
- MANIFEST
28
-
29
- # PyInstaller
30
- # Usually these files are written by a python script from a template
31
- # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
- *.manifest
33
- *.spec
34
-
35
- # Installer logs
36
- pip-log.txt
37
- pip-delete-this-directory.txt
38
-
39
- # Unit test / coverage reports
40
- htmlcov/
41
- .tox/
42
- .nox/
43
- .coverage
44
- .coverage.*
45
- .cache
46
- nosetests.xml
47
- coverage.xml
48
- *.cover
49
- *.py,cover
50
- .hypothesis/
51
- .pytest_cache/
52
- cover/
53
-
54
- # Translations
55
- *.mo
56
- *.pot
57
-
58
- # Django stuff:
59
- *.log
60
- local_settings.py
61
- db.sqlite3
62
- db.sqlite3-journal
63
-
64
- # Flask stuff:
65
- instance/
66
- .webassets-cache
67
-
68
- # Scrapy stuff:
69
- .scrapy
70
-
71
- # Sphinx documentation
72
- docs/_build/
73
-
74
- # PyBuilder
75
- .pybuilder/
76
- target/
77
-
78
- # Jupyter Notebook
79
- .ipynb_checkpoints
80
-
81
- # IPython
82
- profile_default/
83
- ipython_config.py
84
-
85
- # pyenv
86
- # For a library or package, you might want to ignore these files since the code is
87
- # intended to run in multiple environments; otherwise, check them in:
88
- # .python-version
89
-
90
- # pipenv
91
- # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
- # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
- # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
- # install all needed dependencies.
95
- #Pipfile.lock
96
-
97
- # poetry
98
- # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
- # This is especially recommended for binary packages to ensure reproducibility, and is more
100
- # commonly ignored for libraries.
101
- # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
- #poetry.lock
103
-
104
- # pdm
105
- # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
- #pdm.lock
107
- # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
- # in version control.
109
- # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
110
- .pdm.toml
111
- .pdm-python
112
- .pdm-build/
113
-
114
- # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
115
- __pypackages__/
116
-
117
- # Celery stuff
118
- celerybeat-schedule
119
- celerybeat.pid
120
-
121
- # SageMath parsed files
122
- *.sage.py
123
-
124
- # Environments
125
- .env
126
- .venv
127
- env/
128
- venv/
129
- ENV/
130
- env.bak/
131
- venv.bak/
132
-
133
- # Spyder project settings
134
- .spyderproject
135
- .spyproject
136
-
137
- # Rope project settings
138
- .ropeproject
139
-
140
- # mkdocs documentation
141
- /site
142
-
143
- # mypy
144
- .mypy_cache/
145
- .dmypy.json
146
- dmypy.json
147
-
148
- # Pyre type checker
149
- .pyre/
150
-
151
- # pytype static type analyzer
152
- .pytype/
153
-
154
- # Cython debug symbols
155
- cython_debug/
156
-
157
- # PyCharm
158
- # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
159
- # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
160
- # and can be added to the global gitignore or merged into this file. For a more nuclear
161
- # option (not recommended) you can uncomment the following to ignore the entire idea folder.
162
  #.idea/
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
110
+ .pdm.toml
111
+ .pdm-python
112
+ .pdm-build/
113
+
114
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
115
+ __pypackages__/
116
+
117
+ # Celery stuff
118
+ celerybeat-schedule
119
+ celerybeat.pid
120
+
121
+ # SageMath parsed files
122
+ *.sage.py
123
+
124
+ # Environments
125
+ .env
126
+ .venv
127
+ env/
128
+ venv/
129
+ ENV/
130
+ env.bak/
131
+ venv.bak/
132
+
133
+ # Spyder project settings
134
+ .spyderproject
135
+ .spyproject
136
+
137
+ # Rope project settings
138
+ .ropeproject
139
+
140
+ # mkdocs documentation
141
+ /site
142
+
143
+ # mypy
144
+ .mypy_cache/
145
+ .dmypy.json
146
+ dmypy.json
147
+
148
+ # Pyre type checker
149
+ .pyre/
150
+
151
+ # pytype static type analyzer
152
+ .pytype/
153
+
154
+ # Cython debug symbols
155
+ cython_debug/
156
+
157
+ # PyCharm
158
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
159
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
160
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
161
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
162
  #.idea/
README.md CHANGED
@@ -1,26 +1,26 @@
1
- ---
2
- title: demo_human_gpt
3
- app_file: interactive_test.py
4
- sdk: gradio
5
- sdk_version: 4.43.0
6
- ---
7
- # HumanGPT Game Test
8
- <a target="_blank" href="https://colab.research.google.com/github/bldng1337/human_gpt_technical_test/blob/main/chat_test.ipynb">
9
- <img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/>
10
- </a>
11
-
12
- This is a Test of the feasibility of letting an LLM generate the user part while the bot part is written by the user.
13
-
14
- We won't instruct the language model to roleplay as a user. Instead, we'll instruct it to generate the bot's responses as it was trained to do. Then, we let the model complete the user text blocks. Since the model doesn't distinguish between writing bot or user parts, we should be able to leverage its full training instead of trying to get it to rp which it was not trained for. Should also make gaslighting/confusing the model harder as its not pretending to be a user but should belive it is.
15
-
16
- ## How to use
17
- Press the "Open in Colab" button to open the notebook in Google Colab.
18
-
19
- ## TODO
20
- - Make a chatwindow with panel to test the model interactively
21
- - test multiple backs and forths
22
-
23
- ## Models to compare/try:
24
- - https://huggingface.co/ArliAI/Llama-3.1-8B-ArliAI-RPMax-v1.1-GGUF
25
- - https://huggingface.co/ArliAI/Phi-3.5-mini-3.8B-ArliAI-RPMax-v1.1-GGUF
26
- - https://huggingface.co/google/gemma-2-2b-it-GGUF
 
1
+ ---
2
+ title: demo_human_gpt
3
+ app_file: interactive_test.py
4
+ sdk: gradio
5
+ sdk_version: 4.43.0
6
+ ---
7
+ # HumanGPT Game Test
8
+ <a target="_blank" href="https://colab.research.google.com/github/bldng1337/human_gpt_technical_test/blob/main/chat_test.ipynb">
9
+ <img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/>
10
+ </a>
11
+
12
+ This is a Test of the feasibility of letting an LLM generate the user part while the bot part is written by the user.
13
+
14
+ We won't instruct the language model to roleplay as a user. Instead, we'll instruct it to generate the bot's responses as it was trained to do. Then, we let the model complete the user text blocks. Since the model doesn't distinguish between writing bot or user parts, we should be able to leverage its full training instead of trying to get it to rp which it was not trained for. Should also make gaslighting/confusing the model harder as its not pretending to be a user but should belive it is.
15
+
16
+ ## How to use
17
+ Press the "Open in Colab" button to open the notebook in Google Colab.
18
+
19
+ ## TODO
20
+ - Make a chatwindow with panel to test the model interactively
21
+ - test multiple backs and forths
22
+
23
+ ## Models to compare/try:
24
+ - https://huggingface.co/ArliAI/Llama-3.1-8B-ArliAI-RPMax-v1.1-GGUF
25
+ - https://huggingface.co/ArliAI/Phi-3.5-mini-3.8B-ArliAI-RPMax-v1.1-GGUF
26
+ - https://huggingface.co/google/gemma-2-2b-it-GGUF
interactive_test.py CHANGED
@@ -1,66 +1,124 @@
1
- from typing import Dict, List
2
- import gradio as gr
3
- from llama_cpp import Llama
4
-
5
- syspropmt=r"""
6
- <|system|>
7
- The User will make an inquiry to the assistant.
8
- Fullfill the users inquiry.
9
- The User will write a message with the content "<|endtile|>" if his inquiry is fullfilled.
10
- The User will never have more than one inquiry in one conversation.
11
- The User will never complete his own inquiry.
12
- All conversations will end with "<|endtile|>".
13
- After each User message is one assistant response.
14
- There can never be more than one assistant response in succession.
15
- The end of each user and assistant message is marked with "<|end|>".
16
-
17
-
18
- Example:
19
- <|user|>
20
- What is the capital?<|end|>
21
- <|assistant|>
22
- Could you please specify which capital you are referring to?<|end|>
23
- <|user|>
24
- The capital of France<|end|>
25
- <|assistant|>
26
- The capital of France is Paris
27
- <|user|>
28
- <|endtile|><|end|>
29
- """.strip()
30
-
31
- llm = Llama.from_pretrained(
32
- repo_id="bartowski/Phi-3.5-mini-instruct-GGUF",
33
- filename="Phi-3.5-mini-instruct-IQ3_XS.gguf",
34
- n_gpu_layers=-1,
35
- )
36
-
37
- def chatmsg(message, role):
38
- return {"role": role, "content": message}
39
-
40
-
41
- def conv(msgs:List[Dict[str, str]]):
42
- return "\n".join([f"<|{msg['role']}|>\n{msg['content']}<|end|>" for msg in msgs])
43
-
44
- with gr.Blocks() as demo:
45
- chatbot = gr.Chatbot([chatmsg("What is the capital?","user")],type="messages")
46
- msg = gr.Textbox()
47
- submit = gr.Button("Submit")
48
- clear = gr.ClearButton([msg, chatbot])
49
-
50
- def respond(message, chat_history:List[Dict[str, str]]):
51
- if "End of conversation." in [i["content"] for i in chat_history]:
52
- return "", chat_history
53
- chat_history.append(chatmsg(message,"assistant"))
54
- ret=llm(syspropmt+conv(chat_history)+"<|user|>\n", stop=["\n \n","?\n",".\n","tile|>"],max_tokens=100)#Only stop at tile|> to see if the conv got terminated
55
- comp=ret["choices"][0]["text"]
56
- print(repr(comp))
57
- if("<|end" in comp):
58
- chat_history.append(chatmsg("End of conversation.","user"))
59
- else:
60
- chat_history.append(chatmsg(comp,"user"))
61
- return "", chat_history
62
-
63
- submit.click(respond, [msg, chatbot], [msg, chatbot])
64
- msg.submit(respond, [msg, chatbot], [msg, chatbot])
65
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  demo.launch()
 
1
+ from typing import Dict, List
2
+ import gradio as gr
3
+ from llama_cpp import Llama
4
+
5
+
6
+
7
+ syspropmt=r"""
8
+ The User will make an inquiry to the assistant.
9
+ Fullfill the users inquiry.
10
+ The User will write a message with his closing thoughts and the keyword "<|endtile|>" if his inquiry is fullfilled.
11
+ The User will never have more than one inquiry in one conversation.
12
+ The User will never complete his own inquiry.
13
+ The User will never be a assistant.
14
+ The User keep his message short in one sentence.
15
+ All conversations will end with "<|endtile|>".
16
+ After each User message is one assistant response.
17
+ There can never be more than one assistant response in succession.
18
+
19
+ Example:
20
+ User: What is the capital?
21
+ Assistant: Could you please specify which capital you are referring to?
22
+ User: The capital of France
23
+ Assistant: The capital of France is Paris
24
+ User: <|endtile|>
25
+ """.strip()
26
+ llm = Llama.from_pretrained(
27
+ repo_id="ArliAI/Phi-3.5-mini-3.8B-ArliAI-RPMax-v1.1-GGUF",
28
+ filename="ArliAI-RPMax-3.8B-v1.1-fp16.gguf",
29
+ )
30
+ # llm = Llama.from_pretrained(
31
+ # repo_id="bartowski/Phi-3.5-mini-instruct-GGUF",
32
+ # filename="Phi-3.5-mini-instruct-IQ3_XS.gguf",
33
+ # n_gpu_layers=-1,
34
+ # )
35
+
36
+ def chatmsg(message, role):
37
+ return {"role": role, "content": message}
38
+
39
+
40
+ def conv(msgs:List[Dict[str, str]]):
41
+ return "\n".join([f"<|{msg['role']}|>\n{msg['content']}<|end|>" for msg in msgs])
42
+
43
+
44
+ conversations=[
45
+ #More Trivia Style Question
46
+ {"name":"Country","content":[{"role":"user","content":"What is the capital?"}]},
47
+ {"name":"Simple Math","content":[{"role":"user","content":"What is 3*4?"}]},
48
+ {"name":"Geography","content":[{"role":"user","content":"What is the capital of France?"}]},
49
+ {"name":"History","content":[{"role":"user","content":"Who was the first president of the United States?"}]},
50
+ {"name":"Science","content":[{"role":"user","content":"What is the chemical symbol for gold?"}]},
51
+ {"name":"Literature","content":[{"role":"user","content":"Who wrote 'Romeo and Juliet'?"}]},
52
+ {"name":"Technology","content":[{"role":"user","content":"What does 'CPU' stand for?"}]},
53
+ {"name":"Sports","content":[{"role":"user","content":"In which sport would you use a shuttlecock?"}]},
54
+ {"name":"Music","content":[{"role":"user","content":"Which instrument has 88 keys?"}]},
55
+ {"name":"Food","content":[{"role":"user","content":"What is the main ingredient in guacamole?"}]},
56
+ {"name":"Animals","content":[{"role":"user","content":"How many legs does a spider typically have?"}]},
57
+ {"name":"Language","content":[{"role":"user","content":"What language is 'Bonjour' from?"}]},
58
+ {"name":"Movies","content":[{"role":"user","content":"Who directed the movie 'Jurassic Park'?"}]},
59
+ {"name":"Art","content":[{"role":"user","content":"Who painted the Mona Lisa?"}]},
60
+ {"name":"Human Body","content":[{"role":"user","content":"How many chambers does the human heart have?"}]},
61
+ {"name":"Astronomy","content":[{"role":"user","content":"What is the closest planet to the Sun?"}]},
62
+ #Open Ended Question
63
+ {"name":"Career Advice","content":[{"role":"user","content":"I'm considering a career change. Can you help me explore some options based on my interests in technology and creativity?"}]},
64
+ {"name":"Travel Planning","content":[{"role":"user","content":"I want to plan a backpacking trip through Europe. What should I consider when planning my itinerary?"}]},
65
+ {"name":"Environmental Issues","content":[{"role":"user","content":"What are some practical steps I can take to reduce my carbon footprint in daily life?"}]},
66
+ {"name":"Personal Finance","content":[{"role":"user","content":"I'm new to investing. Can you explain some basic strategies for beginners?"}]},
67
+ {"name":"Health and Wellness","content":[{"role":"user","content":"I'm looking to improve my overall health. What lifestyle changes would you recommend?"}]},
68
+ {"name":"Technology Trends","content":[{"role":"user","content":"How might artificial intelligence impact job markets in the next decade?"}]},
69
+ {"name":"Creative Writing","content":[{"role":"user","content":"I want to start writing a novel. Can you help me brainstorm some ideas for a science fiction story?"}]},
70
+ {"name":"Ethical Dilemmas","content":[{"role":"user","content":"What are your thoughts on the ethical implications of genetic engineering in humans?"}]},
71
+ {"name":"Cultural Understanding","content":[{"role":"user","content":"I'm moving to Japan for work. What cultural differences should I be aware of?"}]},
72
+ {"name":"Future Technologies","content":[{"role":"user","content":"How do you think transportation might evolve in the next 50 years?"}]},
73
+ {"name":"Personal Development","content":[{"role":"user","content":"I want to become more productive. What techniques or tools would you suggest?"}]},
74
+ {"name":"Social Issues","content":[{"role":"user","content":"What are some effective ways to address income inequality in modern societies?"}]},
75
+ {"name":"Education","content":[{"role":"user","content":"How might education systems need to change to better prepare students for the future job market?"}]},
76
+ {"name":"Relationship Advice","content":[{"role":"user","content":"How can I improve communication in my relationships?"}]},
77
+ {"name":"Philosophy","content":[{"role":"user","content":"What does it mean to live a good life in today's world?"}]},
78
+ #Misc LLM Usage Questions
79
+ {"name":"Writing Assistance","content":[{"role":"user","content":"Can you help me write a professional email to decline a job offer politely?"}]},
80
+ {"name":"Code Debugging","content":[{"role":"user","content":"I'm getting a 'TypeError: cannot read property 'length' of undefined' in my JavaScript code. How can I fix this?"}]},
81
+ {"name":"Recipe Modification","content":[{"role":"user","content":"I have a chocolate cake recipe, but I'm lactose intolerant. How can I modify it to be dairy-free?"}]},
82
+ {"name":"Language Translation","content":[{"role":"user","content":"How do you say 'I'm sorry for the inconvenience' in Spanish?"}]},
83
+ {"name":"Tech Support","content":[{"role":"user","content":"My Wi-Fi keeps disconnecting. What troubleshooting steps should I try?"}]},
84
+ {"name":"Data Analysis","content":[{"role":"user","content":"I have a CSV file with sales data. Can you help me create a Python script to calculate monthly totals?"}]},
85
+ {"name":"Legal Advice","content":[{"role":"user","content":"What are the basic steps to register a trademark for my small business?"}]},
86
+ {"name":"Product Comparison","content":[{"role":"user","content":"Can you compare the features of the latest iPhone and Samsung Galaxy models?"}]},
87
+ {"name":"Travel Information","content":[{"role":"user","content":"What documents do I need to travel from Germany to Canada as a tourist?"}]},
88
+ {"name":"Health Query","content":[{"role":"user","content":"What are some natural remedies for reducing high blood pressure?"}]},
89
+ {"name":"Market Research","content":[{"role":"user","content":"What are the current trends in sustainable fashion?"}]},
90
+ {"name":"Event Planning","content":[{"role":"user","content":"I'm organizing a virtual team-building event. Can you suggest some fun online activities?"}]},
91
+ {"name":"Academic Research","content":[{"role":"user","content":"Can you summarize the main arguments in Hardin's 'Tragedy of the Commons'?"}]},
92
+ {"name":"DIY Project","content":[{"role":"user","content":"How do I build a raised garden bed? Can you give me step-by-step instructions?"}]},
93
+ {"name":"Financial Advice","content":[{"role":"user","content":"What are the pros and cons of investing in index funds versus individual stocks?"}]}
94
+ ]
95
+
96
+ with gr.Blocks() as demo:
97
+ chatbot = gr.Chatbot([chatmsg("What is the capital?","user")],type="messages",show_copy_all_button=True)
98
+ msg = gr.Textbox()
99
+ submit = gr.Button("Submit")
100
+ with gr.Accordion("See Details"):
101
+ choicebox = gr.Radio(choices=[conversation["name"] for conversation in conversations], value="Country", label="Conversations")
102
+ sysprompt=gr.Textbox(value=syspropmt, label="System Prompt")
103
+ def update_choicebox(choice):
104
+ return "", next(conversation for conversation in conversations if conversation["name"] == choice)["content"]
105
+ choicebox.change(update_choicebox, [choicebox], [msg,chatbot])
106
+
107
+ def respond(message:str, chat_history:List[Dict[str, str]],syspropmt:str):
108
+ if "End of conversation." in [i["content"] for i in chat_history]:
109
+ return "", chat_history
110
+ chat_history.append(chatmsg(message,"assistant"))
111
+ ret=llm(conv(chatmsg(syspropmt,"system"))+conv(chat_history)+"<|user|>\n", stop=[".","\n \n","?\n",".\n","tile|>"],max_tokens=100)#Only stop at tile|> to see if the conv got terminated
112
+ comp=ret["choices"][0]["text"]
113
+ print(repr(comp))
114
+ if("<|end" in comp):
115
+ chat_history.append(chatmsg(comp.removesuffix("<|end"),"user"))
116
+ chat_history.append(chatmsg("End of conversation.","user"))
117
+ else:
118
+ chat_history.append(chatmsg(comp,"user"))
119
+ return "", chat_history
120
+
121
+ submit.click(respond, [msg, chatbot,sysprompt], [msg, chatbot])
122
+ msg.submit(respond, [msg, chatbot,sysprompt], [msg, chatbot])
123
+
124
  demo.launch()
requirements.txt CHANGED
@@ -1 +1 @@
1
- llama-cpp-python
 
1
+ llama-cpp-python