Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ __pycache__/

# Distribution / packaging
.Python
.python-version
build/
develop-eggs/
dist/
Expand Down
4 changes: 2 additions & 2 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

first release version.

## v0.1.2
## v0.1.3

fix import `Self` from `typing`, incompatible to python 3.10.
fix not import some libs from `typing_extensions` but `typing` , incompatible to python 3.10.

## v0.1.1

Expand Down
3 changes: 2 additions & 1 deletion ghostos/abcd/realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
from abc import ABC, abstractmethod
from typing import (
Generic,
List, Iterable, Tuple, TypeVar, Optional, Dict, Callable, Union, Self
List, Iterable, Tuple, TypeVar, Optional, Dict, Callable, Union
)
from typing_extensions import Self
from ghostos.abcd import Conversation
from ghostos.core.messages import Message, ReceiverBuffer
from ghostos.entity import ModelEntityMeta, to_entity_model_meta, from_entity_model_meta
Expand Down
6 changes: 4 additions & 2 deletions ghostos/core/llms/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import os

from typing import List, Dict, Optional, Any, ClassVar, Literal
from typing import List, Dict, Optional, Any, ClassVar
from typing_extensions import Literal
from pydantic import BaseModel, Field
from ghostos.core.messages import Payload
from ghostos.helpers import gettext as _

# from ghostos.helpers import gettext as _

