Spaces:
Sleeping
Sleeping
Leo
commited on
Commit
·
40cef76
1
Parent(s):
ae7baed
Inital upload of working files
Browse files- .dockerignore +20 -0
- .env.sample +1 -0
- .gitignore +164 -0
- Dockerfile +42 -0
- README.md +69 -8
- app.py +94 -0
- chainlit.md +13 -0
- pyproject.toml +14 -0
- uv.lock +0 -0
.dockerignore
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Prevent secrets and junk from being baked into Docker images
|
| 2 |
+
|
| 3 |
+
# Secrets
|
| 4 |
+
.env
|
| 5 |
+
.env.*
|
| 6 |
+
|
| 7 |
+
# macOS junk
|
| 8 |
+
.DS_Store
|
| 9 |
+
|
| 10 |
+
# Python cache
|
| 11 |
+
__pycache__/
|
| 12 |
+
*.py[cod]
|
| 13 |
+
|
| 14 |
+
# Virtual environments
|
| 15 |
+
.venv/
|
| 16 |
+
venv/
|
| 17 |
+
|
| 18 |
+
# Git stuff (optional)
|
| 19 |
+
.git
|
| 20 |
+
.gitignore
|
.env.sample
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
OPENAI_API_KEY=###
|
.gitignore
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Byte-compiled / optimized / DLL files
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.py[cod]
|
| 4 |
+
*$py.class
|
| 5 |
+
|
| 6 |
+
# C extensions
|
| 7 |
+
*.so
|
| 8 |
+
|
| 9 |
+
# more stuff Leo
|
| 10 |
+
.DS_Store
|
| 11 |
+
|
| 12 |
+
# Distribution / packaging
|
| 13 |
+
.Python
|
| 14 |
+
build/
|
| 15 |
+
develop-eggs/
|
| 16 |
+
dist/
|
| 17 |
+
downloads/
|
| 18 |
+
eggs/
|
| 19 |
+
.eggs/
|
| 20 |
+
lib/
|
| 21 |
+
lib64/
|
| 22 |
+
parts/
|
| 23 |
+
sdist/
|
| 24 |
+
var/
|
| 25 |
+
wheels/
|
| 26 |
+
share/python-wheels/
|
| 27 |
+
*.egg-info/
|
| 28 |
+
.installed.cfg
|
| 29 |
+
*.egg
|
| 30 |
+
MANIFEST
|
| 31 |
+
.chainlit/
|
| 32 |
+
|
| 33 |
+
# PyInstaller
|
| 34 |
+
# Usually these files are written by a python script from a template
|
| 35 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
| 36 |
+
*.manifest
|
| 37 |
+
*.spec
|
| 38 |
+
|
| 39 |
+
# Installer logs
|
| 40 |
+
pip-log.txt
|
| 41 |
+
pip-delete-this-directory.txt
|
| 42 |
+
|
| 43 |
+
# Unit test / coverage reports
|
| 44 |
+
htmlcov/
|
| 45 |
+
.tox/
|
| 46 |
+
.nox/
|
| 47 |
+
.coverage
|
| 48 |
+
.coverage.*
|
| 49 |
+
.cache
|
| 50 |
+
nosetests.xml
|
| 51 |
+
coverage.xml
|
| 52 |
+
*.cover
|
| 53 |
+
*.py,cover
|
| 54 |
+
.hypothesis/
|
| 55 |
+
.pytest_cache/
|
| 56 |
+
cover/
|
| 57 |
+
|
| 58 |
+
# Translations
|
| 59 |
+
*.mo
|
| 60 |
+
*.pot
|
| 61 |
+
|
| 62 |
+
# Django stuff:
|
| 63 |
+
*.log
|
| 64 |
+
local_settings.py
|
| 65 |
+
db.sqlite3
|
| 66 |
+
db.sqlite3-journal
|
| 67 |
+
|
| 68 |
+
# Flask stuff:
|
| 69 |
+
instance/
|
| 70 |
+
.webassets-cache
|
| 71 |
+
|
| 72 |
+
# Scrapy stuff:
|
| 73 |
+
.scrapy
|
| 74 |
+
|
| 75 |
+
# Sphinx documentation
|
| 76 |
+
docs/_build/
|
| 77 |
+
|
| 78 |
+
# PyBuilder
|
| 79 |
+
.pybuilder/
|
| 80 |
+
target/
|
| 81 |
+
|
| 82 |
+
# Jupyter Notebook
|
| 83 |
+
.ipynb_checkpoints
|
| 84 |
+
|
| 85 |
+
# IPython
|
| 86 |
+
profile_default/
|
| 87 |
+
ipython_config.py
|
| 88 |
+
|
| 89 |
+
# pyenv
|
| 90 |
+
# For a library or package, you might want to ignore these files since the code is
|
| 91 |
+
# intended to run in multiple environments; otherwise, check them in:
|
| 92 |
+
# .python-version
|
| 93 |
+
|
| 94 |
+
# pipenv
|
| 95 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
| 96 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
| 97 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
| 98 |
+
# install all needed dependencies.
|
| 99 |
+
#Pipfile.lock
|
| 100 |
+
|
| 101 |
+
# poetry
|
| 102 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
| 103 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
| 104 |
+
# commonly ignored for libraries.
|
| 105 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
| 106 |
+
#poetry.lock
|
| 107 |
+
|
| 108 |
+
# pdm
|
| 109 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
| 110 |
+
#pdm.lock
|
| 111 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
| 112 |
+
# in version control.
|
| 113 |
+
# https://pdm.fming.dev/#use-with-ide
|
| 114 |
+
.pdm.toml
|
| 115 |
+
|
| 116 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
| 117 |
+
__pypackages__/
|
| 118 |
+
|
| 119 |
+
# Celery stuff
|
| 120 |
+
celerybeat-schedule
|
| 121 |
+
celerybeat.pid
|
| 122 |
+
|
| 123 |
+
# SageMath parsed files
|
| 124 |
+
*.sage.py
|
| 125 |
+
|
| 126 |
+
# Environments
|
| 127 |
+
.env
|
| 128 |
+
.venv
|
| 129 |
+
env/
|
| 130 |
+
venv/
|
| 131 |
+
ENV/
|
| 132 |
+
env.bak/
|
| 133 |
+
venv.bak/
|
| 134 |
+
|
| 135 |
+
# Spyder project settings
|
| 136 |
+
.spyderproject
|
| 137 |
+
.spyproject
|
| 138 |
+
|
| 139 |
+
# Rope project settings
|
| 140 |
+
.ropeproject
|
| 141 |
+
|
| 142 |
+
# mkdocs documentation
|
| 143 |
+
/site
|
| 144 |
+
|
| 145 |
+
# mypy
|
| 146 |
+
.mypy_cache/
|
| 147 |
+
.dmypy.json
|
| 148 |
+
dmypy.json
|
| 149 |
+
|
| 150 |
+
# Pyre type checker
|
| 151 |
+
.pyre/
|
| 152 |
+
|
| 153 |
+
# pytype static type analyzer
|
| 154 |
+
.pytype/
|
| 155 |
+
|
| 156 |
+
# Cython debug symbols
|
| 157 |
+
cython_debug/
|
| 158 |
+
|
| 159 |
+
# PyCharm
|
| 160 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
| 161 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
| 162 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
| 163 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
| 164 |
+
#.idea/
|
Dockerfile
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Get a distribution that has uv already installed
|
| 2 |
+
FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim
|
| 3 |
+
|
| 4 |
+
# Add Rust compiler installation
|
| 5 |
+
USER root
|
| 6 |
+
RUN apt-get update && apt-get install -y \
|
| 7 |
+
curl \
|
| 8 |
+
build-essential \
|
| 9 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 10 |
+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
|
| 11 |
+
ENV PATH="/root/.cargo/bin:${PATH}"
|
| 12 |
+
|
| 13 |
+
# Add user - this is the user that will run the app
|
| 14 |
+
# If you do not set user, the app will run as root (undesirable)
|
| 15 |
+
RUN useradd -m -u 1000 user
|
| 16 |
+
USER user
|
| 17 |
+
|
| 18 |
+
# Set up Rust for the user
|
| 19 |
+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
|
| 20 |
+
ENV PATH="/home/user/.cargo/bin:${PATH}"
|
| 21 |
+
|
| 22 |
+
# Set the home directory and path
|
| 23 |
+
ENV HOME=/home/user \
|
| 24 |
+
PATH=/home/user/.local/bin:$PATH
|
| 25 |
+
|
| 26 |
+
ENV UVICORN_WS_PROTOCOL=websockets
|
| 27 |
+
|
| 28 |
+
# Set the working directory
|
| 29 |
+
WORKDIR $HOME/app
|
| 30 |
+
|
| 31 |
+
# Copy the app to the container
|
| 32 |
+
COPY --chown=user . $HOME/app
|
| 33 |
+
|
| 34 |
+
# Install the dependencies
|
| 35 |
+
# RUN uv sync --frozen
|
| 36 |
+
RUN uv sync
|
| 37 |
+
|
| 38 |
+
# Expose the port
|
| 39 |
+
EXPOSE 7860
|
| 40 |
+
|
| 41 |
+
# Run the app
|
| 42 |
+
CMD ["uv", "run", "chainlit", "run", "app.py", "--host", "0.0.0.0", "--port", "7860"]
|
README.md
CHANGED
|
@@ -1,12 +1,73 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: docker
|
| 7 |
-
pinned: false
|
| 8 |
-
license: openrail
|
| 9 |
-
short_description: 'LLM-based chatbot based on AIMakerspace tutorial '
|
| 10 |
---
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Beyond ChatGPT – Beginner LLM App
|
| 3 |
+
emoji: 💬
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: indigo
|
| 6 |
sdk: docker
|
|
|
|
|
|
|
|
|
|
| 7 |
---
|
| 8 |
|
| 9 |
+
# 💬 Beyond ChatGPT – Beginner LLM App
|
| 10 |
+
|
| 11 |
+
This is a simple LLM-based chatbot built during the **Beyond ChatGPT** tutorial from [AI Makerspace](https://github.com/AI-Maker-Space/Beyond-ChatGPT).
|
| 12 |
+
It runs locally or in a Hugging Face Space using Docker.
|
| 13 |
+
|
| 14 |
+
The app connects to the OpenAI API and supports system messages, few-shot prompting, and chain-of-thought-style reasoning — all within a clean conversational UI.
|
| 15 |
+
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
## 🧠 What You Can Do
|
| 19 |
+
|
| 20 |
+
- Send prompts to a live OpenAI model
|
| 21 |
+
- Test structured prompting techniques
|
| 22 |
+
- Explore different system/assistant/user message configurations
|
| 23 |
+
- Use this app as a foundation for building your own LLM tools
|
| 24 |
+
|
| 25 |
+
---
|
| 26 |
+
|
| 27 |
+
## 🚀 How to Use
|
| 28 |
+
|
| 29 |
+
If running on Hugging Face (or locally via Docker):
|
| 30 |
+
|
| 31 |
+
1. Enter a prompt in the chat window
|
| 32 |
+
2. Press `Enter` or click `Send`
|
| 33 |
+
3. The model will respond in a conversational format
|
| 34 |
+
|
| 35 |
+
---
|
| 36 |
+
|
| 37 |
+
## 🔧 Tech Stack
|
| 38 |
+
|
| 39 |
+
- Python
|
| 40 |
+
- OpenAI API (`gpt-3.5-turbo` or similar)
|
| 41 |
+
- Chainlit (chat interface)
|
| 42 |
+
- Docker (for deployment)
|
| 43 |
+
- Hugging Face Spaces (hosted version)
|
| 44 |
+
|
| 45 |
+
---
|
| 46 |
+
|
| 47 |
+
## 📦 Tutorial Origin
|
| 48 |
+
|
| 49 |
+
This app was built as part of the *Beyond ChatGPT* tutorial by AI Makerspace:
|
| 50 |
+
🔗 https://github.com/AI-Maker-Space/Beyond-ChatGPT
|
| 51 |
+
|
| 52 |
+
---
|
| 53 |
+
|
| 54 |
+
## ⚠️ Notes
|
| 55 |
+
|
| 56 |
+
- You’ll need a valid OpenAI API key to run this locally or deploy it to Hugging Face.
|
| 57 |
+
- If using Docker, the app runs on port 7860 by default.
|
| 58 |
+
|
| 59 |
+
---
|
| 60 |
+
|
| 61 |
+
## 🧪 Example Prompt
|
| 62 |
+
|
| 63 |
+
```
|
| 64 |
+
What are the key takeaways from the book "Thinking, Fast and Slow"?
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
---
|
| 68 |
+
|
| 69 |
+
## 🙌 Credits
|
| 70 |
+
|
| 71 |
+
Thanks to the team at AI Makerspace for the tutorial and code scaffold.
|
| 72 |
+
|
| 73 |
+
---
|
app.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# You can find this code for Chainlit python streaming here (https://docs.chainlit.io/concepts/streaming/python)
|
| 2 |
+
|
| 3 |
+
# OpenAI Chat completion
|
| 4 |
+
import os
|
| 5 |
+
from openai import AsyncOpenAI # importing openai for API usage
|
| 6 |
+
import chainlit as cl # importing chainlit for our app
|
| 7 |
+
from chainlit.prompt import Prompt, PromptMessage # importing prompt tools
|
| 8 |
+
from chainlit.playground.providers import ChatOpenAI # importing ChatOpenAI tools
|
| 9 |
+
from dotenv import load_dotenv
|
| 10 |
+
|
| 11 |
+
load_dotenv()
|
| 12 |
+
|
| 13 |
+
# ChatOpenAI Templates
|
| 14 |
+
system_template = """You are a helpful assistant who always speaks in a pleasant tone!
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
user_template = """{input}
|
| 18 |
+
Think through your response step by step.
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
@cl.on_chat_start # marks a function that will be executed at the start of a user session
|
| 23 |
+
async def start_chat():
|
| 24 |
+
settings = {
|
| 25 |
+
"model": "gpt-3.5-turbo",
|
| 26 |
+
"temperature": 0,
|
| 27 |
+
"max_tokens": 500,
|
| 28 |
+
"top_p": 1,
|
| 29 |
+
"frequency_penalty": 0,
|
| 30 |
+
"presence_penalty": 0,
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
cl.user_session.set("settings", settings)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
@cl.on_message # marks a function that should be run each time the chatbot receives a message from a user
|
| 37 |
+
async def main(message: cl.Message):
|
| 38 |
+
settings = cl.user_session.get("settings")
|
| 39 |
+
|
| 40 |
+
# Increment message count
|
| 41 |
+
max_messages = 3
|
| 42 |
+
count = cl.user_session.get("message_count") or 0
|
| 43 |
+
count += 1
|
| 44 |
+
cl.user_session.set("message_count", count)
|
| 45 |
+
|
| 46 |
+
# Stop after 3 messages
|
| 47 |
+
if count > max_messages:
|
| 48 |
+
await cl.Message(
|
| 49 |
+
content="⚠️ This demo is limited to 3 messages per session."
|
| 50 |
+
).send()
|
| 51 |
+
return
|
| 52 |
+
|
| 53 |
+
client = AsyncOpenAI()
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
print(message.content)
|
| 57 |
+
|
| 58 |
+
prompt = Prompt(
|
| 59 |
+
provider=ChatOpenAI.id,
|
| 60 |
+
messages=[
|
| 61 |
+
PromptMessage(
|
| 62 |
+
role="system",
|
| 63 |
+
template=system_template,
|
| 64 |
+
formatted=system_template,
|
| 65 |
+
),
|
| 66 |
+
PromptMessage(
|
| 67 |
+
role="user",
|
| 68 |
+
template=user_template,
|
| 69 |
+
formatted=user_template.format(input=message.content),
|
| 70 |
+
),
|
| 71 |
+
],
|
| 72 |
+
inputs={"input": message.content},
|
| 73 |
+
settings=settings,
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
print([m.to_openai() for m in prompt.messages])
|
| 77 |
+
|
| 78 |
+
msg = cl.Message(content="")
|
| 79 |
+
|
| 80 |
+
# Call OpenAI
|
| 81 |
+
async for stream_resp in await client.chat.completions.create(
|
| 82 |
+
messages=[m.to_openai() for m in prompt.messages], stream=True, **settings
|
| 83 |
+
):
|
| 84 |
+
token = stream_resp.choices[0].delta.content
|
| 85 |
+
if not token:
|
| 86 |
+
token = ""
|
| 87 |
+
await msg.stream_token(token)
|
| 88 |
+
|
| 89 |
+
# Update the prompt object with the completion
|
| 90 |
+
prompt.completion = msg.content
|
| 91 |
+
msg.prompt = prompt
|
| 92 |
+
|
| 93 |
+
# Send and close the message stream
|
| 94 |
+
await msg.send()
|
chainlit.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 👋 Welcome to Beyond ChatGPT – Beginner LLM App
|
| 2 |
+
|
| 3 |
+
This lightweight assistant was built using [Chainlit](https://www.chainlit.io/) and OpenAI, as part of the #AI_Makerspace tutorial series.
|
| 4 |
+
|
| 5 |
+
💬 You can type in any question or prompt to get a thoughtful reply.
|
| 6 |
+
|
| 7 |
+
⚠️ For demo purposes, responses are limited to **3 messages per session**.
|
| 8 |
+
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
🔧 Want to learn how this was built?
|
| 12 |
+
Check out the source code and deployment steps in the project [README](https://huggingface.co/spaces/FlamingNeuron/llm-app/tree/main).
|
| 13 |
+
|
pyproject.toml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[project]
|
| 2 |
+
name = "beyond-chatgpt"
|
| 3 |
+
version = "0.1.0"
|
| 4 |
+
description = "Add your description here"
|
| 5 |
+
readme = "README.md"
|
| 6 |
+
requires-python = ">=3.13"
|
| 7 |
+
dependencies = [
|
| 8 |
+
"chainlit==0.7.700",
|
| 9 |
+
"cohere==4.37",
|
| 10 |
+
"openai==1.3.5",
|
| 11 |
+
"pydantic==2.10.1",
|
| 12 |
+
"python-dotenv==1.0.0",
|
| 13 |
+
"tiktoken==0.5.1",
|
| 14 |
+
]
|
uv.lock
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|