Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Southpika committed Dec 22, 2023
2 parents 286f2bd + 7df8462 commit 7bdebf9
Show file tree
Hide file tree
Showing 67 changed files with 363 additions and 242 deletions.
20 changes: 20 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# .readthedocs.yaml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the version of Python and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.12"

mkdocs:
configuration: mkdocs.yml

# Optionally declare the Python requirements required to build your docs
python:
install:
- requirements: docs/requirements.txt
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ ERNIE Bot SDK提供便捷易用的接口,可以调用文心大模型的能力
![Supported Python versions](https://img.shields.io/badge/python-3.8+-orange.svg)
![Supported OSs](https://img.shields.io/badge/os-linux%2C%20win%2C%20mac-yellow.svg)

[![Built with Material for MkDocs](https://img.shields.io/badge/Material_for_MkDocs-526CFE?style=for-the-badge&logo=MaterialForMkDocs&logoColor=white)](https://squidfunk.github.io/mkdocs-material/)
</div>

## 最新动态
Expand Down
17 changes: 17 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Welcome to MkDocs

For full documentation visit [mkdocs.org](https://www.mkdocs.org).

## Commands

* `mkdocs new [dir-name]` - Create a new project.
* `mkdocs serve` - Start the live-reloading docs server.
* `mkdocs build` - Build the documentation site.
* `mkdocs -h` - Print help message and exit.

## Project layout

mkdocs.yml # The configuration file.
docs/
index.md # The documentation homepage.
... # Other markdown pages, images and other files.
10 changes: 10 additions & 0 deletions docs/package/erniebot_agent/agents.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

# Agent Module


::: erniebot_agent.agents.base
options:
summary: true
members:
- BaseAgent
- Agent
4 changes: 4 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mkdocs
mkdocstrings[python]
mkdocstrings-python
griffe
1 change: 1 addition & 0 deletions erniebot-agent/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
aiohttp
anyio
asyncio-atexit
# erniebot
jinja2
langchain
Expand Down
15 changes: 7 additions & 8 deletions erniebot-agent/src/erniebot_agent/agents/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import logging
from typing import Any, Dict, List, Literal, Optional, Union, final

from erniebot_agent import file_io
from erniebot_agent.agents.callback.callback_manager import CallbackManager
from erniebot_agent.agents.callback.default import get_default_callbacks
from erniebot_agent.agents.callback.handlers.base import CallbackHandler
Expand All @@ -28,11 +27,11 @@
ToolResponse,
)
from erniebot_agent.chat_models.base import ChatModel
from erniebot_agent.file_io import protocol
from erniebot_agent.file_io.base import File
from erniebot_agent.file_io.file_manager import FileManager
from erniebot_agent.file import get_global_file_manager, protocol
from erniebot_agent.file.base import File
from erniebot_agent.file.file_manager import FileManager
from erniebot_agent.memory import Message, SystemMessage
from erniebot_agent.memory.base import Memory
from erniebot_agent.messages import Message, SystemMessage
from erniebot_agent.tools.base import BaseTool
from erniebot_agent.tools.tool_manager import ToolManager
from erniebot_agent.utils.mixins import GradioMixin
Expand Down Expand Up @@ -78,7 +77,7 @@ def __init__(
else:
self._callback_manager = CallbackManager(callbacks)
if file_manager is None:
file_manager = file_io.get_global_file_manager()
file_manager = get_global_file_manager()
self.plugins = plugins
self._file_manager = file_manager
self._init_file_repr()
Expand Down Expand Up @@ -163,10 +162,10 @@ def _parse_tool_args(self, tool_args: str) -> Dict[str, Any]:
try:
args_dict = json.loads(tool_args)
except json.JSONDecodeError:
raise ValueError(f"`tool_args` cannot be parsed as JSON. `tool_args` is {tool_args}")
raise ValueError(f"`tool_args` cannot be parsed as JSON. `tool_args`: {tool_args}")

if not isinstance(args_dict, dict):
raise ValueError(f"`tool_args` cannot be interpreted as a dict. It loads as {args_dict} ")
raise ValueError(f"`tool_args` cannot be interpreted as a dict. `tool_args`: {tool_args}")
return args_dict

async def _sniff_and_extract_files_from_args(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from erniebot_agent.agents.callback.handlers.base import CallbackHandler
from erniebot_agent.agents.schema import AgentResponse, LLMResponse, ToolResponse
from erniebot_agent.chat_models.base import ChatModel
from erniebot_agent.messages import Message
from erniebot_agent.memory.messages import Message
from erniebot_agent.tools.base import BaseTool

if TYPE_CHECKING:
Expand Down Expand Up @@ -62,7 +62,7 @@ async def handle_event(self, event_type: EventType, *args: Any, **kwargs: Any) -
for handler in self._handlers:
callback = getattr(handler, callback_name, None)
if not inspect.iscoroutinefunction(callback):
raise TypeError("Callback must be a coroutine function.")
raise RuntimeError("Callback must be a coroutine function.")
await callback(*args, **kwargs)

async def on_run_start(self, agent: Agent, prompt: str) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from erniebot_agent.agents.schema import AgentResponse, LLMResponse, ToolResponse
from erniebot_agent.chat_models.base import ChatModel
from erniebot_agent.messages import Message
from erniebot_agent.memory import Message
from erniebot_agent.tools.base import BaseTool

if TYPE_CHECKING:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from erniebot_agent.agents.callback.handlers.base import CallbackHandler
from erniebot_agent.agents.schema import AgentResponse, LLMResponse, ToolResponse
from erniebot_agent.chat_models.base import ChatModel
from erniebot_agent.messages import Message
from erniebot_agent.memory import Message
from erniebot_agent.tools.base import BaseTool
from erniebot_agent.utils.json import to_pretty_json
from erniebot_agent.utils.output_style import ColoredContent
Expand Down
11 changes: 3 additions & 8 deletions erniebot-agent/src/erniebot_agent/agents/functional_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,10 @@
from erniebot_agent.agents.callback.handlers.base import CallbackHandler
from erniebot_agent.agents.schema import AgentAction, AgentFile, AgentResponse
from erniebot_agent.chat_models.base import ChatModel
from erniebot_agent.file_io.base import File
from erniebot_agent.file_io.file_manager import FileManager
from erniebot_agent.file.base import File
from erniebot_agent.file.file_manager import FileManager
from erniebot_agent.memory import FunctionMessage, HumanMessage, Message, SystemMessage
from erniebot_agent.memory.base import Memory
from erniebot_agent.messages import (
FunctionMessage,
HumanMessage,
Message,
SystemMessage,
)
from erniebot_agent.tools.base import BaseTool

_MAX_STEPS = 5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
AgentResponse,
ToolResponse,
)
from erniebot_agent.file_io.base import File
from erniebot_agent.messages import (
from erniebot_agent.file.base import File
from erniebot_agent.memory.messages import (
AIMessage,
FunctionMessage,
HumanMessage,
Expand Down
6 changes: 3 additions & 3 deletions erniebot-agent/src/erniebot_agent/agents/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
from dataclasses import dataclass
from typing import Dict, List, Literal, Optional, Tuple, Union

from erniebot_agent.file_io import protocol
from erniebot_agent.file_io.base import File
from erniebot_agent.messages import AIMessage, Message
from erniebot_agent.file import protocol
from erniebot_agent.file.base import File
from erniebot_agent.memory import AIMessage, Message


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion erniebot-agent/src/erniebot_agent/chat_models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from abc import ABCMeta, abstractmethod
from typing import Any, AsyncIterator, List, Literal, Union, overload

from erniebot_agent.messages import AIMessage, AIMessageChunk, Message
from erniebot_agent.memory.messages import AIMessage, AIMessageChunk, Message


class ChatModel(metaclass=ABCMeta):
Expand Down
2 changes: 1 addition & 1 deletion erniebot-agent/src/erniebot_agent/chat_models/erniebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from erniebot.response import EBResponse

from erniebot_agent.chat_models.base import ChatModel
from erniebot_agent.messages import (
from erniebot_agent.memory.messages import (
AIMessage,
AIMessageChunk,
FunctionCall,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def _stream(
**kwargs: Any,
) -> Iterator[ChatGenerationChunk]:
if stop is not None:
raise TypeError("Currently, `stop` is not supported when streaming is enabled.")
raise ValueError("Currently, `stop` is not supported when streaming is enabled.")
params = self._invocation_params
params.update(kwargs)
params["messages"] = self._convert_messages_to_dicts(messages)
Expand All @@ -195,7 +195,7 @@ async def _astream(
**kwargs: Any,
) -> AsyncIterator[ChatGenerationChunk]:
if stop is not None:
raise TypeError("Currently, `stop` is not supported when streaming is enabled.")
raise ValueError("Currently, `stop` is not supported when streaming is enabled.")
params = self._invocation_params
params.update(kwargs)
params["messages"] = self._convert_messages_to_dicts(messages)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def _stream(
**kwargs: Any,
) -> Iterator[GenerationChunk]:
if stop is not None:
raise TypeError("Currently, `stop` is not supported when streaming is enabled.")
raise ValueError("Currently, `stop` is not supported when streaming is enabled.")
params = self._invocation_params
params.update(kwargs)
params["messages"] = [self._build_user_message_from_prompt(prompt)]
Expand Down
Loading

0 comments on commit 7bdebf9

Please sign in to comment.