Sweep: Update the docstrings and comments in sdks/python/julep/client.py to fix any issues and mismatch between the comments present and surrounding code
Closed this issue · 2 comments
See the rest of the python files in sdks/python/julep/ directory for context. Make sure that every comment matches the logic in the associated code. Overtime, comments may have drifted and accidentally not kept up with the code changes. Be concise and add new comments ONLY when necessary.
Checklist
-
sdks/python/julep/client.py
✨ Track Sweep's progress on our progress dashboard!
f23e7d46ed
)Tip
I can email you when I complete this pull request if you set up your email here!
Actions (click)
- ↻ Restart Sweep
Step 1: 🔎 Searching
I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.
Some code snippets I think are relevant in decreasing order of relevance (click to expand). If some file is missing from here, you can mention the path in the ticket description.
julep/sdks/python/julep/client.py
Lines 1 to 268 in 63738d5
from typing import Dict, Optional | |
from urllib.parse import urlparse | |
from beartype import beartype | |
import httpx | |
from openai import AsyncOpenAI, OpenAI | |
from openai.resources.chat.chat import AsyncChat, Chat | |
from openai.resources.completions import AsyncCompletions, Completions | |
# Note: This is just here because fern generates docs where it asks to: | |
# `from julep_ai.client import AsyncJulepApi, JulepApi` | |
from .api.client import AsyncJulepApi, JulepApi # noqa: F401 | |
from .env import JULEP_API_KEY, JULEP_API_URL | |
from .managers.agent import AgentsManager, AsyncAgentsManager | |
from .managers.user import UsersManager, AsyncUsersManager | |
from .managers.doc import DocsManager, AsyncDocsManager | |
from .managers.memory import MemoriesManager, AsyncMemoriesManager | |
from .managers.session import SessionsManager, AsyncSessionsManager | |
from .managers.tool import ToolsManager, AsyncToolsManager | |
from .utils.openai_patch import ( | |
patch_chat_acreate, | |
patch_chat_create, | |
patch_completions_acreate, | |
patch_completions_create, | |
) | |
# See Note above | |
__all__ = ["AsyncJulepApi", "JulepApi", "Client", "AsyncClient"] | |
def get_base_url(url): | |
return f"{urlparse(url).scheme}://{urlparse(url).netloc}" | |
class Client: | |
""" | |
A class that encapsulates managers for different aspects of a system and provides an interface for interacting with an API. | |
This class initializes and makes use of various manager classes to handle agents, users, sessions, documents, memories, and tools. It requires an API key and a base URL to initialize the API client that the managers will use. | |
Attributes: | |
agents (AgentsManager): A manager instance for handling agents. | |
users (UsersManager): A manager instance for handling users. | |
sessions (SessionsManager): A manager instance for handling sessions. | |
docs (DocsManager): A manager instance for handling documents. | |
memories (MemoriesManager): A manager instance for handling memories. | |
tools (ToolsManager): A manager instance for handling tools. | |
chat (Chat): A chat manager instance for handling chat interactions (based on OpenAI client). | |
completions (Completions): A manager instance for handling completions (based on OpenAI client). | |
Args: | |
api_key (Optional[str]): The API key needed to authenticate with the API. Defaults to the JULEP_API_KEY environment variable. | |
base_url (Optional[str]): The base URL for the API endpoints. Defaults to the JULEP_API_URL environment variable. | |
*args: Variable length argument list. | |
**kwargs: Arbitrary keyword arguments. | |
Raises: | |
AssertionError: If either `api_key` or `base_url` is not provided and not set as an environment variable. | |
Note: | |
`beartype` decorator is expected to ensure type checking on the parameters during runtime. The constants `JULEP_API_KEY` and `JULEP_API_URL` should be predefined and represent default values for the API key and base URL, respectively, which can be overridden by providing a value at instantiation. | |
""" | |
agents: AgentsManager | |
users: UsersManager | |
sessions: SessionsManager | |
docs: DocsManager | |
memories: MemoriesManager | |
tools: ToolsManager | |
chat: Chat | |
completions: Completions | |
@beartype | |
def __init__( | |
self, | |
api_key: Optional[str] = JULEP_API_KEY, | |
base_url: Optional[str] = JULEP_API_URL, | |
timeout: int = 300, | |
additional_headers: Dict[str, str] = {}, | |
_httpx_client: Optional[httpx.Client] = None, | |
*args, | |
**kwargs, | |
): | |
""" | |
Initialize a new client object with the given API key and base URL. | |
Args: | |
api_key (Optional[str]): The API key for authentication. If not provided, | |
the default is taken from the environment variable JULEP_API_KEY. | |
base_url (Optional[str]): The base URL for the API endpoints. If not provided, | |
the default is taken from the environment variable JULEP_API_URL. | |
*args: Variable length argument list. | |
**kwargs: Arbitrary keyword arguments. | |
Raises: | |
AssertionError: If either `api_key` or `base_url` is None, indicating they have | |
not been provided and are not set as environment variables. | |
Note: | |
This constructor populates the client with different resource managers like | |
agents, users, sessions, docs, memories, and tools, by initializing respective | |
manager classes with the provided API client configuration. | |
""" | |
assert ( | |
api_key is not None | |
), "api_key must be provided or set as env var JULEP_API_KEY" | |
assert ( | |
base_url is not None | |
), "base_url must be provided or set as env var JULEP_API_URL" | |
# Create an httpz client that follows redirects and has a timeout | |
httpx_client = _httpx_client or httpx.Client( | |
timeout=timeout, | |
headers=additional_headers, | |
follow_redirects=True, | |
) | |
self._api_client = JulepApi( | |
api_key=f"Bearer {api_key}", | |
base_url=base_url, | |
httpx_client=httpx_client, | |
*args, | |
**kwargs, | |
) | |
self.agents = AgentsManager(api_client=self._api_client) | |
self.users = UsersManager(api_client=self._api_client) | |
self.sessions = SessionsManager(api_client=self._api_client) | |
self.docs = DocsManager(api_client=self._api_client) | |
self.memories = MemoriesManager(api_client=self._api_client) | |
self.tools = ToolsManager(api_client=self._api_client) | |
# Set up the OpenAI client | |
openai_base_url = f"{get_base_url(base_url)}/v1" | |
self._openai_client = OpenAI( | |
api_key=api_key, | |
base_url=openai_base_url, | |
*args, | |
**kwargs, | |
) | |
# Patch the OpenAI client to pass non-openai params | |
patch_chat_create(self._openai_client) | |
patch_completions_create(self._openai_client) | |
self.chat = self._openai_client.chat | |
self.completions = self._openai_client.completions | |
class AsyncClient: | |
""" | |
A class representing an asynchronous client for interacting with various managers. | |
This class initializes asynchronous managers for agents, users, sessions, documents, memories, | |
and tools. It requires an API key and a base URL to establish a connection with the backend | |
service. If these are not explicitly provided, it looks for them in the environment variables. | |
Attributes: | |
agents (AsyncAgentsManager): Manager for handling agent-related interactions. | |
users (AsyncUsersManager): Manager for handling user-related interactions. | |
sessions (AsyncSessionsManager): Manager for handling session-related interactions. | |
docs (AsyncDocsManager): Manager for handling document-related interactions. | |
memories (AsyncMemoriesManager): Manager for handling memory-related interactions. | |
tools (AsyncToolsManager): Manager for handling tool-related interactions. | |
chat (AsyncChat): A chat manager instance for handling chat interactions (based on OpenAI client). | |
completions (AsyncCompletions): A manager instance for handling completions (based on OpenAI client). | |
Raises: | |
AssertionError: If `api_key` or `base_url` is not provided and also not set as an | |
environment variable. | |
Note: | |
The `api_key` and `base_url` can either be passed explicitly or set as environment | |
variables `JULEP_API_KEY` and `JULEP_API_URL`, respectively. | |
Args: | |
api_key (Optional[str]): The API key required to authenticate with the service. | |
Defaults to the value of the `JULEP_API_KEY` environment variable. | |
base_url (Optional[str]): The base URL of the API service. | |
Defaults to the value of the `JULEP_API_URL` environment variable. | |
*args: Variable length argument list. | |
**kwargs: Arbitrary keyword arguments. | |
""" | |
agents: AsyncAgentsManager | |
users: AsyncUsersManager | |
sessions: AsyncSessionsManager | |
docs: AsyncDocsManager | |
memories: AsyncMemoriesManager | |
tools: AsyncToolsManager | |
chat: AsyncChat | |
completions: AsyncCompletions | |
@beartype | |
def __init__( | |
self, | |
api_key: Optional[str] = JULEP_API_KEY, | |
base_url: Optional[str] = JULEP_API_URL, | |
*args, | |
**kwargs, | |
): | |
""" | |
Initialize the client with the provided API key and base URL. | |
This constructor sets up an asynchronous client for various service managers | |
like agents, users, sessions, documents, memories, and tools. | |
The 'beartype' decorator is used for runtime type checking on the given arguments. | |
The `api_key` and `base_url` must either be provided as arguments or set as | |
environment variables (`JULEP_API_KEY`, `JULEP_API_URL` respectively). | |
Args: | |
api_key (Optional[str]): The API key for authentication. If not provided, | |
it should be set as the environment variable 'JULEP_API_KEY'. | |
base_url (Optional[str]): The base URL of the API. If not provided, | |
it should be set as the environment variable 'JULEP_API_URL'. | |
*args: Variable length argument list to be passed to the `AsyncJulepApi`. | |
**kwargs: Arbitrary keyword arguments to be passed to the `AsyncJulepApi`. | |
Raises: | |
AssertionError: If `api_key` or `base_url` is not supplied either | |
through function arguments or environment variables. | |
Note: | |
The actual function signature does not explicitly show the environment variables | |
(`JULEP_API_KEY`, `JULEP_API_URL`) as default values for `api_key` and `base_url` | |
due to the limitations in using environment variables as default function argument values. | |
Instead, they must be handled within the body of the function. | |
""" | |
assert ( | |
api_key is not None | |
), "api_key must be provided or set as env var JULEP_API_KEY" | |
assert ( | |
base_url is not None | |
), "base_url must be provided or set as env var JULEP_API_URL" | |
self._api_client = AsyncJulepApi( | |
api_key=f"Bearer {api_key}", base_url=base_url, *args, **kwargs | |
) | |
self.agents = AsyncAgentsManager(api_client=self._api_client) | |
self.users = AsyncUsersManager(api_client=self._api_client) | |
self.sessions = AsyncSessionsManager(api_client=self._api_client) | |
self.docs = AsyncDocsManager(api_client=self._api_client) | |
self.memories = AsyncMemoriesManager(api_client=self._api_client) | |
self.tools = AsyncToolsManager(api_client=self._api_client) | |
# Set up the OpenAI client | |
openai_base_url = f"{get_base_url(base_url)}/v1" | |
self._openai_client = AsyncOpenAI( | |
api_key=api_key, | |
base_url=openai_base_url, | |
*args, | |
**kwargs, | |
) | |
# Patch the OpenAI client to pass non-openai params | |
patch_chat_acreate(self._openai_client) | |
patch_completions_acreate(self._openai_client) | |
self.chat = self._openai_client.chat |
julep/sdks/python/julep/managers/doc.py
Lines 1 to 470 in 63738d5
import json | |
from typing import Optional, TypedDict | |
from uuid import UUID | |
from beartype import beartype | |
from beartype.typing import Any, Awaitable, Dict, List, Union | |
from ..api.types import ( | |
CreateDoc, | |
Doc, | |
ResourceCreatedResponse, | |
GetAgentDocsResponse, | |
) | |
from .utils import rewrap_in_class | |
from .base import BaseManager | |
from .utils import is_valid_uuid4 | |
from .types import DocDict | |
class DocsCreateArgs(TypedDict): | |
agent_id: Optional[Union[str, UUID]] | |
user_id: Optional[Union[str, UUID]] | |
doc: DocDict | |
metadata: Dict[str, Any] = {} | |
class BaseDocsManager(BaseManager): | |
""" | |
Manages documents for agents or users by providing methods to get, create, and delete docsrmation. | |
The class utilizes an API client to interact with a back-end service that handles the document management operations. | |
Typical usage example: | |
docs_manager = BaseDocsManager(api_client) | |
agent_docs = docs_manager._list(agent_id="some-agent-uuid") | |
user_docs = docs_manager._list(user_id="some-user-uuid") | |
created_doc = docs_manager._create(agent_id="some-agent-uuid", doc={"key": "value"}) | |
docs_manager._delete(user_id="some-user-uuid", doc_id="some-doc-uuid") | |
Attributes: | |
api_client: A client instance used to make API calls to the document management system. | |
Methods: | |
_list(agent_id: Optional[Union[str, UUID]], user_id: Optional[Union[str, UUID]], | |
limit: Optional[int]=None, offset: Optional[int]=None) -> Union[GetAgentDocsResponse, Awaitable[GetAgentDocsResponse]] | |
Retrieves docsrmation for either an agent or user. | |
Must provide exactly one valid UUID v4 for either `agent_id` or `user_id`. | |
_create(agent_id: Optional[Union[str, UUID]], user_id: Optional[Union[str, UUID]], doc: DocDict) -> Union[ResourceCreatedResponse, Awaitable[ResourceCreatedResponse]] | |
Creates docsrmation for either an agent or user. | |
Must provide exactly one valid UUID v4 for either `agent_id` or `user_id`. | |
The `doc` parameter contains the document information to be created. | |
_delete(agent_id: Optional[Union[str, UUID]], user_id: Optional[Union[str, UUID]], doc_id: Union[str, UUID]): | |
Deletes docsrmation for either an agent or user. | |
Must provide exactly one valid UUID v4 for either `agent_id` or `user_id`, and a valid UUID for `doc_id`. | |
""" | |
def _list( | |
self, | |
agent_id: Optional[Union[str, UUID]], | |
user_id: Optional[Union[str, UUID]], | |
limit: Optional[int] = None, | |
offset: Optional[int] = None, | |
metadata_filter: Dict[str, Any] = {}, | |
) -> Union[GetAgentDocsResponse, Awaitable[GetAgentDocsResponse]]: | |
""" | |
Retrieve docsrmation for an agent or user based on their ID. | |
This internal method fetches docsrmation for either an agent or a user, | |
but not both. If both or neither `agent_id` and `user_id` are provided, it will | |
assert an error. | |
Args: | |
agent_id (Optional[Union[str, UUID]]): The UUID v4 of the agent for whom docs is requested, exclusive with `user_id`. | |
user_id (Optional[Union[str, UUID]]): The UUID v4 of the user for whom docs is requested, exclusive with `agent_id`. | |
limit (Optional[int]): The maximum number of records to return. Defaults to None. | |
offset (Optional[int]): The number of records to skip before starting to collect the response set. Defaults to None. | |
Returns: | |
Union[GetAgentDocsResponse, Awaitable[GetAgentDocsResponse]]: The response object containing docsrmation about the agent or user, or a promise of such an object if the call is asynchronous. | |
Raises: | |
AssertionError: If both `agent_id` and `user_id` are provided or neither is provided, or if the provided IDs are not valid UUID v4. | |
""" | |
metadata_filter_string = json.dumps(metadata_filter) | |
assert ( | |
(agent_id and is_valid_uuid4(agent_id)) | |
or (user_id and is_valid_uuid4(user_id)) | |
and not (agent_id and user_id) | |
), "One and only one of user_id or agent_id must be given and must be valid UUID v4" | |
if agent_id is not None: | |
return self.api_client.get_agent_docs( | |
agent_id=agent_id, | |
limit=limit, | |
offset=offset, | |
metadata_filter=metadata_filter_string, | |
) | |
if user_id is not None: | |
return self.api_client.get_user_docs( | |
user_id=user_id, | |
limit=limit, | |
offset=offset, | |
metadata_filter=metadata_filter_string, | |
) | |
def _create( | |
self, | |
doc: DocDict, | |
agent_id: Optional[Union[str, UUID]] = None, | |
user_id: Optional[Union[str, UUID]] = None, | |
metadata: Dict[str, Any] = {}, | |
) -> Union[ResourceCreatedResponse, Awaitable[ResourceCreatedResponse]]: | |
""" | |
Create a new resource with docsrmation for either an agent or a user, but not both. | |
This function asserts that exactly one of `agent_id` or `user_id` is provided and is a valid UUID v4. | |
It then creates the appropriate docsrmation based on which ID was provided. | |
Args: | |
agent_id (Optional[Union[str, UUID]]): The UUID of the agent or None. | |
user_id (Optional[Union[str, UUID]]): The UUID of the user or None. | |
doc (DocDict): A dictionary containing the document data for the resource being created. | |
Returns: | |
Union[ResourceCreatedResponse, Awaitable[ResourceCreatedResponse]]: The response after creating the resource, which could be immediate or an awaitable for asynchronous execution. | |
Raises: | |
AssertionError: If both `agent_id` and `user_id` are provided, neither are provided, or if the provided IDs are not valid UUID v4 strings. | |
Note: | |
One and only one of `agent_id` or `user_id` must be provided and must be a valid UUID v4. | |
The `DocDict` type should be a dictionary compatible with the `CreateDoc` schema. | |
""" | |
assert ( | |
(agent_id and is_valid_uuid4(agent_id)) | |
or (user_id and is_valid_uuid4(user_id)) | |
and not (agent_id and user_id) | |
), "One and only one of user_id or agent_id must be given and must be valid UUID v4" | |
doc: CreateDoc = CreateDoc(**doc) | |
if agent_id is not None: | |
return self.api_client.create_agent_doc( | |
agent_id=agent_id, | |
request=doc, | |
) | |
if user_id is not None: | |
return self.api_client.create_user_doc( | |
user_id=user_id, | |
request=doc, | |
) | |
def _delete( | |
self, | |
agent_id: Optional[Union[str, UUID]], | |
user_id: Optional[Union[str, UUID]], | |
doc_id: Union[str, UUID], | |
): | |
""" | |
Delete docs based on either an agent_id or a user_id. | |
This method selects the appropriate deletion operation (agent or user) based on whether an `agent_id` or `user_id` is provided. Only one of these ID types should be valid and provided. | |
Args: | |
agent_id (Optional[Union[str, UUID]]): A unique identifier of an agent. Either a string or UUID v4, but not both `agent_id` and `user_id`. | |
user_id (Optional[Union[str, UUID]]): A unique identifier of a user. Either a string or UUID v4, but not both `agent_id` and `user_id`. | |
doc_id (Union[str, UUID]): A unique identifier for docsrmation to be deleted, as a string or UUID v4. | |
Returns: | |
The result of the API deletion request. This can be the response object from the client's delete operation. | |
Raises: | |
AssertionError: If neither `agent_id` nor `user_id` is valid, if both are provided simultaneously, or if negation logic for valid UUIDs fails. | |
Other exceptions related to the `api_client` operations could potentially be raised and depend on its implementation. | |
""" | |
assert ( | |
(agent_id and is_valid_uuid4(agent_id)) | |
or (user_id and is_valid_uuid4(user_id)) | |
and not (agent_id and user_id) | |
), "One and only one of user_id or agent_id must be given and must be valid UUID v4" | |
if agent_id is not None: | |
return self.api_client.delete_agent_doc( | |
agent_id=agent_id, | |
doc_id=doc_id, | |
) | |
if user_id is not None: | |
return self.api_client.delete_user_doc( | |
user_id=user_id, | |
doc_id=doc_id, | |
) | |
class DocsManager(BaseDocsManager): | |
""" | |
A class responsible for managing documents. | |
This class provides methods for retrieving, creating, and deleting documents. It uses a base document management system to perform operations. | |
Attributes: | |
None specific to this class, as all are inherited from BaseDocsManager. | |
Methods: | |
get: | |
Retrieves a list of documents according to specified filters. | |
Args: | |
agent_id (Optional[Union[str, UUID]]): The agent's identifier to filter documents by, if any. | |
user_id (Optional[Union[str, UUID]]): The user's identifier to filter documents by, if any. | |
limit (Optional[int]): The maximum number of documents to be retrieved. | |
offset (Optional[int]): The number of documents to skip before starting to collect the document output list. | |
Returns: | |
List[Doc]: A list of documents matching the provided filters. | |
create: | |
Creates a new document. | |
Args: | |
agent_id (Optional[Union[str, UUID]]): The agent's identifier associated with the document, if any. | |
user_id (Optional[Union[str, UUID]]): The user's identifier associated with the document, if any. | |
doc (DocDict): The document to be created represented as a dictionary of document metadata. | |
Returns: | |
ResourceCreatedResponse: An object representing the creation response, typically containing the ID of the created document. | |
delete: | |
Deletes a document by its document identifier. | |
Args: | |
doc_id (Union[str, UUID]): The identifier of the document to be deleted. | |
agent_id (Optional[Union[str, UUID]]): The agent's identifier associated with the document, if any. | |
user_id (Optional[Union[str, UUID]]): The user's identifier associated with the document, if any. | |
Returns: | |
None, but the method may raise exceptions on failure. | |
""" | |
@beartype | |
def list( | |
self, | |
*, | |
agent_id: Optional[Union[str, UUID]] = None, | |
user_id: Optional[Union[str, UUID]] = None, | |
limit: Optional[int] = None, | |
offset: Optional[int] = None, | |
metadata_filter: Dict[str, Any] = {}, | |
) -> List[Doc]: | |
""" | |
Retrieve a list of documents based on specified criteria. | |
This method supports filtering the documents by agent_id or user_id, and also supports pagination through the limit and offset parameters. | |
Args: | |
agent_id (Optional[Union[str, UUID]]): The unique identifier for the agent. Can be a string or a UUID object. Default is None, which means no filtering by agent_id is applied. | |
user_id (Optional[Union[str, UUID]]): The unique identifier for the user. Can be a string or a UUID object. Default is None, which means no filtering by user_id is applied. | |
limit (Optional[int]): The maximum number of documents to retrieve. Default is None, which means no limit is applied. | |
offset (Optional[int]): The number of documents to skip before starting to collect the document list. Default is None, which means no offset is applied. | |
Returns: | |
List[Doc]: A list of documents that match the provided criteria. | |
Note: | |
The `@beartype` decorator is used to ensure that the input arguments are of the expected types. If an argument is passed that does not match the expected type, a type error will be raised. | |
""" | |
return self._list( | |
agent_id=agent_id, | |
user_id=user_id, | |
limit=limit, | |
offset=offset, | |
metadata_filter=metadata_filter, | |
).items | |
@beartype | |
@rewrap_in_class(Doc) | |
def create(self, **kwargs: DocsCreateArgs) -> Doc: | |
""" | |
Create a new resource with the specified document. | |
This method wraps a call to an internal '_create' method, passing along any | |
specified agent or user identifiers, along with the document data. | |
Args: | |
agent_id (Optional[Union[str, UUID]]): The agent identifier associated with the resource creation. | |
user_id (Optional[Union[str, UUID]]): The user identifier associated with the resource creation. | |
doc (DocDict): A dictionary containing the document data. | |
Returns: | |
ResourceCreatedResponse: An object representing the response for the resource creation operation. | |
Raises: | |
BeartypeException: If any input parameters are of incorrect type, due to type enforcement by the @beartype decorator. | |
""" | |
result = self._create(**kwargs) | |
return result | |
@beartype | |
def delete( | |
self, | |
*, | |
doc_id: Union[str, UUID], | |
agent_id: Optional[Union[str, UUID]] = None, | |
user_id: Optional[Union[str, UUID]] = None, | |
): | |
""" | |
Deletes a document by its identifier. | |
This function wraps the internal _delete method, providing an interface to delete documents by their ID while optionally specifying the agent ID and user ID. | |
Args: | |
doc_id (Union[str, UUID]): The unique identifier of the document to be deleted. | |
agent_id (Optional[Union[str, UUID]]): The unique identifier of the agent performing the delete operation, if any. | |
user_id (Optional[Union[str, UUID]]): The unique identifier of the user performing the delete operation, if any. | |
Returns: | |
The return type depends on the implementation of the `_delete` method. | |
Raises: | |
The exceptions raised depend on the implementation of the `_delete` method. | |
""" | |
return self._delete( | |
agent_id=agent_id, | |
user_id=user_id, | |
doc_id=doc_id, | |
) | |
class AsyncDocsManager(BaseDocsManager): | |
""" | |
A class for managing asynchronous operations on documents. | |
Inherits from BaseDocsManager to provide async document retrieval, creation, and deletion. | |
Attributes: | |
Inherited from BaseDocsManager. | |
Methods: | |
async list(self, *, agent_id: Optional[Union[str, UUID]] = None, user_id: Optional[Union[str, UUID]] = None, limit: Optional[int] = None, offset: Optional[int] = None) -> List[Doc]: | |
Asynchronously get a list of documents, with optional filtering based on agent_id, user_id, and pagination options limit and offset. | |
Args: | |
agent_id (Optional[Union[str, UUID]]): The agent's identifier to filter documents. | |
user_id (Optional[Union[str, UUID]]): The user's identifier to filter documents. | |
limit (Optional[int]): The maximum number of documents to return. | |
offset (Optional[int]): The offset from where to start returning documents. | |
Returns: | |
List[Doc]: A list of documents. | |
async create(self, *, agent_id: Optional[Union[str, UUID]] = None, user_id: Optional[Union[str, UUID]] = None, doc: DocDict) -> ResourceCreatedResponse: | |
Asynchronously create a new document with the given document information, and optional agent_id and user_id. | |
Args: | |
agent_id (Optional[Union[str, UUID]]): The agent's identifier associated with the document. | |
user_id (Optional[Union[str, UUID]]): The user's identifier associated with the document. | |
doc (DocDict): The document data to be created. | |
Returns: | |
ResourceCreatedResponse: A response object indicating successful creation of the document. | |
async delete(self, *, doc_id: Union[str, UUID], agent_id: Optional[Union[str, UUID]] = None, user_id: Optional[Union[str, UUID]] = None): | |
Asynchronously delete a document by its id, with optional association to a specific agent_id or user_id. | |
Args: | |
doc_id (Union[str, UUID]): The unique identifier of the document to be deleted. | |
agent_id (Optional[Union[str, UUID]]): The agent's identifier associated with the document, if applicable. | |
user_id (Optional[Union[str, UUID]]): The user's identifier associated with the document, if applicable. | |
Note: | |
The `@beartype` decorator is being used to perform runtime type checking on the function arguments. | |
""" | |
@beartype | |
async def list( | |
self, | |
*, | |
agent_id: Optional[Union[str, UUID]] = None, | |
user_id: Optional[Union[str, UUID]] = None, | |
limit: Optional[int] = None, | |
offset: Optional[int] = None, | |
metadata_filter: Dict[str, Any] = {}, | |
) -> List[Doc]: | |
""" | |
Asynchronously get a list of documents. | |
This function fetches documents based on the provided filtering criteria such as `agent_id`, `user_id`, | |
and supports pagination through `limit` and `offset`. | |
Args: | |
agent_id (Optional[Union[str, UUID]]): The ID of the agent to filter documents by. Default is None. | |
user_id (Optional[Union[str, UUID]]): The ID of the user to filter documents by. Default is None. | |
limit (Optional[int]): The maximum number of documents to return. Default is None. | |
offset (Optional[int]): The offset from where to start the document retrieval. Default is None. | |
Returns: | |
List[Doc]: A list of document objects. | |
Note: | |
The `@beartype` decorator is used to ensure that arguments conform to the expected types. | |
Raises: | |
BeartypeDecorHintPepParamException: If any of the parameters do not adhere to the declared types. | |
""" | |
return ( | |
await self._list( | |
agent_id=agent_id, | |
user_id=user_id, | |
limit=limit, | |
offset=offset, | |
metadata_filter=metadata_filter, | |
) | |
).items | |
@beartype | |
@rewrap_in_class(Doc) | |
async def create(self, **kwargs: DocsCreateArgs) -> Doc: | |
""" | |
Create a new resource asynchronously. | |
Args: | |
agent_id (Optional[Union[str, UUID]]): The ID of the agent. Default is None. | |
user_id (Optional[Union[str, UUID]]): The ID of the user. Default is None. | |
doc (DocDict): A dictionary containing document data. | |
Returns: | |
ResourceCreatedResponse: An object representing the response for a resource created. | |
Raises: | |
BeartypeException: If any of the input arguments do not match their expected types. This is implicitly raised due to the use of the beartype decorator. | |
""" | |
result = await self._create(**kwargs) | |
return result | |
@beartype | |
async def delete( | |
self, | |
*, | |
doc_id: Union[str, UUID], | |
agent_id: Optional[Union[str, UUID]] = None, | |
user_id: Optional[Union[str, UUID]] = None, | |
): | |
""" | |
Asynchronously deletes a document by its ID. | |
This function is a coroutine and must be awaited. | |
Args: | |
doc_id (Union[str, UUID]): The unique identifier of the document to delete. | |
agent_id (Optional[Union[str, UUID]]): The unique identifier of the agent, if any. | |
user_id (Optional[Union[str, UUID]]): The unique identifier of the user, if any. | |
Returns: | |
Coroutine[Any]: A coroutine that, when awaited, returns the result of the document deletion process. | |
Note: | |
The `@beartype` decorator is used to enforce type checking on the function arguments. | |
""" | |
# Assert either user_id or agent_id is provided | |
if not agent_id and not user_id: | |
raise ValueError("Either agent_id or user_id must be provided.") | |
return await self._delete( | |
agent_id=agent_id, | |
user_id=user_id, | |
doc_id=doc_id, |
Step 2: ⌨️ Coding
-
sdks/python/julep/client.py
Modify sdks/python/julep/client.py with contents:
• Review and update the module-level docstring to accurately describe the purpose and functionality of the `client.py` file, including its role in initializing and managing API clients and resources.
• For the `Client` class: - Update the class docstring to reflect any recent changes in the class's functionality or the resources it manages. - Ensure that the docstring for the `__init__` method accurately describes all parameters, their default values, and their purposes. Pay special attention to the `timeout` and `additional_headers` parameters, ensuring their descriptions are clear and concise. - Verify that the comments related to the OpenAI client setup (lines 137-148) accurately describe the process and purpose of patching the OpenAI client.
• For the `AsyncClient` class: - Update the class docstring to accurately reflect the asynchronous nature of the client and its methods. - In the `__init__` method, ensure that the docstring accurately describes the asynchronous initialization process, including any asynchronous-specific considerations or differences from the synchronous `Client` class. - Review the comments related to setting up the asynchronous OpenAI client (lines 254-265) for accuracy and clarity.
• Throughout the file, remove any outdated comments or docstrings that no longer apply to the current codebase. Add new comments only where necessary to clarify complex logic or important considerations that are not immediately obvious from the code itself.
• Ensure consistency in the style and format of docstrings and comments throughout the file, following the conventions used in other Python files within the `sdks/python/julep/` directory.
Step 3: 🔁 Code Review
Working on it...
🎉 Latest improvements to Sweep:
- New dashboard launched for real-time tracking of Sweep issues, covering all stages from search to coding.
- Integration of OpenAI's latest Assistant API for more efficient and reliable code planning and editing, improving speed by 3x.
- Use the GitHub issues extension for creating Sweep issues directly from your editor.
💡 To recreate the pull request edit the issue title or description.
Something wrong? Let us know.
This is an automated message generated by Sweep AI.
Actions (click)
- ↻ Restart Sweep
❌ Unable to Complete PR
I'm sorry, but it looks like an error has occurred due to a planning failure. Feel free to add more details to the issue description so Sweep can better address it. Alternatively, reach out to Kevin or William for help at https://discord.gg/sweep.
For bonus GPT-4 tickets, please report this bug on Discord (tracking ID: f23e7d46ed
).
Please look at the generated plan. If something looks wrong, please add more details to your issue.
File Path | Proposed Changes |
---|---|
sdks/python/julep/client.py |
Modify sdks/python/julep/client.py with contents: • Review and update the module-level docstring to accurately describe the purpose and functionality of the client.py file, including its role in initializing and managing API clients and resources.• For the Client class:- Update the class docstring to reflect any recent changes in the class's functionality or the resources it manages. - Ensure that the docstring for the __init__ method accurately describes all parameters, their default values, and their purposes. Pay special attention to the timeout and additional_headers parameters, ensuring their descriptions are clear and concise.- Verify that the comments related to the OpenAI client setup (lines 137-148) accurately describe the process and purpose of patching the OpenAI client. • For the AsyncClient class:- Update the class docstring to accurately reflect the asynchronous nature of the client and its methods. - In the __init__ method, ensure that the docstring accurately describes the asynchronous initialization process, including any asynchronous-specific considerations or differences from the synchronous Client class.- Review the comments related to setting up the asynchronous OpenAI client (lines 254-265) for accuracy and clarity. • Throughout the file, remove any outdated comments or docstrings that no longer apply to the current codebase. Add new comments only where necessary to clarify complex logic or important considerations that are not immediately obvious from the code itself. • Ensure consistency in the style and format of docstrings and comments throughout the file, following the conventions used in other Python files within the sdks/python/julep/ directory. |
🎉 Latest improvements to Sweep:
- New dashboard launched for real-time tracking of Sweep issues, covering all stages from search to coding.
- Integration of OpenAI's latest Assistant API for more efficient and reliable code planning and editing, improving speed by 3x.
- Use the GitHub issues extension for creating Sweep issues directly from your editor.
💡 To recreate the pull request edit the issue title or description.