jerpint commited on
Commit
e02ac39
Β·
1 Parent(s): 1c53d7d

remove all previous formatters

Browse files
buster/formatter/__init__.py DELETED
@@ -1,17 +0,0 @@
1
- # from .base import Response, ResponseFormatter, Source
2
- # from .factory import response_formatter_factory
3
- # from .gradio import GradioResponseFormatter
4
- # from .html import HTMLResponseFormatter
5
- # from .markdown import MarkdownResponseFormatter
6
- # from .slack import SlackResponseFormatter
7
-
8
- __all__ = [
9
- # Source,
10
- # Response,
11
- # ResponseFormatter,
12
- # HTMLResponseFormatter,
13
- # MarkdownResponseFormatter,
14
- # SlackResponseFormatter,
15
- # GradioResponseFormatter,
16
- # response_formatter_factory,
17
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
buster/formatter/base.py DELETED
@@ -1,56 +0,0 @@
1
- # from dataclasses import dataclass
2
- # from typing import Iterable, NamedTuple
3
-
4
- # import pandas as pd
5
-
6
- # from buster.completers.base import Completion
7
-
8
-
9
-
10
- # @dataclass
11
- # class ResponseFormatter:
12
- # response_footnote: str
13
- # source_template: str = "{source.title} (relevance: {source.question_similarity:2.1f})"
14
- # error_msg_template: str = """Something went wrong:\n{response.error_msg}"""
15
- # error_fallback_template: str = "Something went very wrong."
16
- # sourced_answer_template: str = (
17
- # """{response.text}\n\n"""
18
- # """πŸ“ Here are the sources I used to answer your question:\n"""
19
- # """{sources}\n\n"""
20
- # """{footnote}"""
21
- # )
22
- # unsourced_answer_template: str = "{response.text}\n\n{footnote}"
23
-
24
- # def source_item(self, source: Source) -> str:
25
- # """Format a single source item."""
26
- # return self.source_template.format(source=source)
27
-
28
- # def sources_list(self, sources: Iterable[Source]) -> str | None:
29
- # """Format sources into a list."""
30
- # items = [self.source_item(source) for source in sources]
31
- # if not items:
32
- # return None # No list needed.
33
-
34
- # return "\n".join(f"{ind}. {item}" for ind, item in enumerate(items, 1))
35
-
36
- # def error(self, response: Response) -> str:
37
- # """Format an error message."""
38
- # if response.error_msg:
39
- # return self.error_msg_template.format(response=response)
40
- # return self.error_fallback_template.format(response=response)
41
-
42
- # def answer(self, response: Response, sources: Iterable[Source]) -> str:
43
- # """Format an answer and its sources."""
44
- # sources_list = self.sources_list(sources)
45
- # if sources_list:
46
- # return self.sourced_answer_template.format(
47
- # response=response, sources=sources_list, footnote=self.response_footnote
48
- # )
49
-
50
- # return self.unsourced_answer_template.format(response=response, footnote=self.response_footnote)
51
-
52
- # def __call__(self, response: Response, sources: Iterable[Source]) -> str:
53
- # """Format an answer and its sources, or an error message."""
54
- # if response.error:
55
- # return self.error(response)
56
- # return self.answer(response, sources)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
buster/formatter/factory.py DELETED
@@ -1,23 +0,0 @@
1
- import logging
2
-
3
- import buster.formatter as F
4
-
5
- logger = logging.getLogger(__name__)
6
- logging.basicConfig(level=logging.INFO)
7
-
8
-
9
- def response_formatter_factory(format: str, **kwargs):
10
- pass
11
- # logger.info(f"Using formatter: {format}")
12
- # if format == "text":
13
- # return F.ResponseFormatter(**kwargs)
14
- # elif format == "slack":
15
- # return F.SlackResponseFormatter(**kwargs)
16
- # elif format == "HTML":
17
- # return F.HTMLResponseFormatter(**kwargs)
18
- # elif format == "gradio":
19
- # return F.GradioResponseFormatter(**kwargs)
20
- # elif format == "markdown":
21
- # return F.MarkdownResponseFormatter(**kwargs)
22
- # else:
23
- # raise ValueError(f"Undefined {format=}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
buster/formatter/gradio.py DELETED
@@ -1,28 +0,0 @@
1
- from dataclasses import dataclass
2
- from typing import Iterable
3
-
4
- from buster.formatter import ResponseFormatter, Source
5
-
6
-
7
- @dataclass
8
- class GradioResponseFormatter(ResponseFormatter):
9
- """Format the answer for gradio chat interface."""
10
-
11
- error_msg_template: str = """Something went wrong:<br>{response.error_msg}"""
12
- error_fallback_template: str = "Something went very wrong."
13
- sourced_answer_template: str = (
14
- """{response.text}<br><br>"""
15
- """πŸ“ Here are the sources I used to answer your question:<br>"""
16
- """{sources}<br><br>"""
17
- """{footnote}"""
18
- )
19
- unsourced_answer_template: str = "{response.text}<br><br>{footnote}"
20
- source_template: str = """[πŸ”— {source.title}]({source.url}), relevance: {source.question_similarity:2.1f} %"""
21
-
22
- def sources_list(self, sources: Iterable[Source]) -> str | None:
23
- """Format sources into a list."""
24
- items = [self.source_item(source) for source in sources]
25
- if not items:
26
- return None # No list needed.
27
-
28
- return "<br>".join(items)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
buster/formatter/html.py DELETED
@@ -1,41 +0,0 @@
1
- import html
2
- from dataclasses import dataclass
3
- from typing import Iterable
4
-
5
- from buster.formatter.base import Response, ResponseFormatter, Source
6
-
7
-
8
- @dataclass
9
- class HTMLResponseFormatter(ResponseFormatter):
10
- """Format the answer in HTML."""
11
-
12
- source_template: str = """<li><a href='{source.url}'>πŸ”— {source.source}</a></li>"""
13
- error_msg_template: str = """<div class="error">Something went wrong:\n<p>{response.error_msg}</p></div>"""
14
- error_fallback_template: str = """<div class="error">Something went very wrong.</div>"""
15
- sourced_answer_template: str = (
16
- """<div class="answer"><p>{response.text}</p></div>\n"""
17
- """<div class="sources>πŸ“ Here are the sources I used to answer your question:\n"""
18
- """<ol>\n{sources}</ol></div>\n"""
19
- """<div class="footer">I'm a chatbot, bleep bloop.</div>"""
20
- )
21
- unsourced_answer_template: str = (
22
- """<div class="answer">{response.text}</div>\n<div class="footer">I'm a chatbot, bleep bloop.</div>"""
23
- )
24
-
25
- def sources_list(self, sources: Iterable[Source]) -> str | None:
26
- """Format sources into a list."""
27
- items = [self.source_item(source) for source in sources]
28
- if not items:
29
- return None # No list needed.
30
-
31
- return "\n".join(items)
32
-
33
- def __call__(self, response: Response, sources: Iterable[Source]) -> str:
34
- # Escape any html in the text.
35
- response = Response(
36
- html.escape(response.text) if response.text else response.text,
37
- response.error,
38
- html.escape(response.error_msg) if response.error_msg else response.error_msg,
39
- )
40
- sources = (Source(html.escape(source.title), source.url, source.question_similarity) for source in sources)
41
- return super().__call__(response, sources)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
buster/formatter/markdown.py DELETED
@@ -1,19 +0,0 @@
1
- from dataclasses import dataclass
2
- from typing import Iterable
3
-
4
- from buster.formatter.base import ResponseFormatter, Source
5
-
6
-
7
- @dataclass
8
- class MarkdownResponseFormatter(ResponseFormatter):
9
- """Format the answer in markdown."""
10
-
11
- source_template: str = """[πŸ”— {source.title}]({source.url}), relevance: {source.question_similarity:2.3f}"""
12
-
13
- def sources_list(self, sources: Iterable[Source]) -> str | None:
14
- """Format sources into a list."""
15
- items = [self.source_item(source) for source in sources]
16
- if not items:
17
- return None # No list needed.
18
-
19
- return "\n".join(f"{ind}. {item}" for ind, item in enumerate(items, 1))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
buster/formatter/slack.py DELETED
@@ -1,19 +0,0 @@
1
- from dataclasses import dataclass
2
- from typing import Iterable
3
-
4
- from buster.formatter import ResponseFormatter, Source
5
-
6
-
7
- @dataclass
8
- class SlackResponseFormatter(ResponseFormatter):
9
- """Format the answer for Slack."""
10
-
11
- source_template: str = """<{source.url}|πŸ”— {source.title}>, relevance: {source.question_similarity:2.3f}"""
12
-
13
- def sources_list(self, sources: Iterable[Source]) -> str | None:
14
- """Format sources into a list."""
15
- items = [self.source_item(source) for source in sources]
16
- if not items:
17
- return None # No list needed.
18
-
19
- return "\n".join(items)