From 83d12a3311ffe2639c7f2cee713eeeba2501eb26 Mon Sep 17 00:00:00 2001 From: PhilippGawlik Date: Thu, 18 Jul 2024 12:16:10 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20Added=20url=20normalisation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api.py | 12 +----------- src/tools.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 11 deletions(-) create mode 100644 src/tools.py diff --git a/api.py b/api.py index 049692c..e658dd6 100644 --- a/api.py +++ b/api.py @@ -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 @@ -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) diff --git a/src/tools.py b/src/tools.py new file mode 100644 index 0000000..82470f7 --- /dev/null +++ b/src/tools.py @@ -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}" + ) +