Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat/stream-config] Enable Stream config to avoid hardcode in base o… #302

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ RPM: 10
#OPENAI_API_VERSION: "YOUR_AZURE_API_VERSION"
#DEPLOYMENT_NAME: "YOUR_DEPLOYMENT_NAME"
#DEPLOYMENT_ID: "YOUR_DEPLOYMENT_ID"
STREAM: true

#### if zhipuai from `https://open.bigmodel.cn`. You can set here or export API_KEY="YOUR_API_KEY"
# ZHIPUAI_API_KEY: "YOUR_API_KEY"
Expand Down
1 change: 1 addition & 0 deletions metagpt/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def __init__(self, yaml_file=default_yaml_file):
self.max_tokens_rsp = self._get("MAX_TOKENS", 2048)
self.deployment_name = self._get("DEPLOYMENT_NAME")
self.deployment_id = self._get("DEPLOYMENT_ID")
self.stream = self._get("STREAM")

self.spark_appid = self._get("SPARK_APPID")
self.spark_api_secret = self._get("SPARK_API_SECRET")
Expand Down
7 changes: 5 additions & 2 deletions metagpt/provider/base_gpt_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class BaseGPTAPI(BaseChatbot):
"""GPT API abstract class, requiring all inheritors to provide a series of standard capabilities"""

stream = True
system_prompt = "You are a helpful assistant."

def _user_msg(self, msg: str) -> dict[str, str]:
Expand Down Expand Up @@ -45,14 +45,17 @@ async def aask(self, msg: str, system_msgs: Optional[list[str]] = None) -> str:
else:
message = [self._default_system_msg(), self._user_msg(msg)] if self.use_system_prompt \
else [self._user_msg(msg)]
rsp = await self.acompletion_text(message, stream=True)
rsp = await self.acompletion_text(message, stream=self.stream)
logger.debug(message)
# logger.debug(rsp)
return rsp

def _extract_assistant_rsp(self, context):
return "\n".join([i["content"] for i in context if i["role"] == "assistant"])

def set_stream(self, stream: bool):
self.stream = stream

def ask_batch(self, msgs: list) -> str:
context = []
for msg in msgs:
Expand Down
1 change: 1 addition & 0 deletions metagpt/provider/openai_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def __init__(self):

def __init_openai(self, config):
openai.api_key = config.openai_api_key
self.set_stream(config.stream)
if config.openai_api_base:
openai.api_base = config.openai_api_base
if config.openai_api_type:
Expand Down