Skip to content

Commit

Permalink
🚧 Added url normalisation
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippGawlik committed Jul 18, 2024
1 parent 36d85d0 commit 83d12a3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
12 changes: 1 addition & 11 deletions api.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from typing import Optional, Generator
from fastapi import FastAPI, Depends, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from starlette.responses import RedirectResponse
import uvicorn

from langchain_core.documents.base import Document

from interface.response_models import ResponseModel, CTA, CTAType
from interface.request_models import RequestModel
from src.context import get_context
from src.tools import generate_cta
#from src.generate_with_azure import generate_answer
from src.generate_with_openai import generate_answer
from src.prompt import assemble_prompt
Expand Down Expand Up @@ -63,14 +62,5 @@ def answer_a_question(query: RequestModel) -> ResponseModel:
)


def generate_cta(context: list[Optional[Document]]) -> Generator[CTA, None, None]:
for c in context:
yield CTA(
type=CTAType.LINK,
text=c.metadata["title"],
payload=f"https://brbuddy-api-service-volume.brdata-dev.de/{c.metadata['title']}"
)


if __name__ == "__main__":
uvicorn.run(APP, host="0.0.0.0", port=3000)
16 changes: 16 additions & 0 deletions src/tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from typing import Optional, Generator
from langchain_core.documents.base import Document

from interface.response_models import CTA, CTAType
from urllib import parse


def generate_cta(context: list[Optional[Document]]) -> Generator[CTA, None, None]:
for c in context:
norm_name = parse.quote_plus(c.metadata['title'])
yield CTA(
type=CTAType.LINK,
text=c.metadata["title"],
payload=f"https://brbuddy-api-service-volume.brdata-dev.de/share/URV7wHnY/{norm_name}"
)

0 comments on commit 83d12a3

Please sign in to comment.