mirror of
https://github.com/kovidgoyal/calibre.git
synced 2026-04-06 09:12:00 -04:00
Store provider and model details
This commit is contained in:
parent
53c4bbb570
commit
29d4d3fc09
@ -37,11 +37,18 @@ class ChatResponse(NamedTuple):
|
||||
content: str = ''
|
||||
reasoning: str = ''
|
||||
type: ChatMessageType = ChatMessageType.assistant
|
||||
cost: float = 0
|
||||
currency: str = 'USD'
|
||||
|
||||
exception: Exception | None = None
|
||||
error_details: str = '' # can be traceback or error message from HTTP response
|
||||
|
||||
# This metadata will typically be present in the last response from a
|
||||
# streaming chat session.
|
||||
has_metadata: bool = False
|
||||
cost: float = 0
|
||||
currency: str = 'USD'
|
||||
provider: str = ''
|
||||
model: str = ''
|
||||
|
||||
|
||||
class NoFreeModels(Exception):
|
||||
pass
|
||||
|
||||
@ -310,7 +310,10 @@ def text_chat_implementation(messages: Iterable[ChatMessage]) -> Iterator[ChatRe
|
||||
if c or r:
|
||||
yield ChatResponse(content=c, reasoning=r, type=ChatMessageType(role))
|
||||
if u := data.get('usage'):
|
||||
yield ChatResponse(cost=float(u['cost'] or 0))
|
||||
yield ChatResponse(
|
||||
cost=float(u['cost'] or 0), currency=_('credits'), provider=data.get('provider') or '',
|
||||
model=data.get('model') or '', has_metadata=True,
|
||||
)
|
||||
|
||||
with opener().open(rq) as response:
|
||||
if response.status != http.HTTPStatus.OK:
|
||||
@ -350,9 +353,8 @@ def develop():
|
||||
raise SystemExit(str(x.exception))
|
||||
if x.content:
|
||||
print(end=x.content, flush=True)
|
||||
if x.cost:
|
||||
print(f'Cost: {x.cost}')
|
||||
print()
|
||||
if x.has_metadata:
|
||||
print(f'\nCost: {x.cost} {x.currency} Provider: {x.provider} Model: {x.model}')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user