File size: 2,347 Bytes
33bd61d ba7196e 4e61338 ba7196e be9ddcf 4e61338 ba7196e 8e99545 8f55dd1 8e99545 ba7196e e9c817b 33bd61d ba7196e 4e61338 ba7196e 8e99545 4e61338 8f55dd1 be9ddcf e9c817b 110df4d 33bd61d 110df4d |
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 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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
from typing import Any, Dict, List, Literal, NewType, Optional, TypedDict, Union
from .type_utils import register_type
Text = NewType("Text", str)
Number = NewType("Number", Union[float, int])
class JsonSchema:
@classmethod
def __verify_type__(cls, object):
if not isinstance(object, dict):
return False
import jsonschema_rs
jsonschema_rs.meta.validate(object)
return True
class Tool(TypedDict):
# Original fields
name: str
description: str
parameters: JsonSchema
# LiteLLM extension
type: Optional[Literal["function"]]
class ToolCall(TypedDict):
name: str
arguments: Dict[str, Any]
class ToolCallContext(TypedDict):
id: str
type: Literal["function"]
function: ToolCall
class ToolCallTurn(TypedDict):
role: Literal["assistant"]
content: Optional[str]
tool_calls: List[ToolCallContext]
class ToolOutputTurn(TypedDict):
role: Literal["tool"]
tool_call_id: str
name: str
content: str
class TextTurn(TypedDict):
role: Literal["system", "user", "agent", "assistant"]
content: Text
class RagResponse(TypedDict):
answer: str
contexts: List[str]
context_ids: Union[List[int], List[str]]
is_answerable: bool
Dialog = NewType("Dialog", List[Union[TextTurn, ToolCallTurn, ToolOutputTurn]])
class Conversation(TypedDict):
id: str
dialog: Dialog
class Image(TypedDict):
image: Any
format: str
class Document(TypedDict):
title: str
body: str
MultiDocument = NewType("MultiDocument", List[Document])
Video = NewType("Video", List[Image])
class Audio(TypedDict):
audio: Any
class Table(TypedDict):
header: List[str]
rows: List[List[Any]]
class SQLDatabase(TypedDict):
db_id: Optional[str]
db_type: Literal["local", "in_memory", "remote"]
dbms: Optional[str]
data: Optional[Dict[str, Dict]]
register_type(Text)
register_type(Number)
register_type(TextTurn)
register_type(ToolCallTurn)
register_type(ToolOutputTurn)
register_type(Dialog)
register_type(Table)
register_type(Audio)
register_type(Image)
register_type(Video)
register_type(Conversation)
register_type(Document)
register_type(MultiDocument)
register_type(RagResponse)
register_type(SQLDatabase)
register_type(Tool)
register_type(JsonSchema)
register_type(ToolCall)
|