- Fix pass system_message argument in new feature openai_functions_agent (#6297)

can't pass system_message argument, the prompt always show default
message "System: You are a helpful AI assistant."
```
system_message = SystemMessage(
    content="You are an AI that provides information to Human regarding documentation."
)
agent = initialize_agent(
    tools,
    llm=openai_llm_chat,
    agent=AgentType.OPENAI_FUNCTIONS,
    system_message=system_message,
    agent_kwargs={
        "system_message": system_message,
    },
    verbose=False,
)
```

#### Who can review?

Tag maintainers/contributors who might be interested:

<!-- For a quicker response, figure out the right person to tag with @

  @hwchase17 - project lead

  Tracing / Callbacks
  - @agola11

  Async
  - @agola11

  DataLoaders
  - @eyurtsev

  Models
  - @hwchase17
  - @agola11

  Agents / Tools / Toolkits
  - @hwchase17

  VectorStores / Retrievers / Memory
  - @dev2049

 -->
This commit is contained in:
Ly Nguyen 2023-06-19 07:54:00 +07:00 committed by GitHub
parent e64bafed3a
commit 1e0af59f69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -236,12 +236,15 @@ class OpenAIFunctionsAgent(BaseSingleActionAgent):
llm: BaseLanguageModel, llm: BaseLanguageModel,
tools: Sequence[BaseTool], tools: Sequence[BaseTool],
callback_manager: Optional[BaseCallbackManager] = None, callback_manager: Optional[BaseCallbackManager] = None,
system_message: Optional[SystemMessage] = SystemMessage(
content="You are a helpful AI assistant."
),
**kwargs: Any, **kwargs: Any,
) -> BaseSingleActionAgent: ) -> BaseSingleActionAgent:
"""Construct an agent from an LLM and tools.""" """Construct an agent from an LLM and tools."""
if not isinstance(llm, ChatOpenAI): if not isinstance(llm, ChatOpenAI):
raise ValueError("Only supported with OpenAI models.") raise ValueError("Only supported with OpenAI models.")
prompt = cls.create_prompt() prompt = cls.create_prompt(system_message=system_message)
return cls( return cls(
llm=llm, llm=llm,
prompt=prompt, prompt=prompt,