Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /Quansight_ragna /ragna /assistants /_demo.py
| import textwrap | |
| from collections.abc import Iterator | |
| from ragna.core import Assistant, Message, MessageRole | |
| class RagnaDemoAssistant(Assistant): | |
| """Demo assistant without requirements. | |
| !!! note | |
| As the name implies, this assistant is just for demo purposes and cannot | |
| answer any questions. By default it replies with the prompt and the given | |
| sources. | |
| If you include the phrase `"markdown"` into your prompt, it will return a | |
| Markdown table including emojis. | |
| """ | |
| def display_name(cls) -> str: | |
| return "Ragna/DemoAssistant" | |
| def answer(self, messages: list[Message]) -> Iterator[str]: | |
| if "markdown" in messages[-1].content.lower(): | |
| yield self._markdown_answer() | |
| else: | |
| yield self._default_answer(messages) | |
| def _markdown_answer(self) -> str: | |
| return textwrap.dedent( | |
| """ | |
| | String | Integer | Float | Emoji | | |
| | :----- | :------: | ----: | ------ | | |
| | foo | 0 | 1.0 | ๐ฆ | | |
| | `bar` | 1 | -1.23 | ๐ค | | |
| | "baz" | -1 | 1e6 | ๐๐๐ | | |
| """ | |
| ).strip() | |
| def _default_answer(self, messages: list[Message]) -> str: | |
| prompt, sources = (message := messages[-1]).content, message.sources | |
| sources_display = [] | |
| for source in sources: | |
| source_display = f"- {source.document_name}" | |
| if source.location: | |
| source_display += f", {source.location}" | |
| source_display += f": {textwrap.shorten(source.content, width=100)}" | |
| sources_display.append(source_display) | |
| if len(sources) > 3: | |
| sources_display.append("[...]") | |
| n_messages = len([m for m in messages if m.role == MessageRole.USER]) | |
| return ( | |
| textwrap.dedent( | |
| """ | |
| I'm a demo assistant and can be used to try Ragna's workflow. | |
| I will only mirror back my inputs. | |
| So far I have received {n_messages} messages. | |
| Your last prompt was: | |
| > {prompt} | |
| These are the sources I was given: | |
| {sources} | |
| """ | |
| ) | |
| .strip() | |
| .format( | |
| name=str(self), | |
| n_messages=n_messages, | |
| prompt=prompt, | |
| sources="\n".join(sources_display), | |
| ) | |
| ) | |
| def avatar(cls) -> str: | |
| return "imgs/ragna_logo.svg" | |
Xet Storage Details
- Size:
- 2.61 kB
- Xet hash:
- 31634068e3c6197f10b8895a7be00fd004f55760b838f43e15c4b01ee611e6de
ยท
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.