__all__ = [
'ModelConf', 'ServiceConf', 'LLMsConfig',
Expand Down
3 changes: 2 additions & 1 deletion ghostos/core/llms/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from abc import ABC, abstractmethod

from typing import List, Iterable, Optional, Union, Callable, Self, Set
from typing import List, Iterable, Optional, Union, Callable, Set
from typing_extensions import Self
from openai.types.chat.completion_create_params import Function, FunctionCall
from openai import NotGiven, NOT_GIVEN
from openai.types.chat.chat_completion_function_call_option_param import ChatCompletionFunctionCallOptionParam
Expand Down
4 changes: 2 additions & 2 deletions ghostos/core/messages/message_classes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import base64
from typing import Optional, Dict, List, Iterable, Any, Union, Literal
from typing_extensions import Self
from typing import Optional, Dict, List, Iterable, Any, Union
from typing_extensions import Self, Literal

from ghostos.contracts.variables import Variables
from ghostos.contracts.assets import FileInfo
Expand Down
5 changes: 2 additions & 3 deletions ghostos/core/messages/transport.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations
from typing import Iterable, Optional, Tuple, List, Self, Iterator

from typing_extensions import Protocol
from typing import Iterable, Optional, Tuple, List, Iterator
from typing_extensions import Protocol, Self
from collections import deque
from abc import abstractmethod
from ghostos.core.messages.message import Message, MessageType
Expand Down
3 changes: 2 additions & 1 deletion ghostos/core/moss/abcd.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations
from typing import Dict, Any, Union, List, Optional, NamedTuple, Type, Callable, Self, TypeVar, ClassVar
from typing import Dict, Any, Union, List, Optional, NamedTuple, Type, Callable, TypeVar, ClassVar
from typing_extensions import Self
from types import ModuleType
from abc import ABC, abstractmethod
from ghostos.container import Container, Provider, Factory, provide
Expand Down
3 changes: 2 additions & 1 deletion ghostos/core/moss/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import inspect
import re
from typing import Any, Dict, Callable, Optional, List, Iterable, TypedDict, is_typeddict
from typing import Any, Callable, Optional, List, Iterable
from typing_extensions import TypedDict, is_typeddict
from pydantic import BaseModel

__all__ = [
Expand Down
3 changes: 2 additions & 1 deletion ghostos/core/runtime/tasks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Optional, List, ClassVar, Dict, Self
from typing import Optional, List, ClassVar, Dict
from typing_extensions import Self
from abc import ABC, abstractmethod
from enum import Enum
from pydantic import BaseModel, Field
Expand Down
3 changes: 2 additions & 1 deletion ghostos/core/runtime/threads.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Optional, List, Iterable, Dict, Any, Self
from typing import Optional, List, Iterable, Dict, Any
from typing_extensions import Self
from abc import ABC, abstractmethod
from pydantic import BaseModel, Field
from ghostos.core.messages import Message, copy_messages, Role
Expand Down
3 changes: 2 additions & 1 deletion ghostos/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import json
from abc import ABC, abstractmethod
from typing import Union, Any, TypedDict, Required, Self, TypeVar, Type, Optional, Protocol
from typing import Union, Any, TypeVar, Type, Optional, Protocol
from typing_extensions import Required, Self, TypedDict
from types import ModuleType
from pydantic import BaseModel
from ghostos.helpers import generate_import_path, import_from_path, parse_import_path_module_and_attr_name
Expand Down
5 changes: 3 additions & 2 deletions ghostos/framework/ghostos/taskflow_impl.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from __future__ import annotations

from typing import Union, List, Self
from typing import Union, List
from typing_extensions import Self
from abc import ABC

from ghostos.container import Container
from ghostos.abcd import Taskflow, Session, Operator
from ghostos.abcd import fire_session_event
from ghostos.core.runtime import TaskState, EventTypes, TaskBrief
from ghostos.core.moss import Injection, MossRuntime
from ghostos.core.messages import MessageKind, MessageKindParser, Message, Role, MessageType
from ghostos.core.messages import MessageKind, MessageKindParser, Message, Role
from pprint import pprint
from contextlib import redirect_stdout
from io import StringIO
Expand Down
3 changes: 2 additions & 1 deletion ghostos/framework/openai_realtime/configs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import ClassVar, Optional, Self
from typing import ClassVar, Optional
from typing_extensions import Self
from ghostos.abcd.realtime import RealtimeAppConfig
from ghostos.contracts.configs import YamlConfig
from ghostos.framework.openai_realtime.event_data_objects import SessionObject
Expand Down
3 changes: 2 additions & 1 deletion ghostos/framework/openai_realtime/event_data_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import base64

from pydantic import BaseModel, Field
from typing import Optional, Literal, List, Union, Dict
from typing import Optional, List, Union, Dict
from typing_extensions import Literal
from io import BytesIO
from ghostos.core.messages import (
MessageType, Message, AudioMessage, FunctionCallMessage, FunctionCallOutputMessage,
Expand Down
2 changes: 1 addition & 1 deletion ghostos/framework/openai_realtime/event_from_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional, ClassVar, Self
from typing import Optional, ClassVar
from abc import ABC
from enum import Enum
from pydantic import BaseModel, Field
Expand Down
4 changes: 2 additions & 2 deletions ghostos/framework/openai_realtime/event_from_server.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import base64
from typing import Self, List, Optional, Union, ClassVar
from typing import List, Optional, Union, ClassVar
from typing_extensions import Self
from abc import ABC
from enum import Enum
from pydantic import BaseModel, Field
from ghostos.core.messages import Message as GhostOSMessage, MessageType
from ghostos.framework.openai_realtime.event_data_objects import (
RateLimit, Response, MessageItem,
DeltaIndex, ConversationObject, Error, SessionObject,
ResponseSettings,
Content,
)

Expand Down
3 changes: 2 additions & 1 deletion ghostos/framework/openai_realtime/state_of_client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations
from typing import List, Optional, Tuple, Protocol, Self
from typing import List, Optional, Protocol
from typing_extensions import Self
from abc import ABC, abstractmethod
from ghostos.framework.openai_realtime.configs import OpenAIRealtimeAppConf
from ghostos.core.runtime import Event as GhostOSEvent
Expand Down
3 changes: 2 additions & 1 deletion ghostos/framework/openai_realtime/state_of_server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations
from abc import ABC, abstractmethod
from typing import Protocol, Optional, Dict, Self, List, Union
from typing import Protocol, Optional, Dict, List, Union
from typing_extensions import Self
from ghostos.framework.openai_realtime.event_from_server import *
from ghostos.framework.openai_realtime.event_data_objects import (
MessageItem,
Expand Down
3 changes: 2 additions & 1 deletion ghostos/ghosts/moss_agent/agent.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Union, Optional, Dict, List, Self, Iterable, Tuple, ClassVar
from typing import Union, Optional, Dict, List, Iterable, Tuple, ClassVar
from typing_extensions import Self
from types import ModuleType

from ghostos.identifier import Identifier
Expand Down
3 changes: 2 additions & 1 deletion ghostos/prompter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import inspect
from typing import (
List, Self, Union, Callable, Any, Protocol, Optional, Dict, TypeVar, Type, Generic, Set,
List, Union, Callable, Any, Protocol, Optional, Dict, TypeVar, Type, Generic,
)
from typing_extensions import Self
from abc import ABC, abstractmethod
from types import ModuleType
from ghostos.container import Container
Expand Down
3 changes: 2 additions & 1 deletion ghostos/prototypes/spherogpt/bolt/ball_impl.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Literal, Optional, Callable, Self, Dict, Tuple
from typing import Optional, Callable, Dict, Tuple
from typing_extensions import Self, Literal

from spherov2.commands.io import FrameRotationOptions

Expand Down
3 changes: 2 additions & 1 deletion ghostos/scripts/cli/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations
import sys
from typing import Tuple, List, NamedTuple, Any, Optional, Dict, Self
from typing import Tuple, List, NamedTuple, Any, Optional, Dict
from typing_extensions import Self
from types import ModuleType

from ghostos.bootstrap import expect_workspace_dir
Expand Down
18 changes: 8 additions & 10 deletions ghostos/streamlit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Protocol, Self, TypeVar, Optional, NamedTuple, Generic
from typing import Protocol, Optional, NamedTuple, Any
from abc import ABC, abstractmethod

__all__ = [
Expand All @@ -8,39 +8,37 @@
'Rendered',
]

T = TypeVar('T')


class Rendered(Generic[T], NamedTuple):
value: T
class Rendered(NamedTuple):
value: Any
changed: bool


class StreamlitRenderable(Protocol):

@abstractmethod
def __streamlit_render__(self) -> Optional[Rendered[Self]]:
def __streamlit_render__(self) -> Optional[Rendered]:
pass


class StreamlitObject(ABC):
@abstractmethod
def __streamlit_render__(self) -> Optional[Rendered[Self]]:
def __streamlit_render__(self) -> Optional[Rendered]:
pass


class StreamlitRenderer(ABC):

@abstractmethod
def render(self, value: T) -> Optional[Rendered[T]]:
def render(self, value) -> Optional[Rendered]:
pass


class GroupRenderer(StreamlitRenderer):
def __init__(self, *renderers: StreamlitRenderer):
self.renderers = list(renderers)

def render(self, value: T) -> Optional[Rendered[T]]:
def render(self, value) -> Optional[Rendered]:
for renderer in self.renderers:
result = renderer.render(value)
if result is None:
Expand All @@ -53,7 +51,7 @@ def is_streamlit_renderable(obj):
return isinstance(obj, StreamlitObject) or hasattr(obj, "__streamlit_render__")


def render_streamlit_object(obj: T) -> Optional[Rendered[T]]:
def render_streamlit_object(obj) -> Optional[Rendered]:
if is_streamlit_renderable(obj):
fn = getattr(obj, "__streamlit_render__", None)
if fn is not None:
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ghostos"
version = "0.1.2"
version = "0.1.3"
description = "A framework offers an operating system simulator with a Python Code Interface for AI Agents"
authors = ["zhuming <thirdgerb@gmail.com>", "Nile Zhou <nilezhou123@gmail.com>"]
license = "MIT"
Expand All @@ -13,7 +13,7 @@ documentation = "https://ghost-in-moss.github.io/GhostOS/#/en/"
issues = "https://github.com/ghost-in-moss/GhostOS/issues"

[tool.poetry.dependencies]
python = ">=3.9,<3.14,!=3.9.7"
python = ">=3.10,<3.14"
pydantic = "^2.7.0"
openai = "^1.19.0"
pyyaml = "^6.0.1"
Expand Down
4 changes: 4 additions & 0 deletions tests/core/aifuncs/test_aifunc_repository.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
from ghostos.core.aifunc import AIFuncRepoByConfigsProvider, AIFuncRepository, AIFuncsConf
from ghostos.framework.configs import Configs, MemoryConfigs
from ghostos.contracts.modules import Modules, DefaultModules
from ghostos.contracts.workspace import Workspace
from ghostos.framework.workspaces import BasicWorkspace
from ghostos.framework.storage import MemStorage
from ghostos.container import Container
from ghostos.demo import aifuncs_demo


def test_aifunc_repository():
container = Container()
container.set(Modules, DefaultModules())
container.set(Workspace, BasicWorkspace(MemStorage()))
container.set(Configs, MemoryConfigs({
AIFuncsConf.conf_path(): "{}",

Expand Down
2 changes: 1 addition & 1 deletion tests/core/moss/test_callable.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,4 @@ def test_get_callable_definition_with_abstractmethod():
from abc import abstractmethod
assert not inspect.isbuiltin(abstractmethod)
code = get_callable_definition(abstractmethod)
assert code == ""
assert code != ""
58 changes: 29 additions & 29 deletions tests/python/test_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,32 @@ async def foo():
lp = asyncio.new_event_loop()
lp.run_until_complete(foo())


def test_producer_and_consumer():
class Main:
stop = False

got = []

async def _producer(self, q: asyncio.Queue):
count = 0
while not self.stop:
q.put_nowait(count)
count += 1
await asyncio.sleep(0.1)

async def _consumer(self, q: asyncio.Queue):
while not self.stop:
v = await q.get()
self.got.append(v)
self.stop = v > 2

async def run(self):
async with asyncio.TaskGroup() as tg:
q = asyncio.Queue()
tg.create_task(self._producer(q))
tg.create_task(self._consumer(q))

main = Main()
asyncio.run(main.run())
assert main.got == [0, 1, 2, 3]
# for 3.12
# def test_producer_and_consumer():
# class Main:
# stop = False
#
# got = []
#
# async def _producer(self, q: asyncio.Queue):
# count = 0
# while not self.stop:
# q.put_nowait(count)
# count += 1
# await asyncio.sleep(0.1)
#
# async def _consumer(self, q: asyncio.Queue):
# while not self.stop:
# v = await q.get()
# self.got.append(v)
# self.stop = v > 2
#
# async def run(self):
# async with asyncio.TaskGroup() as tg:
# q = asyncio.Queue()
# tg.create_task(self._producer(q))
# tg.create_task(self._consumer(q))
#
# main = Main()
# asyncio.run(main.run())
# assert main.got == [0, 1, 2, 3]
3 changes: 2 additions & 1 deletion tests/python/test_dict.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import TypedDict, Optional
from typing import Optional
from typing_extensions import TypedDict


def test_dict_items():
Expand Down
Loading