Skip to content

Commit

Permalink
feat: update tabby-python-client
Browse files Browse the repository at this point in the history
  • Loading branch information
wsxiaoys committed Oct 19, 2023
1 parent 5cd32eb commit aacfd35
Show file tree
Hide file tree
Showing 14 changed files with 672 additions and 10 deletions.
2 changes: 1 addition & 1 deletion clients/tabby-python-client/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name="tabby-python-client",
version="0.1.0",
version="0.3.0",
description="A client library for accessing Tabby Server",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
2 changes: 1 addition & 1 deletion clients/tabby-python-client/tabby_client/api/v1/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def _get_kwargs(
cookies: Dict[str, Any] = client.get_cookies()

return {
"method": "post",
"method": "get",
"url": url,
"headers": headers,
"cookies": cookies,
Expand Down
16 changes: 16 additions & 0 deletions clients/tabby-python-client/tabby_client/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
""" Contains all the data models used in inputs/outputs """

from .chat_completion_chunk import ChatCompletionChunk
from .chat_completion_request import ChatCompletionRequest
from .choice import Choice
from .completion_request import CompletionRequest
from .completion_response import CompletionResponse
from .health_state import HealthState
from .hit import Hit
from .hit_document import HitDocument
from .log_event_request import LogEventRequest
from .message import Message
from .search_response import SearchResponse
from .segments import Segments
from .snippet import Snippet
from .version import Version

__all__ = (
"ChatCompletionChunk",
"ChatCompletionRequest",
"Choice",
"CompletionRequest",
"CompletionResponse",
"HealthState",
"Hit",
"HitDocument",
"LogEventRequest",
"Message",
"SearchResponse",
"Segments",
"Snippet",
"Version",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from typing import Any, Dict, List, Type, TypeVar

import attr

T = TypeVar("T", bound="ChatCompletionChunk")


@attr.s(auto_attribs=True)
class ChatCompletionChunk:
"""
Attributes:
content (str):
"""

content: str
additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)

def to_dict(self) -> Dict[str, Any]:
content = self.content

field_dict: Dict[str, Any] = {}
field_dict.update(self.additional_properties)
field_dict.update(
{
"content": content,
}
)

return field_dict

@classmethod
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
d = src_dict.copy()
content = d.pop("content")

chat_completion_chunk = cls(
content=content,
)

chat_completion_chunk.additional_properties = d
return chat_completion_chunk

@property
def additional_keys(self) -> List[str]:
return list(self.additional_properties.keys())

def __getitem__(self, key: str) -> Any:
return self.additional_properties[key]

def __setitem__(self, key: str, value: Any) -> None:
self.additional_properties[key] = value

def __delitem__(self, key: str) -> None:
del self.additional_properties[key]

def __contains__(self, key: str) -> bool:
return key in self.additional_properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar

import attr

if TYPE_CHECKING:
from ..models.message import Message


T = TypeVar("T", bound="ChatCompletionRequest")


@attr.s(auto_attribs=True)
class ChatCompletionRequest:
"""
Example:
{'messages': [{'content': 'What is tail recursion?', 'role': 'user'}, {'content': "It's a kind of optimization
in compiler?", 'role': 'assistant'}, {'content': 'Could you share more details?', 'role': 'user'}]}
Attributes:
messages (List['Message']):
"""

messages: List["Message"]
additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)

def to_dict(self) -> Dict[str, Any]:
messages = []
for messages_item_data in self.messages:
messages_item = messages_item_data.to_dict()

messages.append(messages_item)

field_dict: Dict[str, Any] = {}
field_dict.update(self.additional_properties)
field_dict.update(
{
"messages": messages,
}
)

return field_dict

@classmethod
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
from ..models.message import Message

d = src_dict.copy()
messages = []
_messages = d.pop("messages")
for messages_item_data in _messages:
messages_item = Message.from_dict(messages_item_data)

messages.append(messages_item)

chat_completion_request = cls(
messages=messages,
)

chat_completion_request.additional_properties = d
return chat_completion_request

@property
def additional_keys(self) -> List[str]:
return list(self.additional_properties.keys())

def __getitem__(self, key: str) -> Any:
return self.additional_properties[key]

def __setitem__(self, key: str, value: Any) -> None:
self.additional_properties[key] = value

def __delitem__(self, key: str) -> None:
del self.additional_properties[key]

def __contains__(self, key: str) -> bool:
return key in self.additional_properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ class CompletionRequest:
language (Union[Unset, None, str]): Language identifier, full list is maintained at
https://code.visualstudio.com/docs/languages/identifiers Example: python.
segments (Union[Unset, None, Segments]):
user (Union[Unset, None, str]):
user (Union[Unset, None, str]): A unique identifier representing your end-user, which can help Tabby to monitor
& generating
reports.
"""

prompt: Union[Unset, None, str] = UNSET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
@attr.s(auto_attribs=True)
class CompletionResponse:
"""
Example:
{'choices': [{'index': 0, 'text': 'string'}], 'id': 'string'}
Attributes:
id (str):
choices (List['Choice']):
Expand Down
60 changes: 53 additions & 7 deletions clients/tabby-python-client/tabby_client/models/health_state.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from typing import Any, Dict, List, Type, TypeVar
from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union, cast

import attr

from ..types import UNSET, Unset

if TYPE_CHECKING:
from ..models.version import Version


T = TypeVar("T", bound="HealthState")


Expand All @@ -11,44 +17,84 @@ class HealthState:
Attributes:
model (str):
device (str):
compute_type (str):
arch (str):
cpu_info (str):
cpu_count (int):
cuda_devices (List[str]):
version (Version):
chat_model (Union[Unset, None, str]):
"""

model: str
device: str
compute_type: str
arch: str
cpu_info: str
cpu_count: int
cuda_devices: List[str]
version: "Version"
chat_model: Union[Unset, None, str] = UNSET
additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)

def to_dict(self) -> Dict[str, Any]:
model = self.model
device = self.device
compute_type = self.compute_type
arch = self.arch
cpu_info = self.cpu_info
cpu_count = self.cpu_count
cuda_devices = self.cuda_devices

version = self.version.to_dict()

chat_model = self.chat_model

field_dict: Dict[str, Any] = {}
field_dict.update(self.additional_properties)
field_dict.update(
{
"model": model,
"device": device,
"compute_type": compute_type,
"arch": arch,
"cpu_info": cpu_info,
"cpu_count": cpu_count,
"cuda_devices": cuda_devices,
"version": version,
}
)
if chat_model is not UNSET:
field_dict["chat_model"] = chat_model

return field_dict

@classmethod
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
from ..models.version import Version

d = src_dict.copy()
model = d.pop("model")

device = d.pop("device")

compute_type = d.pop("compute_type")
arch = d.pop("arch")

cpu_info = d.pop("cpu_info")

cpu_count = d.pop("cpu_count")

cuda_devices = cast(List[str], d.pop("cuda_devices"))

version = Version.from_dict(d.pop("version"))

chat_model = d.pop("chat_model", UNSET)

health_state = cls(
model=model,
device=device,
compute_type=compute_type,
arch=arch,
cpu_info=cpu_info,
cpu_count=cpu_count,
cuda_devices=cuda_devices,
version=version,
chat_model=chat_model,
)

health_state.additional_properties = d
Expand Down
78 changes: 78 additions & 0 deletions clients/tabby-python-client/tabby_client/models/hit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar

import attr

if TYPE_CHECKING:
from ..models.hit_document import HitDocument


T = TypeVar("T", bound="Hit")


@attr.s(auto_attribs=True)
class Hit:
"""
Attributes:
score (float):
doc (HitDocument):
id (int):
"""

score: float
doc: "HitDocument"
id: int
additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)

def to_dict(self) -> Dict[str, Any]:
score = self.score
doc = self.doc.to_dict()

id = self.id

field_dict: Dict[str, Any] = {}
field_dict.update(self.additional_properties)
field_dict.update(
{
"score": score,
"doc": doc,
"id": id,
}
)

return field_dict

@classmethod
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
from ..models.hit_document import HitDocument

d = src_dict.copy()
score = d.pop("score")

doc = HitDocument.from_dict(d.pop("doc"))

id = d.pop("id")

hit = cls(
score=score,
doc=doc,
id=id,
)

hit.additional_properties = d
return hit

@property
def additional_keys(self) -> List[str]:
return list(self.additional_properties.keys())

def __getitem__(self, key: str) -> Any:
return self.additional_properties[key]

def __setitem__(self, key: str, value: Any) -> None:
self.additional_properties[key] = value

def __delitem__(self, key: str) -> None:
del self.additional_properties[key]

def __contains__(self, key: str) -> bool:
return key in self.additional_properties
Loading

0 comments on commit aacfd35

Please sign in to comment.