jerpint commited on
Commit
1c53d7d
·
1 Parent(s): 24f8c1c

add all comments just in case

Browse files
buster/formatter/__init__.py CHANGED
@@ -1,17 +1,17 @@
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
  ]
 
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 CHANGED
@@ -1,69 +1,56 @@
1
- from dataclasses import dataclass
2
- from typing import Iterable, NamedTuple
3
-
4
-
5
- # Should be from the `documents` module.
6
- class Source(NamedTuple):
7
- title: str
8
- url: str
9
- question_similarity: float
10
- source: str = ""
11
- # TODO Add answer similarity.
12
- # answer_similarity: float
13
-
14
-
15
- # Should be from the `nlp` module.
16
- @dataclass(slots=True)
17
- class Response:
18
- text: str
19
- error: bool = False
20
- error_msg: str | None = None
21
-
22
-
23
- @dataclass
24
- class ResponseFormatter:
25
- response_footnote: str
26
- source_template: str = "{source.name} (relevance: {source.question_similarity:2.1f})"
27
- error_msg_template: str = """Something went wrong:\n{response.error_msg}"""
28
- error_fallback_template: str = "Something went very wrong."
29
- sourced_answer_template: str = (
30
- """{response.text}\n\n"""
31
- """📝 Here are the sources I used to answer your question:\n"""
32
- """{sources}\n\n"""
33
- """{footnote}"""
34
- )
35
- unsourced_answer_template: str = "{response.text}\n\n{footnote}"
36
-
37
- def source_item(self, source: Source) -> str:
38
- """Format a single source item."""
39
- return self.source_template.format(source=source)
40
-
41
- def sources_list(self, sources: Iterable[Source]) -> str | None:
42
- """Format sources into a list."""
43
- items = [self.source_item(source) for source in sources]
44
- if not items:
45
- return None # No list needed.
46
-
47
- return "\n".join(f"{ind}. {item}" for ind, item in enumerate(items, 1))
48
-
49
- def error(self, response: Response) -> str:
50
- """Format an error message."""
51
- if response.error_msg:
52
- return self.error_msg_template.format(response=response)
53
- return self.error_fallback_template.format(response=response)
54
-
55
- def answer(self, response: Response, sources: Iterable[Source]) -> str:
56
- """Format an answer and its sources."""
57
- sources_list = self.sources_list(sources)
58
- if sources_list:
59
- return self.sourced_answer_template.format(
60
- response=response, sources=sources_list, footnote=self.response_footnote
61
- )
62
-
63
- return self.unsourced_answer_template.format(response=response, footnote=self.response_footnote)
64
-
65
- def __call__(self, response: Response, sources: Iterable[Source]) -> str:
66
- """Format an answer and its sources, or an error message."""
67
- if response.error:
68
- return self.error(response)
69
- return self.answer(response, sources)
 
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 CHANGED
@@ -7,16 +7,17 @@ logging.basicConfig(level=logging.INFO)
7
 
8
 
9
  def response_formatter_factory(format: str, **kwargs):
10
- logger.info(f"Using formatter: {format}")
11
- if format == "text":
12
- return F.ResponseFormatter(**kwargs)
13
- elif format == "slack":
14
- return F.SlackResponseFormatter(**kwargs)
15
- elif format == "HTML":
16
- return F.HTMLResponseFormatter(**kwargs)
17
- elif format == "gradio":
18
- return F.GradioResponseFormatter(**kwargs)
19
- elif format == "markdown":
20
- return F.MarkdownResponseFormatter(**kwargs)
21
- else:
22
- raise ValueError(f"Undefined {format=}")
 
 
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=}")