oocana 0.16.5__tar.gz → 0.16.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: oocana
3
- Version: 0.16.5
3
+ Version: 0.16.7
4
4
  Summary: python implement of oocana to give a context for oocana block
5
5
  License: MIT
6
6
  Requires-Python: >=3.9
@@ -136,7 +136,7 @@ class Context:
136
136
  "api_key": os.getenv("OOMOL_LLM_API_KEY", ""),
137
137
  "models": os.getenv("OOMOL_LLM_MODELS", "").split(","),
138
138
  }
139
-
139
+
140
140
  @property
141
141
  def host_info(self) -> HostInfo:
142
142
  """this is a dict contains the host information
@@ -145,7 +145,17 @@ class Context:
145
145
  "gpu_vendor": os.getenv("OOMOL_HOST_GPU_VENDOR", "unknown"),
146
146
  "gpu_renderer": os.getenv("OOMOL_HOST_GPU_RENDERER", "unknown"),
147
147
  }
148
-
148
+
149
+ @property
150
+ def host_endpoint(self) -> str | None:
151
+ """A host endpoint that allows containers to access services running on the host system.
152
+
153
+ Returns:
154
+ str: The host endpoint if available.
155
+ None: If the application is running in a cloud environment where no host endpoint is defined.
156
+ """
157
+ return os.getenv("OO_HOST_ENDPOINT", None)
158
+
149
159
  @property
150
160
  def is_done(self) -> bool:
151
161
  return self.__is_done
@@ -255,6 +265,11 @@ class Context:
255
265
  )
256
266
 
257
267
  def __dataframe(self, payload: PreviewPayload) -> PreviewPayload:
268
+ def not_default_index(df: DataFrame) -> bool:
269
+ index = df.index.tolist()
270
+ default_index = list(range(len(df)))
271
+ return index != default_index
272
+
258
273
  if isinstance(payload, DataFrame):
259
274
  payload = { "type": "table", "data": payload }
260
275
 
@@ -266,12 +281,28 @@ class Context:
266
281
  data = df.to_dict(orient='split')
267
282
  columns = data.get("columns", [])
268
283
  rows = data.get("data", [])
284
+ if not_default_index(df):
285
+ index = df.index.tolist()
286
+ rows = [[index[i], *rows[i]] for i in range(len(rows))]
287
+ columns = ["", *columns]
288
+
269
289
  elif isinstance(df, PartialDataFrame):
270
- data_columns = loads(df.head(5).to_json(orient='split'))
271
- columns = data_columns.get("columns", [])
272
- rows_head = data_columns.get("data", [])
273
- data_tail = loads(df.tail(5).to_json(orient='split'))
274
- rows_tail = data_tail.get("data", [])
290
+ need_add_index = not_default_index(df)
291
+ head_data = df.head(5).to_dict(orient='split')
292
+ columns = head_data.get("columns", [])
293
+
294
+ rows_head = head_data.get("data", [])
295
+ if need_add_index:
296
+ columns = ["", *columns]
297
+ head_index = head_data.get("index", [])
298
+ rows_head = [[head_index[i], *rows_head[i]] for i in range(len(rows_head))]
299
+
300
+ tail_data = df.tail(5).to_dict(orient='split')
301
+ rows_tail = tail_data.get("data", [])
302
+ if need_add_index:
303
+ tail_index = tail_data.get("index", [])
304
+ rows_tail = [[tail_index[i], *rows_tail[i]] for i in range(len(rows_tail))]
305
+
275
306
  rows_dots = [["..."] * len(columns)]
276
307
  rows = rows_head + rows_dots + rows_tail
277
308
  else:
@@ -3,20 +3,26 @@ from typing import Any, TypedDict, List, Literal, TypeAlias, Union, Protocol, ru
3
3
 
4
4
  __all__ = ["PreviewPayload", "TablePreviewPayload", "TextPreviewPayload", "JSONPreviewPayload", "ImagePreviewPayload", "MediaPreviewPayload", "PandasPreviewPayload", "DefaultPreviewPayload"]
5
5
 
6
+ @runtime_checkable
7
+ class DataFrameIndex(Protocol):
8
+ def tolist(self) -> Any:
9
+ ...
10
+
6
11
  # this class is for pandas.DataFrame
7
12
  @runtime_checkable
8
13
  class DataFrame(Protocol):
9
14
 
10
- def __dataframe__(self, *args: Any, **kwargs: Any) -> Any:
15
+ def __len__(self) -> int:
11
16
  ...
12
17
 
13
- def to_dict(self, *args: Any, **kwargs: Any) -> Any:
18
+ def __dataframe__(self, *args: Any, **kwargs: Any) -> Any:
14
19
  ...
15
20
 
16
- @runtime_checkable
17
- class JsonAble(Protocol):
21
+ @property
22
+ def index(self) -> DataFrameIndex:
23
+ ...
18
24
 
19
- def to_json(self, *args: Any, **kwargs: Any) -> Any:
25
+ def to_dict(self, orient: Literal["split"]) -> Any:
20
26
  ...
21
27
 
22
28
  @runtime_checkable
@@ -27,11 +33,11 @@ class ShapeDataFrame(DataFrame, Protocol):
27
33
  ...
28
34
 
29
35
  @runtime_checkable
30
- class PartialDataFrame(Protocol):
31
- def head(self, *args: Any, **kwargs: Any) -> JsonAble:
36
+ class PartialDataFrame(DataFrame, Protocol):
37
+ def head(self, count: int) -> DataFrame:
32
38
  ...
33
39
 
34
- def tail(self, *args: Any, **kwargs: Any) -> JsonAble:
40
+ def tail(self, count: int) -> DataFrame:
35
41
  ...
36
42
 
37
43
  class TablePreviewData(TypedDict):
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "oocana"
3
- version = "0.16.5"
3
+ version = "0.16.7"
4
4
  description = "python implement of oocana to give a context for oocana block"
5
5
  dependencies = [
6
6
  "paho-mqtt>=2",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes