├── .dockerignore
├── .env.example
├── .gitignore
├── Dockerfile
├── README.md
├── logo.png
├── minichain-ui
├── .gitignore
├── README.md
├── client.py
├── package-lock.json
├── package.json
├── public
│ ├── config.js
│ ├── favicon.ico
│ ├── index.html
│ ├── logo192.png
│ ├── logo512.png
│ ├── manifest.json
│ ├── plotly-latest.min.js
│ └── robots.txt
└── src
│ ├── App.css
│ ├── App.js
│ ├── App.test.js
│ ├── ChatApp.css
│ ├── ChatApp.js
│ ├── ChatMessage.js
│ ├── CodeBlock.js
│ ├── DisplayJson.css
│ ├── DisplayJson.js
│ ├── NewCell.js
│ ├── TextWithCode.js
│ ├── index.css
│ ├── index.js
│ ├── logo.svg
│ ├── reportWebVitals.js
│ └── setupTests.js
├── minichain-vscode
├── README.md
├── extension.js
├── logo.png
├── node_modules
│ └── .package-lock.json
├── package-lock.json
└── package.json
├── minichain
├── agent.py
├── agents
│ ├── agi.py
│ ├── chatgpt.py
│ ├── hippocampus.py
│ ├── memory_agent.prompt
│ ├── memory_agent.py
│ ├── programmer.py
│ ├── replicate_multimodal.py
│ ├── researcher.py
│ └── webgpt.py
├── api.py
├── auth.py
├── default_settings.yml
├── dtypes.py
├── finetune
│ ├── README.md
│ └── traindata.py
├── functions.py
├── memory.py
├── message_handler.py
├── schemas.py
├── settings.py
├── tools
│ ├── bash.py
│ ├── browser.py
│ ├── codebase.py
│ ├── deploy_static.py
│ ├── document_qa.py
│ ├── google_search.py
│ ├── is_prompt_injection.py
│ ├── recursive_summarizer.py
│ ├── replicate_client.py
│ ├── summarize.py
│ ├── taskboard.py
│ └── text_to_memory.py
└── utils
│ ├── README.md
│ ├── cached_openai.py
│ ├── debug.py
│ ├── disk_cache.py
│ ├── document_splitter.py
│ ├── generate_docs.py
│ ├── json_datetime.py
│ ├── markdown_browser.py
│ ├── search.py
│ ├── summarize_history.py
│ └── tokens.py
├── pipeline.sh
├── setup.py
└── test
├── test_chatgpt.py
├── test_disk_cache.py
├── test_google_search.py
├── test_is_prompt_injection.py
├── test_memory.py
├── test_recursive_summarizer.py
├── test_structured_response.py
├── test_text_to_memories.py
└── test_webgpt.py
/.dockerignore:
--------------------------------------------------------------------------------
1 | notes.md
2 | todo.md
3 |
4 | demo/
5 | minichain-vscode/
6 |
7 | .cache/
8 | **/.cache/
9 | # Created by https://www.toptal.com/developers/gitignore/api/python
10 | # Edit at https://www.toptal.com/developers/gitignore?templates=python
11 |
12 | ### Python ###
13 | # Byte-compiled / optimized / DLL files
14 | __pycache__/
15 | *.py[cod]
16 | *$py.class
17 |
18 | # C extensions
19 | *.so
20 |
21 | # Distribution / packaging
22 | .Python
23 | build/
24 | develop-eggs/
25 | dist/
26 | downloads/
27 | eggs/
28 | .eggs/
29 | lib/
30 | lib64/
31 | parts/
32 | sdist/
33 | var/
34 | wheels/
35 | share/python-wheels/
36 | *.egg-info/
37 | .installed.cfg
38 | *.egg
39 | MANIFEST
40 |
41 | # PyInstaller
42 | # Usually these files are written by a python script from a template
43 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
44 | *.manifest
45 | *.spec
46 |
47 | # Installer logs
48 | pip-log.txt
49 | pip-delete-this-directory.txt
50 |
51 | # Unit test / coverage reports
52 | htmlcov/
53 | .tox/
54 | .nox/
55 | .coverage
56 | .coverage.*
57 | .cache
58 | nosetests.xml
59 | coverage.xml
60 | *.cover
61 | *.py,cover
62 | .hypothesis/
63 | .pytest_cache/
64 | cover/
65 |
66 | # Translations
67 | *.mo
68 | *.pot
69 |
70 | # Django stuff:
71 | *.log
72 | local_settings.py
73 | db.sqlite3
74 | db.sqlite3-journal
75 |
76 | # Flask stuff:
77 | instance/
78 | .webassets-cache
79 |
80 | # Scrapy stuff:
81 | .scrapy
82 |
83 | # Sphinx documentation
84 | docs/_build/
85 |
86 | # PyBuilder
87 | .pybuilder/
88 | target/
89 |
90 | # Jupyter Notebook
91 | .ipynb_checkpoints
92 |
93 | # IPython
94 | profile_default/
95 | ipython_config.py
96 |
97 | # pyenv
98 | # For a library or package, you might want to ignore these files since the code is
99 | # intended to run in multiple environments; otherwise, check them in:
100 | # .python-version
101 |
102 | # pipenv
103 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
104 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
105 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
106 | # install all needed dependencies.
107 | #Pipfile.lock
108 |
109 | # poetry
110 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
111 | # This is especially recommended for binary packages to ensure reproducibility, and is more
112 | # commonly ignored for libraries.
113 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
114 | #poetry.lock
115 |
116 | # pdm
117 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
118 | #pdm.lock
119 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
120 | # in version control.
121 | # https://pdm.fming.dev/#use-with-ide
122 | .pdm.toml
123 |
124 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
125 | __pypackages__/
126 |
127 | # Celery stuff
128 | celerybeat-schedule
129 | celerybeat.pid
130 |
131 | # SageMath parsed files
132 | *.sage.py
133 |
134 | # Environments
135 | .env
136 | .venv
137 | env/
138 | venv/
139 | ENV/
140 | env.bak/
141 | venv.bak/
142 |
143 | # Spyder project settings
144 | .spyderproject
145 | .spyproject
146 |
147 | # Rope project settings
148 | .ropeproject
149 |
150 | # mkdocs documentation
151 | /site
152 |
153 | # mypy
154 | .mypy_cache/
155 | .dmypy.json
156 | dmypy.json
157 |
158 | # Pyre type checker
159 | .pyre/
160 |
161 | # pytype static type analyzer
162 | .pytype/
163 |
164 | # Cython debug symbols
165 | cython_debug/
166 |
167 | # PyCharm
168 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
169 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
170 | # and can be added to the global gitignore or merged into this file. For a more nuclear
171 | # option (not recommended) you can uncomment the following to ignore the entire idea folder.
172 | #.idea/
173 |
174 | ### Python Patch ###
175 | # Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
176 | poetry.toml
177 |
178 | # ruff
179 | .ruff_cache/
180 |
181 | # LSP config files
182 | pyrightconfig.json
183 |
184 | # End of https://www.toptal.com/developers/gitignore/api/python
185 | .DS_Store
186 |
187 | .memory
188 |
189 | example.md
190 |
191 | example/
192 |
193 | .minichain
194 |
195 | last_openai_request.json
196 | last*
197 |
198 | *.vsix
199 |
200 | .idea/
201 | **/build/
202 |
203 | .vscode/
204 | Untitled.ipynb
205 | art-portfolio/
206 | examples/
207 | llama_prompt_templates/
208 | music/
209 | portfolio/
210 | sine_plot.png
211 | sine_wave.png
212 | webdesign/
213 | .minichain_old/
214 |
215 |
216 | !minichain-ui/build/
--------------------------------------------------------------------------------
/.env.example:
--------------------------------------------------------------------------------
1 | SERP_API_KEY=your-key-here-for-webgpt
2 | REPLICATE_API_TOKEN=your-key-here-for-artist
3 | OPENAI_API_KEY=your-key-here-for-gpt
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | notes.md
2 | todo.md
3 |
4 | demo/
5 |
6 |
7 | .cache/
8 | **/.cache/
9 | # Created by https://www.toptal.com/developers/gitignore/api/python
10 | # Edit at https://www.toptal.com/developers/gitignore?templates=python
11 |
12 | ### Python ###
13 | # Byte-compiled / optimized / DLL files
14 | __pycache__/
15 | *.py[cod]
16 | *$py.class
17 |
18 | # C extensions
19 | *.so
20 |
21 | # Distribution / packaging
22 | .Python
23 | build/
24 | develop-eggs/
25 | dist/
26 | downloads/
27 | eggs/
28 | .eggs/
29 | lib/
30 | lib64/
31 | parts/
32 | sdist/
33 | var/
34 | wheels/
35 | share/python-wheels/
36 | *.egg-info/
37 | .installed.cfg
38 | *.egg
39 | MANIFEST
40 |
41 | # PyInstaller
42 | # Usually these files are written by a python script from a template
43 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
44 | *.manifest
45 | *.spec
46 |
47 | # Installer logs
48 | pip-log.txt
49 | pip-delete-this-directory.txt
50 |
51 | # Unit test / coverage reports
52 | htmlcov/
53 | .tox/
54 | .nox/
55 | .coverage
56 | .coverage.*
57 | .cache
58 | nosetests.xml
59 | coverage.xml
60 | *.cover
61 | *.py,cover
62 | .hypothesis/
63 | .pytest_cache/
64 | cover/
65 |
66 | # Translations
67 | *.mo
68 | *.pot
69 |
70 | # Django stuff:
71 | *.log
72 | local_settings.py
73 | db.sqlite3
74 | db.sqlite3-journal
75 |
76 | # Flask stuff:
77 | instance/
78 | .webassets-cache
79 |
80 | # Scrapy stuff:
81 | .scrapy
82 |
83 | # Sphinx documentation
84 | docs/_build/
85 |
86 | # PyBuilder
87 | .pybuilder/
88 | target/
89 |
90 | # Jupyter Notebook
91 | .ipynb_checkpoints
92 |
93 | # IPython
94 | profile_default/
95 | ipython_config.py
96 |
97 | # pyenv
98 | # For a library or package, you might want to ignore these files since the code is
99 | # intended to run in multiple environments; otherwise, check them in:
100 | # .python-version
101 |
102 | # pipenv
103 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
104 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
105 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
106 | # install all needed dependencies.
107 | #Pipfile.lock
108 |
109 | # poetry
110 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
111 | # This is especially recommended for binary packages to ensure reproducibility, and is more
112 | # commonly ignored for libraries.
113 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
114 | #poetry.lock
115 |
116 | # pdm
117 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
118 | #pdm.lock
119 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
120 | # in version control.
121 | # https://pdm.fming.dev/#use-with-ide
122 | .pdm.toml
123 |
124 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
125 | __pypackages__/
126 |
127 | # Celery stuff
128 | celerybeat-schedule
129 | celerybeat.pid
130 |
131 | # SageMath parsed files
132 | *.sage.py
133 |
134 | # Environments
135 | .env
136 | .venv
137 | env/
138 | venv/
139 | ENV/
140 | env.bak/
141 | venv.bak/
142 |
143 | # Spyder project settings
144 | .spyderproject
145 | .spyproject
146 |
147 | # Rope project settings
148 | .ropeproject
149 |
150 | # mkdocs documentation
151 | /site
152 |
153 | # mypy
154 | .mypy_cache/
155 | .dmypy.json
156 | dmypy.json
157 |
158 | # Pyre type checker
159 | .pyre/
160 |
161 | # pytype static type analyzer
162 | .pytype/
163 |
164 | # Cython debug symbols
165 | cython_debug/
166 |
167 | # PyCharm
168 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
169 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
170 | # and can be added to the global gitignore or merged into this file. For a more nuclear
171 | # option (not recommended) you can uncomment the following to ignore the entire idea folder.
172 | #.idea/
173 |
174 | ### Python Patch ###
175 | # Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
176 | poetry.toml
177 |
178 | # ruff
179 | .ruff_cache/
180 |
181 | # LSP config files
182 | pyrightconfig.json
183 |
184 | # End of https://www.toptal.com/developers/gitignore/api/python
185 | .DS_Store
186 |
187 | .memory
188 |
189 | example.md
190 |
191 | example/
192 |
193 | .minichain
194 |
195 | last_openai_request.json
196 | last*
197 |
198 | *.vsix
199 |
200 | .idea/
201 | **/build/
202 |
203 | .vscode/
204 | Untitled.ipynb
205 | art-portfolio/
206 | examples/
207 | llama_prompt_templates/
208 | music/
209 | portfolio/
210 | sine_plot.png
211 | sine_wave.png
212 | webdesign/
213 | .minichain_old/
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | # Start with a base image
2 | FROM python:3.11
3 |
4 | # Install dependencies for building Python packages
5 | RUN apt-get update \
6 | && apt-get install -y --no-install-recommends \
7 | build-essential \
8 | libffi-dev \
9 | libssl-dev \
10 | curl
11 |
12 | # Install node via NVM
13 | ENV NVM_DIR /root/.nvm
14 | ENV NODE_VERSION 20.4.0
15 |
16 | RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash \
17 | && . $NVM_DIR/nvm.sh \
18 | && nvm install $NODE_VERSION \
19 | && nvm alias default $NODE_VERSION \
20 | && nvm use default
21 |
22 | # Add node and npm to path so that they're usable
23 | ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
24 |
25 | # Confirm installation
26 | RUN node -v
27 | RUN npm -v
28 |
29 | # Install tree
30 | RUN apt-get install -y tree ffmpeg
31 |
32 | # # # Clean up
33 | # RUN apt-get clean \
34 | # && rm -rf /var/lib/apt/lists/x* /tmp/* /var/tmp/*
35 |
36 | RUN pip install --upgrade pip
37 | RUN pip install numpy pandas matplotlib seaborn plotly scikit-learn requests beautifulsoup4
38 | RUN pip install librosa pydub yt-dlp soundfile
39 |
40 | # install screen
41 | RUN apt-get install -y screen
42 |
43 | RUN pip install moviepy
44 |
45 | # install jupyter
46 | RUN pip install jupyterlab
47 |
48 |
49 | RUN pip install python-jose[cryptography]
50 |
51 | RUN pip install click python-dotenv openai replicate retry google-search-results fastapi pytest pytest-asyncio pylint!=2.5.0 black mypy flake8 pytest-cov httpx playwright requests pydantic docker html2text uvicorn numpy tiktoken uvicorn[standard] python-jose[cryptography]
52 |
53 | WORKDIR /app
54 | # RUN git clone https://github.com/nielsrolf/minichain.git
55 | RUN mkdir minichain
56 | WORKDIR /app/minichain
57 | COPY minichain /app/minichain/minichain
58 | COPY setup.py /app/minichain
59 | RUN pip install -e .
60 | WORKDIR /app
61 |
62 | # Add build files
63 | COPY minichain-ui/ /app/minichain-ui/
64 | WORKDIR /app/minichain-ui
65 | RUN npm ci
66 | RUN apt-get install -y tidy
67 | RUN npm run build
68 | # remove everything but the build folder
69 | RUN find . -maxdepth 1 ! -name 'build' ! -name '.' -exec rm -rf {} +
70 | WORKDIR /app
71 |
72 | # Start minichain api
73 | CMD ["python", "-m", "minichain.api", "--build-dir", "/app/minichain-ui/build"]
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | # minichain
3 |
4 |
5 | Minichain is a framework for LLM agents with structured data, and useful tools for them. It consists of three components
6 | - the [python `minichain` package](#python-package) to build agents that run on the host
7 | - tools that allow agents to run, debug, and edit code, interact with frontend devtools, and a semantic memory creation and retrieval system that allow for infinitely long messages and conversations
8 | - a webui that can be started in [docker](#web-ui) and used as a [vscode extension](#vscode-extension)
9 |
10 | Checkout the [example use cases](#demo)
11 |
12 | # Installation
13 |
14 | If you want to use GPT powered agents as programming assistants in VSCode, install the VSCode extension and the minichain backend via docker.
15 | To develop your own agents, install the python package.
16 |
17 | ## VSCode extension
18 |
19 | The VSCode extension requires you to have a locally running backend - either started via [docker](#web-ui) or via [python](#python-package) - on `http://localhost:8745`.
20 |
21 | You can install the VSCode extension by downloading the `.vsix` file from [releases](https://github.com/nielsrolf/minichain/releases).
22 |
23 | To start the extension, you can open Visual Studio Code, go to the Extensions view (Ctrl+Shift+X), and click on the ... (More Actions) button at the top of the view and select Install from VSIX.... Navigate to the minichain-vscode/ directory, select the .vsix file, and click Install. After the installation, you should be able to use the "Open Minichain" command.
24 |
25 | ## Web-UI
26 | If you want to use the UI (either via browser or with the VSCode extension), run:
27 | ```bash
28 | cp .env.example .env # add your openai, replicate and serp API keys.
29 | docker run -v $(pwd):$(pwd) \
30 | -w $(pwd) -p 20000-21000:20000-21000 -p 8745:8745 \
31 | --env-file .env \
32 | nielsrolf/minichain # optionally: --gpus all
33 | ```
34 |
35 | You can then open minichain on [`http://localhost:8745/index.html`](http://localhost:8745/index.html). You will need the token printed in the beginning of the startup to connect.
36 |
37 | # Demo
38 |
39 | The demos are created using the "Share"-Button that gives read access to a workspace of conversation. In order actually talk to agents, you need to install minichain and use your own OpenAI API key.
40 | - **create and deploy a simple full stack app**: [demo](https://minichain.polybase.app/index.html?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJmcm9udGVuZCIsInNjb3BlcyI6WyIxMmFlMWYyYiIsInZpZXciXX0.GFcoM6lGzx6pK_qBxqs7jPFZxpWhYs99RseLcRUNiek)
41 | - creates a backend
42 | - starts it
43 | - creates a frontend
44 | - tests the frontend using "Chrome Devtools" as a function
45 | - finds and fixes some CORS issues
46 | - fixes the errors
47 | - build and deploy a [simple portfolio website](https://minichain.polybase.app/.public/portfolio): [demo](https://minichain.polybase.app/index.html?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJmcm9udGVuZCIsInNjb3BlcyI6WyIzNDUxNTQ4OSIsInZpZXciXX0.PUS3QWVJQ07MIoLtpfwUgE2mdYTBVx0K07o8C_MHAh0)
48 | - help as a research assistant: [demo](https://minichain.polybase.app/index.html?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJmcm9udGVuZCIsInNjb3BlcyI6WyIzMjMzMTVjOSIsInZpZXciXX0.jPrNeH5tsWXakhALjEPft7Gc81BTS1O_85DMboqPyHQ)
49 | - derive a loss function from an idea
50 | - solve the optimizatin problem using torch
51 | - visualize the results
52 | - make a beautiful 3d plot to demonstrate the jupyter like environment: [demo](https://minichain.polybase.app/index.html?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJmcm9udGVuZCIsInNjb3BlcyI6WyJiOGZkNTRhYiIsInZpZXciXX0.To41pbcUND5Zwba8EVKuUR6-Wr7fWSaiVcxzkSQpQh0)
53 | - working with messages that are longer than the context: [demo](https://minichain.polybase.app/index.html?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJmcm9udGVuZCIsInNjb3BlcyI6WyJiMmYwNGYyMyIsInZpZXciXX0.eG088GxE6g9ib_LW0oCXdhg6-ba7fGPyPUF3U0-fpEY)
54 | - for this example the context size was set to 2k
55 | - the messages is first ingested into semantic memories that can be accessed using the `find_memory` tool
56 |
57 |
58 | [](https://www.youtube.com/watch?v=wxj7qjC8Xb4)
59 |
60 | ## Python package
61 | If you want to build agents, install the python library:
62 | ```bash
63 | pip install git+https://github.com/nielsrolf/minichain
64 | cp .env.example .env # add your openai, replicate and serp API keys.
65 | ```
66 |
67 | It is recommended to run agents inside of docker environments where they have no permission to destroy important things or have access to all secrets. If you feel like taking the risk, you can also run the api on the host via: `python -m minichain.api`.
68 |
69 |
70 |
71 | # Python library
72 | **Why?**
73 | - structured output should be the default. Always converting to text is often a bottleneck
74 | - langchain has too many classes and is generally too big.
75 | - it's fun to build from scratch
76 |
77 | **Core concepts**
78 | The two core concepts are agents and functions that the agent can use. In order to respond, an an agent can use as many function calls as it needs until it uses the built-in return function that returns structured output.
79 | Chat models are agents without structured output and end their turn by responding without a message that is not a function call. They return a string.
80 |
81 |
82 | ## Defining a tool
83 |
84 | Define a tool using the `@tool()` decorator:
85 | ```python
86 | from minichain.agent import Agent, SystemMessage, tool
87 |
88 | @tool()
89 | async def scan_website(
90 | url: str = Field(..., description="The url to read.", ),
91 | question: str = Field(..., description="The question to answer.")
92 | ):
93 | ...
94 | return answer
95 | ```
96 |
97 |
98 | ## Defining an agent
99 | ```python
100 | from minichain.agent import Agent, SystemMessage
101 | from minichain.tools.document_qa import AnswerWithCitations
102 | from minichain.tools.google_search import google_search_function
103 |
104 | ...
105 | webgpt = Agent(
106 | functions=[google_search_function, scan_website],
107 | system_message=SystemMessage(
108 | "You are webgpt. You research by using google search, reading websites, and recalling memories of websites you read. Once you gathered enough information, you end the conversation by answering the question. You cite sources in the answer text as [1], [2] etc."
109 | ),
110 | prompt_template="{query}".format,
111 | response_openapi=AnswerWithCitations, # this is a pydantic.BaseModel
112 | )
113 |
114 | response = await webgpt.run(query="What is the largest publicly known language model in terms of parameters?")
115 | print(response['content'], response['sources'])
116 | ```
117 |
118 | ## Running tests
119 | ```
120 | pytest test
121 | ```
122 |
123 |
--------------------------------------------------------------------------------
/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nielsrolf/minichain/c617b5e1fdc4b65bcc05aca6a11e4c719630e211/logo.png
--------------------------------------------------------------------------------
/minichain-ui/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 |
--------------------------------------------------------------------------------
/minichain-ui/README.md:
--------------------------------------------------------------------------------
1 |
2 | # UI dev setup
3 |
4 | By default, the docker image serves both the bundled frontend and the API. For development, you can also start the api without serving the frontend:
5 | ```
6 | OPENAI_API_KEY=key REPLICATE_API_TOKEN=key python -m minichain.api
7 | ```
8 | And then start the react development server via:
9 | ```
10 | cd minichain-ui
11 | npm install
12 | npm run start
13 | ```
14 |
15 | You will need your [OpenAI GPT-4](https://openai.com) and [Replicate](https://replicate.com) keys in your enviroment variables:
16 |
17 | ### macOS npm install
18 | Install [Brew](https://brew.sh/) if you don't have it already:
19 | ```
20 | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
21 | ```
22 | Install npm [Node.js](https://nodejs.org/en/) if you don't have it already:
23 | ```
24 | brew install npm
25 | ```
26 |
--------------------------------------------------------------------------------
/minichain-ui/client.py:
--------------------------------------------------------------------------------
1 | import asyncio
2 | import json
3 |
4 | import websockets
5 |
6 |
7 | async def heartbeat(websocket):
8 | while True:
9 | await websocket.send(json.dumps({"type": "heartbeat"}))
10 | await asyncio.sleep(1) # Send a heartbeat every 10 seconds.
11 |
12 |
13 | async def websocket_client():
14 | uri = "ws://localhost:8745/ws/webgpt" # Replace with your server URL and agent name
15 |
16 | async with websockets.connect(uri) as websocket:
17 | # Start the heartbeat task
18 | asyncio.create_task(heartbeat(websocket))
19 |
20 | payload = {
21 | "query": "what is the latest post on r/programmerhumor?",
22 | }
23 |
24 | # Send initial payload
25 | await websocket.send(json.dumps(payload))
26 |
27 | try:
28 | while True:
29 | response = await websocket.recv()
30 | print(response)
31 | except websockets.exceptions.ConnectionClosed:
32 | print("The server closed the connection")
33 | except KeyboardInterrupt:
34 | print("Client closed the connection")
35 |
36 |
37 | # Run the client
38 | if __name__ == "__main__":
39 | asyncio.run(websocket_client())
40 |
--------------------------------------------------------------------------------
/minichain-ui/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "minichain-ui",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@emotion/react": "^11.11.1",
7 | "@emotion/styled": "^11.11.0",
8 | "@monaco-editor/react": "^4.6.0",
9 | "@mui/icons-material": "^5.14.12",
10 | "@mui/material": "^5.14.12",
11 | "@mui/styled-engine-sc": "^5.14.12",
12 | "@testing-library/jest-dom": "^5.17.0",
13 | "@testing-library/react": "^13.4.0",
14 | "@testing-library/user-event": "^13.5.0",
15 | "@visx/group": "^3.3.0",
16 | "@visx/mock-data": "^3.3.0",
17 | "@visx/network": "^3.3.0",
18 | "react": "^18.2.0",
19 | "react-dom": "^18.2.0",
20 | "react-force-graph": "^1.43.2",
21 | "react-markdown": "^8.0.7",
22 | "react-scripts": "5.0.1",
23 | "react-syntax-highlighter": "^15.5.0",
24 | "react-use-websocket": "^4.3.1",
25 | "react-websocket": "^2.1.0",
26 | "styled-components": "^5.3.11",
27 | "web-vitals": "^2.1.4",
28 | "websocket": "^1.0.34"
29 | },
30 | "scripts": {
31 | "start": "react-scripts start",
32 | "build": "react-scripts build && (tidy -m -i build/index.html || echo '') && rm -rf ../minichain-vscode/build && cp -r build ../minichain-vscode/",
33 | "test": "react-scripts test",
34 | "eject": "react-scripts eject"
35 | },
36 | "eslintConfig": {
37 | "extends": [
38 | "react-app",
39 | "react-app/jest"
40 | ]
41 | },
42 | "browserslist": {
43 | "production": [
44 | ">0.2%",
45 | "not dead",
46 | "not op_mini all"
47 | ],
48 | "development": [
49 | "last 1 chrome version",
50 | "last 1 firefox version",
51 | "last 1 safari version"
52 | ]
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/minichain-ui/public/config.js:
--------------------------------------------------------------------------------
1 | window.REACT_APP_BACKEND_URL = 'http://localhost:8745';
--------------------------------------------------------------------------------
/minichain-ui/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nielsrolf/minichain/c617b5e1fdc4b65bcc05aca6a11e4c719630e211/minichain-ui/public/favicon.ico
--------------------------------------------------------------------------------
/minichain-ui/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |