Skip to content

Commit

Permalink
initial code commit
Browse files Browse the repository at this point in the history
  • Loading branch information
arnemu committed Jun 25, 2024
0 parents commit f8baef4
Show file tree
Hide file tree
Showing 40 changed files with 7,443 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["@babel/preset-env"]
}

1 change: 1 addition & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM mcr.microsoft.com/devcontainers/javascript-node:22
13 changes: 13 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "chatbotui",
"build": {
"context": "..",
"dockerfile": "./Dockerfile"
},
"customizations": {
"vscode": {
"extensions": [
]
}
}
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
examples/fastapi/__pycache__
examples/fastapi/static/markdown-it.min.js
dist/*
1 change: 1 addition & 0 deletions .nvimrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nnoremap <leader>cb :!devcontainer exec --workspace-folder . npm run build<CR>
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Contribution Agreement

By submitting a contribution (code, documentation, or other content), you agree
that your contribution is licensed under the MIT License as stated in the
LICENSE file of this project.

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright 2024 prognostica GmbH

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the “Software”), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Chatbot UI

A dependency free chatbot ui.

While developed by prognosticians, chatbotui is not an official
prognostica product.

<img alt="an example of chatbotui in action" src="example.png" />

## Build

```bash
npm install --include=dev --ignore-scripts
npm run build
```

### Types

```bash
npm install typescript --no-save
npx -p typescript tsc src/**/*.js --declaration --allowJs --emitDeclarationOnly --outDir types
```

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Contributing

By submitting a contribution (code, documentation, or other content), you agree
that your contribution is licensed under the MIT License as stated in the
LICENSE file of this project. For more details, please see our
[CONTRIBUTING](CONTRIBUTING.md) guidelines.
Binary file added example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions examples/fastapi/.devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM mcr.microsoft.com/devcontainers/python:3.11
WORKDIR /build
COPY requirements.txt .
RUN pip install -r requirements.txt
15 changes: 15 additions & 0 deletions examples/fastapi/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "fastapi-container",
"appPort": ["8000:8000"],
"build": {
"context": "..",
"dockerfile": "./Dockerfile"
},
"customizations": {
"vscode": {
"extensions": [
"ms-python.python"
]
}
}
}
167 changes: 167 additions & 0 deletions examples/fastapi/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
from fastapi.staticfiles import StaticFiles
from pydantic import BaseModel, Field
from fastapi import FastAPI, File, UploadFile, Form
from fastapi.responses import StreamingResponse
import json
import time
from uuid import uuid4
from typing import Optional, List

app = FastAPI()

app.mount("/dist", StaticFiles(directory="../../dist"), name="dist")
app.mount("/static", StaticFiles(directory="static"), name="static")


class Data(BaseModel):
session: str
message: str
files: List[str]


class MessageItemResponse(BaseModel):
type: str
content: str
message_item_id: int = Field(..., alias='messageItemID')
name: Optional[str] = None

class Config:
populate_by_name = True


class MessageItemResponseChunk(BaseModel):
type: str
content: str
message_item_id: int = Field(..., alias='messageItemID')
name: Optional[str] = None

class Config:
populate_by_name = True


class DocumentResponse(BaseModel):
title: str
content: str
icon: str


@app.post("/stream")
async def stream(data: Data):
return StreamingResponse(
line_streamer(),
media_type="application/json",
)


@app.post("/file")
async def file(session: str = Form(...), file: UploadFile = File(...)):
return str(uuid4())


@app.delete("/file")
async def delete_file(session: str = Form(...)):
return {"status": "ok"}


def line_streamer():
global msg
msg = (msg + 1) % len(msgs)
for data in msgs[msg]:
if ("sleep" in data):
duration = data["sleep"]
time.sleep(duration)
else:
time.sleep(0.04)
item = data["item"]
yield f'{json.dumps({"class": item.__class__.__name__, "data": item.dict(by_alias=True)}, ensure_ascii=False)}\n'


@ app.get("/session")
async def session():
return {
"name": "ExampleBot",
"session": str(uuid4()),
"multiTurn": True,
"fileSupport": True,
}

# Test messages


def getTestImage():
return "iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAApgAAAKYB3X3/OAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAANCSURBVEiJtZZPbBtFFMZ/M7ubXdtdb1xSFyeilBapySVU8h8OoFaooFSqiihIVIpQBKci6KEg9Q6H9kovIHoCIVQJJCKE1ENFjnAgcaSGC6rEnxBwA04Tx43t2FnvDAfjkNibxgHxnWb2e/u992bee7tCa00YFsffekFY+nUzFtjW0LrvjRXrCDIAaPLlW0nHL0SsZtVoaF98mLrx3pdhOqLtYPHChahZcYYO7KvPFxvRl5XPp1sN3adWiD1ZAqD6XYK1b/dvE5IWryTt2udLFedwc1+9kLp+vbbpoDh+6TklxBeAi9TL0taeWpdmZzQDry0AcO+jQ12RyohqqoYoo8RDwJrU+qXkjWtfi8Xxt58BdQuwQs9qC/afLwCw8tnQbqYAPsgxE1S6F3EAIXux2oQFKm0ihMsOF71dHYx+f3NND68ghCu1YIoePPQN1pGRABkJ6Bus96CutRZMydTl+TvuiRW1m3n0eDl0vRPcEysqdXn+jsQPsrHMquGeXEaY4Yk4wxWcY5V/9scqOMOVUFthatyTy8QyqwZ+kDURKoMWxNKr2EeqVKcTNOajqKoBgOE28U4tdQl5p5bwCw7BWquaZSzAPlwjlithJtp3pTImSqQRrb2Z8PHGigD4RZuNX6JYj6wj7O4TFLbCO/Mn/m8R+h6rYSUb3ekokRY6f/YukArN979jcW+V/S8g0eT/N3VN3kTqWbQ428m9/8k0P/1aIhF36PccEl6EhOcAUCrXKZXXWS3XKd2vc/TRBG9O5ELC17MmWubD2nKhUKZa26Ba2+D3P+4/MNCFwg59oWVeYhkzgN/JDR8deKBoD7Y+ljEjGZ0sosXVTvbc6RHirr2reNy1OXd6pJsQ+gqjk8VWFYmHrwBzW/n+uMPFiRwHB2I7ih8ciHFxIkd/3Omk5tCDV1t+2nNu5sxxpDFNx+huNhVT3/zMDz8usXC3ddaHBj1GHj/As08fwTS7Kt1HBTmyN29vdwAw+/wbwLVOJ3uAD1wi/dUH7Qei66PfyuRj4Ik9is+hglfbkbfR3cnZm7chlUWLdwmprtCohX4HUtlOcQjLYCu+fzGJH2QRKvP3UNz8bWk1qMxjGTOMThZ3kvgLI5AzFfo379UAAAAASUVORK5CYII="


msgs = [
[
{"item": MessageItemResponseChunk(
type="text", content=chunk, message_item_id=0), "sleep": 0.04}
for chunk in
["Hi", ",", " Chatbot", " UI", " is", " a", " dependency", " free", " UI", " you", " can", " use", " in",
" your", " projects", ".", " It", " is", " licensed", " under", " the", " MIT", " License", "."]],
[
{"item": MessageItemResponseChunk(
type="text", content=chunk, message_item_id=0), "sleep": 0.03}
for chunk in ["Hi", "!", " Chat", "bot", " UI", " is", " a", " JavaScript", " project", " designed", " to", " handle", " the", " user", " interface", " part", " of", " conversations", " with", " a", " chat", "bot", ".", " It", " includes", " an", " input", " field", " for", " users", " to", " type", " their", " messages", " and", " displays", " messages", " from", " both", " the", " user", " and", " the", " bot", ".", " Additionally", ",", " it", " supports", " special", " messages", " and", " has", " call", "back", " functionality", " for", " handling", " documents", ".", "\n\n", "One", " of", " its", " standout", " features", " is", " that", " it", "'", "s", " completely", " dependency", "-", "free", ",", " meaning", " it", " doesn't", " rely", " on", " other", " libraries", " or", " frameworks", " to", " function", ".", " This", " makes", " it", " easy", " to", " integrate", " into", " existing", " apps", " or", " websites", "."]],
[
{
"item": MessageItemResponseChunk(
type="text", content="Some", message_item_id=0),
"sleep": 0.6,
},
{
"item": MessageItemResponse(
type="tool", content="This is an example tool response.",
message_item_id=1, name="Supertool"),
"sleep": 0.02,
},
{
"item": MessageItemResponseChunk(
type="text", content=" tool", message_item_id=0),
"sleep": 0.04,
},
{
"item": MessageItemResponseChunk(
type="text", content=" output", message_item_id=0),
"sleep": 0.04,
},
{
"item": MessageItemResponseChunk(
type="text", content=" for", message_item_id=0),
"sleep": 0.04,
},
{
"item": MessageItemResponseChunk(
type="text", content=" tes", message_item_id=0),
"sleep": 0.2,
},
{
"item": MessageItemResponseChunk(
type="text", content="ting", message_item_id=0),
"sleep": 0.04,
},
{
"item": MessageItemResponseChunk(
type="text", content=".", message_item_id=0),
"sleep": 0.04,
},
{
"item": MessageItemResponse(
type="tool", content="Another Tool",
message_item_id=2, name="Second Tool"),
"sleep": 0.7,
},
{
"item": MessageItemResponse(
type="b64image", content=getTestImage(),
message_item_id=3),
"sleep": 0.04,
},
{
"item": DocumentResponse(title="Example Document",
content="Lorem Ipsum "*1000,
icon="📄"),
"sleep": 0.01,
},
]]
msg = len(msgs)
2 changes: 2 additions & 0 deletions examples/fastapi/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fastapi
uvicorn
Loading

0 comments on commit f8baef4

Please sign in to comment.