Skip to content

Commit

Permalink
Merge pull request #135 from rgbkrk/deprecate
Browse files Browse the repository at this point in the history
Trim down for 2.0
rgbkrk authored Feb 27, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents c3e75e6 + 5580d42 commit f063fd7
Showing 2 changed files with 2 additions and 94 deletions.
46 changes: 2 additions & 44 deletions chatlab/__init__.py
Original file line number Diff line number Diff line change
@@ -15,8 +15,6 @@
__author__ = """Kyle Kelley"""
__email__ = "[email protected]"

from deprecation import deprecated

from . import models
from ._version import __version__
from .chat import Chat
@@ -30,51 +28,12 @@
narrate,
system,
user,
tool_result
tool_result,
)
from .registry import FunctionRegistry
from spork import Markdown


# Deprecate Session in favor of Chat
class Session(Chat):
"""Interactive chats inside of computational notebooks, relying on OpenAI's API.
Session is deprecated. Use `Chat` instead.
"""

@deprecated(
deprecated_in="0.13.0",
removed_in="1.0.0",
current_version=__version__,
details="Use `Chat` instead.",
)
def __init__(self, *args, **kwargs):
"""Initialize a Session with an optional initial context of messages.
Session is deprecated. Use `Chat` instead."""
super().__init__(*args, **kwargs)


# Deprecate Session in favor of Chat
class Conversation(Chat):
"""Interactive chats inside of computational notebooks, relying on OpenAI's API.
Conversation is deprecated. Use `Chat` instead.
"""

@deprecated(
deprecated_in="1.0.0",
removed_in="1.1.0",
current_version=__version__,
details="Use `Chat` instead.",
)
def __init__(self, *args, **kwargs):
"""Initialize a Session with an optional initial context of messages.
Session is deprecated. Use `Chat` instead."""
super().__init__(*args, **kwargs)

__version__ = __version__

__all__ = [
"Markdown",
@@ -88,7 +47,6 @@ def __init__(self, *args, **kwargs):
"function_result",
"tool_result",
"models",
"Session",
"Chat",
"FunctionRegistry",
"ChatlabMetadata",
50 changes: 0 additions & 50 deletions chatlab/chat.py
Original file line number Diff line number Diff line change
@@ -17,14 +17,11 @@
from typing import Callable, List, Optional, Tuple, Type, Union, overload

import openai
from deprecation import deprecated
from IPython.core.async_helpers import get_asyncio_loop
from openai import AsyncOpenAI, AsyncStream
from openai.types import FunctionDefinition
from openai.types.chat import ChatCompletion, ChatCompletionChunk, ChatCompletionMessageParam
from pydantic import BaseModel

from ._version import __version__
from .errors import ChatLabError
from .messaging import assistant_tool_calls, human
from .registry import FunctionRegistry, PythonHallucinationFunction
@@ -123,22 +120,6 @@ def __init__(
if chat_functions is not None:
self.function_registry.register_functions(chat_functions)

@deprecated(
deprecated_in="0.13.0",
removed_in="1.0.0",
current_version=__version__,
details="Use `submit` instead.",
)
def chat(
self,
*messages: Union[ChatCompletionMessageParam, str],
):
"""Send messages to the chat model and display the response.
Deprecated in 0.13.0, removed in 1.0.0. Use `submit` instead.
"""
raise Exception("This method is deprecated. Use `submit` instead.")

async def __call__(self, *messages: Union[ChatCompletionMessageParam, str], stream=True, **kwargs):
"""Send messages to the chat model and display the response."""
return await self.submit(*messages, stream=stream, **kwargs)
@@ -464,34 +445,3 @@ def __repr__(self):
return "<ChatLab 1 message>"

return f"<ChatLab {len(self.messages)} messages>"

def ipython_magic_submit(self, line, cell: Optional[str] = None, **kwargs):
"""Submit a cell to the ChatLab instance."""
# Line is currently unused, allowing for future expansion into allowing
# sending messages with other roles.

if cell is None:
return
cell = cell.strip()

asyncio.run_coroutine_threadsafe(self.submit(cell, **kwargs), get_asyncio_loop())

def make_magic(self, name):
"""Register the chat as an IPython magic with the given name.
In [1]: chat = Chat()
In [2]: chat.make_magic("chat")
In [3]: %%chat
...:
...: Lets chat!
...:
Out[3]: Sure, I'd be happy to chat! What's on your mind?
"""
from IPython.core.getipython import get_ipython

ip = get_ipython()
if ip is None:
raise Exception("IPython is not available.")

ip.register_magic_function(self.ipython_magic_submit, magic_kind="line_cell", magic_name=name)

0 comments on commit f063fd7

Please sign in to comment.