Spaces:
Runtime error
Runtime error
add all comments just in case
Browse files- buster/formatter/__init__.py +14 -14
- buster/formatter/base.py +56 -69
- buster/formatter/factory.py +14 -13
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 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
#
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
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 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
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=}")
|