summaryrefslogtreecommitdiffstats
path: root/g4f/providers/response.py
blob: a4d1467aec7acdc24f3ab1cbe3ab00df04c4afac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from __future__ import annotations

from abc import abstractmethod

class ResponseType:
    @abstractmethod
    def __str__(self) -> str:
        pass

class FinishReason():
    def __init__(self, reason: str):
        self.reason = reason

    def __str__(self) -> str:
        return ""

class Sources(ResponseType):
    def __init__(self, sources: list[dict[str, str]]) -> None:
        self.list = sources

    def __str__(self) -> str:
        return "\n\n" + ("\n".join([f"{idx+1}. [{link['title']}]({link['url']})" for idx, link in enumerate(self.list)]))

class BaseConversation(ResponseType):
    def __str__(self) -> str:
        return ""