Skip to content

Commit

Permalink
Init reflyd version
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcfps committed Feb 24, 2024
1 parent 30f07a0 commit e81d2ee
Show file tree
Hide file tree
Showing 10 changed files with 2,338 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.venv
.mypy_cache
1 change: 1 addition & 0 deletions reflyd/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10.13
8 changes: 8 additions & 0 deletions reflyd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# reflyd

# Setup

```bash
brew install pyenv pipx
pipx ensurepath
```
Empty file added reflyd/app/__init__.py
Empty file.
77 changes: 77 additions & 0 deletions reflyd/app/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import logging

import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from llama_index.embeddings.openai import OpenAIEmbedding # type:ignore
from llama_index.core.node_parser import SentenceSplitter
from llama_index.core.extractors import TitleExtractor
from llama_index.core.ingestion import IngestionPipeline, IngestionCache
from llama_index.core import VectorStoreIndex
from llama_index.core.readers.base import BaseReader
from llama_index.core.ingestion.cache import SimpleCache
from llama_index.readers.web.async_web.base import AsyncWebPageReader # type:ignore

from app.models.dto import VisitLink

logger = logging.getLogger(__name__)

APP_HOST = "0.0.0.0"
APP_PORT = 8080


def get_application() -> FastAPI:
application = FastAPI(title="Refly Backend")

application.add_middleware(
CORSMiddleware,
allow_origins=["*"], # Change this to the list of allowed origins if needed
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

return application


app = get_application()

index = VectorStoreIndex([])
pipeline = IngestionPipeline(
transformations=[
SentenceSplitter(chunk_size=25, chunk_overlap=0),
TitleExtractor(),
OpenAIEmbedding(),
],
cache=IngestionCache(cache=SimpleCache()),
)


@app.post("/store-links")
def report_links(links: list[VisitLink]):
loader = BaseReader()

documents = loader.load_data()
nodes = pipeline.run(documents=documents)
index.insert_nodes(nodes)


@app.get("/query")
def query():
engine = index.as_query_engine()
engine.query()


@app.get("/chat")
def chat():
engine = index.as_chat_engine()
engine.chat()


if __name__ == "__main__":
logger.info(f"Starting reflyd on http://{APP_HOST}:{str(APP_PORT)}/")
uvicorn.run(
app,
host=APP_HOST,
port=APP_PORT,
)
Empty file added reflyd/app/models/__init__.py
Empty file.
1 change: 1 addition & 0 deletions reflyd/app/models/db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from pydantic import BaseModel
8 changes: 8 additions & 0 deletions reflyd/app/models/dto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from pydantic import BaseModel


class VisitLink(BaseModel):
last_visit_time: float
title: str
url: str
visit_count: int
2,224 changes: 2,224 additions & 0 deletions reflyd/poetry.lock

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions reflyd/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[tool.poetry]
name = "reflyd"
version = "0.1.0"
description = ""
authors = ["mrcfps <mrc@powerformer.com>"]
readme = "README.md"

[tool.poetry.dependencies]
python = ">=3.10,<3.12"
fastapi = "^0.109.2"
llama-index = "^0.10.6"
uvicorn = "^0.27.1"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

0 comments on commit e81d2ee

Please sign in to comment.