-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
2,338 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.venv | ||
.mypy_cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.10.13 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from pydantic import BaseModel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |