Skip to content

Commit 8642d7d

Browse files
committed
[chore] add more to documentations
1 parent b527734 commit 8642d7d

File tree

16 files changed

+130
-26
lines changed

16 files changed

+130
-26
lines changed

tuneapi/apis/model_anthropic.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""
2+
Connect to the `Anthropic API <https://console.anthropic.com/>`_ to use Claude series of LLMs
3+
"""
4+
15
# Copyright © 2024- Frello Technology Private Limited
26

37
import re
@@ -23,6 +27,9 @@ def set_api_token(self, token: str) -> None:
2327
self.anthropic_api_token = token
2428

2529
def tool_to_claude_xml(self, tool):
30+
"""
31+
Deprecated: was written when function calling did not exist in Anthropic API.
32+
"""
2633
tool_signature = ""
2734
if len(tool["parameters"]) > 0:
2835
for name, p in tool["parameters"]["properties"].items():

tuneapi/apis/model_gemini.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""
2+
Connect to the Google Gemini API to their LLMs. See more `Gemini <https://ai.google.dev>`_.
3+
"""
4+
15
# Copyright © 2024- Frello Technology Private Limited
26
# https://ai.google.dev/gemini-api/docs/function-calling
37

tuneapi/apis/model_groq.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""
2+
Connect to the `Groq API <https://console.groq.com/>`_ to experience the speed of their LPUs.
3+
"""
4+
15
# Copyright © 2024- Frello Technology Private Limited
26

37
import json

tuneapi/apis/model_mistral.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""
2+
Connect to the `Mistral API <https://console.mistral.ai/>`_ and use their LLMs.
3+
"""
4+
15
# Copyright © 2024- Frello Technology Private Limited
26

37
import json

tuneapi/apis/model_openai.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""
2+
Connect to the `OpenAI API <https://playground.openai.com/>`_ and use their LLMs.
3+
"""
4+
15
# Copyright © 2024- Frello Technology Private Limited
26

37
import json

tuneapi/apis/model_tune.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""
2+
Connect to the `TuneAI Proxy API <https://studio.tune.app/>`_ and use our standard endpoint for AI.
3+
"""
4+
15
# Copyright © 2024- Frello Technology Private Limited
26

37
import json

tuneapi/apis/threads.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""
2+
Use the `Threads API <https://studio.tune.app/docs/concepts/threads>`_ for managing threads and messages on the Tune AI
3+
platform.
4+
"""
5+
16
# Copyright © 2024- Frello Technology Private Limited
27

38
from functools import cache

tuneapi/types/chats.py

Lines changed: 71 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
"""
2+
This file contains all the datatypes relevant for a chat conversation. In general this is the nomenclature that we follow:
3+
* Message: a unit of information produced by a ``role``
4+
* Thread: a group of messages is called a thread. There can be many 2 types of threads, linear and tree based.
5+
* ThreadsList: a group of linear threads is called a threads list.
6+
* Dataset: a container for grouping threads lists is called a dataset
7+
8+
Almost all the classes contain ``to_dict`` and ``from_dict`` for serialisation and deserialisation.
9+
"""
10+
111
# Copyright © 2023- Frello Technology Private Limited
212

313
import io
@@ -23,8 +33,13 @@
2333

2434

2535
class Tool:
36+
"""A tool is a container for telling the LLM what it can do. This is a standard definition."""
2637

2738
class Prop:
39+
"""
40+
An individual property is called a prop.
41+
"""
42+
2843
def __init__(
2944
self,
3045
name: str,
@@ -97,6 +112,16 @@ def from_dict(cls, x):
97112

98113

99114
class Message:
115+
"""
116+
A message is the unit element of information in a thread. You should avoid using directly and use the convinience
117+
aliases ``tuneapi.types.chat. human/assistant/system/...``.
118+
119+
Args:
120+
- value: this is generally a string or a list of dictionary objects for more advanced use cases
121+
- role: the role who produced this information
122+
- images: a list of PIL images or base64 strings
123+
"""
124+
100125
# names that are our standards roles
101126
SYSTEM = "system"
102127
HUMAN = "human"
@@ -123,11 +148,12 @@ class Message:
123148
"function_resp": FUNCTION_RESP,
124149
"function-resp": FUNCTION_RESP,
125150
}
151+
"""A map that contains the popularly known mappings to make life simpler"""
126152

127153
# start initialization here
128154
def __init__(
129155
self,
130-
value: str | float | List[Dict[str, Any]],
156+
value: str | List[Dict[str, Any]],
131157
role: str,
132158
images: List[str | Image] = [],
133159
id: str = None,
@@ -230,20 +256,31 @@ def to_dict(
230256

231257
@classmethod
232258
def from_dict(cls, data):
259+
"""Deserialise and construct a message from a dictionary"""
233260
return cls(
234261
value=data.get("value") or data.get("content"),
235262
role=data.get("from") or data.get("role"),
236-
id=data.get("id"),
263+
id=data.get("id", ""),
264+
images=data.get("images", []),
237265
**data.get("metadata", {}),
238266
) # type: ignore
239267

240268

241269
### Aliases
242270
human = partial(Message, role=Message.HUMAN)
271+
"""Convinience for creating a human message"""
272+
243273
system = partial(Message, role=Message.SYSTEM)
274+
"""Convinience for creating a system message"""
275+
244276
assistant = partial(Message, role=Message.GPT)
277+
"""Convinience for creating an assistant message"""
278+
245279
function_call = partial(Message, role=Message.FUNCTION_CALL)
280+
"""Convinience for creating a function call message"""
281+
246282
function_resp = partial(Message, role=Message.FUNCTION_RESP)
283+
"""Convinience for creating a function response message"""
247284

248285

249286
########################################################################################################################
@@ -255,6 +292,8 @@ def from_dict(cls, data):
255292

256293

257294
class ModelInterface:
295+
"""This is the generic interface implemented by all the model APIs"""
296+
258297
def set_api_token(self, token: str) -> None:
259298
"""This are used to set the API token for the model"""
260299

@@ -296,11 +335,12 @@ def stream_chat(
296335

297336
class Thread:
298337
"""
299-
If the last Message is a "value".
338+
This is a container for a list of chat messages. This follows a similar interface to a list in python. See the methods
339+
below for more information.
300340
301341
Args:
302-
chats (List[Message]): List of chat messages
303-
jl (Dict[str, Any]): Optional json-logic
342+
*chats: List of chat ``Message`` objects
343+
evals: JSON logic and
304344
"""
305345

306346
def __init__(
@@ -469,24 +509,24 @@ def _eval(self, out):
469509
evals[k] = tu.json_logic(e, {"response": out})
470510
return evals
471511

472-
def step_streaming(self, model: ModelInterface, /, eval: bool = False):
473-
out = ""
474-
for x in model.stream_chat(self):
475-
yield x
476-
if isinstance(x, dict):
477-
out = x
478-
else:
479-
out += x
480-
if eval:
481-
yield self._eval(out)
482-
self.append(assistant(out))
483-
484-
def step(self, model: ModelInterface, /, eval: bool = False):
485-
out = model.chat(self)
486-
self.append(assistant(out))
487-
if eval:
488-
return out, self._eval(out)
489-
return out
512+
# def step_streaming(self, model: ModelInterface, /, eval: bool = False):
513+
# out = ""
514+
# for x in model.stream_chat(self):
515+
# yield x
516+
# if isinstance(x, dict):
517+
# out = x
518+
# else:
519+
# out += x
520+
# if eval:
521+
# yield self._eval(out)
522+
# self.append(assistant(out))
523+
524+
# def step(self, model: ModelInterface, /, eval: bool = False):
525+
# out = model.chat(self)
526+
# self.append(assistant(out))
527+
# if eval:
528+
# return out, self._eval(out)
529+
# return out
490530

491531

492532
########################################################################################################################
@@ -699,7 +739,7 @@ def undo(self) -> "ThreadsTree":
699739

700740
def pick(self, to: Message = None, from_: Message = None) -> Thread:
701741
"""
702-
Get a thread from the Tree srtucture by telling ``to`` and ``from_`` in the tree
742+
A poerful methods to get a thread from the Tree srtucture by telling ``to`` and ``from_`` in the tree
703743
"""
704744
if self.system:
705745
thread = Thread(system(self.system))
@@ -844,7 +884,7 @@ def rollout(
844884
):
845885
# perform a full on rollout of the tree and provide necesary callbacks. The underlying threads contain
846886
# all the necessary information to perform the rollouts
847-
raise NotImplementedError("Not implemented yet")
887+
raise NotImplementedError("Not implemented yet, contact developers if urgent!")
848888

849889

850890
########################################################################################################################
@@ -1053,6 +1093,9 @@ def to_hf_dict(self) -> Tuple["datasets.DatasetDict", Dict[str, List]]: # type:
10531093
}
10541094

10551095
def to_disk(self, folder: str, fmt: Optional[str] = None):
1096+
"""
1097+
Serialise all the items of the container to a folder on the disk
1098+
"""
10561099
config = {}
10571100
config["type"] = "tune"
10581101
config["hf_type"] = fmt
@@ -1063,6 +1106,9 @@ def to_disk(self, folder: str, fmt: Optional[str] = None):
10631106

10641107
@classmethod
10651108
def from_disk(cls, folder: str):
1109+
"""
1110+
Deserialise and rebuild the container from a folder on the disk
1111+
"""
10661112
if not os.path.exists(folder):
10671113
raise ValueError(f"Folder '{folder}' does not exist")
10681114
if not os.path.exists(f"{folder}/train"):

tuneapi/types/experimental.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33

44
class Evals:
5+
"""
6+
A simple class containing different evaluation metrics. Each function is self explanatory and returns a JSON logic
7+
object.
8+
"""
9+
510
# small things like unit tests
611
def exactly(x):
712
return {"==": [{"var": "response"}, x]}

tuneapi/utils/code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def pyannotation_to_json_schema(
112112
allow_any (bool): Whether to allow the `Any` type.
113113
allow_exc (bool): Whether to allow the `Exception` type.
114114
allow_none (bool): Whether to allow the `None` type.
115-
trace (bool, optional): Adds verbosity the schema generation also set FURY_LOG_LEVEL='debug'. Defaults to False.
115+
trace (bool, optional): Adds verbosity the schema generation. Defaults to False.
116116
117117
Returns:
118118
Var: The converted annotation.

0 commit comments

Comments
 (0)