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

Global Config #1045

Merged
merged 46 commits into from
Aug 13, 2024
Merged

Global Config #1045

merged 46 commits into from
Aug 13, 2024

Conversation

collindutter
Copy link
Member

@collindutter collindutter commented Aug 6, 2024

Describe your changes

This change completely refactors how configuration is handled in the framework. Since the beginning we have relied on Structure to serve as the source of truth for configuration values. However, as the framework grew in complexity, it became increasingly difficult (and sometimes wrong) to propagate a Structure reference around in order to access these configuration values.

This PR introduces a global singleton, griptape.config.config, that stores these configuration values. Today, it stores configuration for drivers (previously called StructureConfig), and logging. The framework has been updated to pull from this object for default values.

Since this configuration now lives in the config object, I have removed these configuration values from Structure. Note that Agent.prompt_driver and Agent.stream were kept since the purpose of an Agent is to provide a syntactically concise way to create a Structure with either a PromptTask/ToolkitTask. These fields felt consistent with the other helper field: Agent.tools.


Overall I really like this change, but you might notice that not all drivers are included in DriversConfig. Does it makes sense to provide a default value for something like a WebScraperDriver? Or should this be left to the specific areas of the framework that require it? We could just provide a None default, but this may mask the fact that something like the WebSearch Tool does actually require one.


Changelog

Added:

  • Global config, griptape.config.config, for setting global configuration defaults.

Changed:

  • BREAKING: Removed Pipeline.prompt_driver and Workflow.prompt_driver. Agent.prompt_driver has not been removed.
  • BREAKING: Removed Pipeline.stream and Workflow.stream. Agent.stream has not been removed.
  • BREAKING: Removed Structure.embedding_driver, set this via griptape.config.config.drivers.embedding instead.
  • BREAKING: Removed Structure.custom_logger and Structure.logger_level, set these via griptape.config.config.logger instead.
  • Engines that previously required Drivers now pull from griptape.config.config.drivers by default.
  • BREAKING: Removed BaseStructureConfig.merge_config.
  • BREAKING: Renamed StructureConfig to DriverConfig, and renamed fields accordingly.

Issue ticket number and link

Closes #826 (merge_config is removed).


📚 Documentation preview 📚: https://griptape--1045.org.readthedocs.build//1045/

Copy link

codecov bot commented Aug 6, 2024

@collindutter collindutter force-pushed the refactor/global-config branch from e7cf26b to 4220e0f Compare August 7, 2024 23:57
@collindutter collindutter changed the base branch from dev to feature/event-bus August 7, 2024 23:57
@collindutter collindutter force-pushed the refactor/global-config branch from fc518f7 to daa1710 Compare August 8, 2024 19:52
@collindutter collindutter marked this pull request as ready for review August 8, 2024 20:04
@collindutter collindutter changed the title Refactor/global config Global Config Aug 8, 2024
@vachillo
Copy link
Member

vachillo commented Aug 8, 2024

can you write up the motivation for these changes and an example? hard to look at 123 files that seems like mostly small config changes and formatting

@collindutter collindutter requested a review from vachillo August 9, 2024 16:38
@collindutter
Copy link
Member Author

@vachillo updated the PR description with more context

griptape/utils/chat.py Outdated Show resolved Hide resolved
griptape/utils/chat.py Show resolved Hide resolved
griptape/utils/stream.py Outdated Show resolved Hide resolved
@collindutter collindutter requested a review from vachillo August 12, 2024 18:56
dylanholmes
dylanholmes previously approved these changes Aug 13, 2024
Copy link
Contributor

@dylanholmes dylanholmes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of comments, but they can be addressed in another PR if at all. No more revisions on this plz


### Changed
- **BREAKING**: Removed all uses of `EventPublisherMixin` in favor of `event_bus`.
- **BREAKING**: Removed `EventPublisherMixin`.
- **BREAKING**: Removed `Pipeline.prompt_driver` and `Workflow.prompt_driver`. `Agent.prompt_driver` has not been removed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's special about Agent.prompt_driver ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the PR description:

Note that Agent.prompt_driver and Agent.stream were kept since the purpose of an Agent is to provide a syntactically concise way to create a Structure with either a PromptTask/ToolkitTask. These fields felt consistent with the other helper field: Agent.tools.

Let me know if this is not a sufficient explanation, happy to go into more detail.


### Changed
- **BREAKING**: Removed all uses of `EventPublisherMixin` in favor of `event_bus`.
- **BREAKING**: Removed `EventPublisherMixin`.
- **BREAKING**: Removed `Pipeline.prompt_driver` and `Workflow.prompt_driver`. `Agent.prompt_driver` has not been removed.
- **BREAKING**: Removed `Pipeline.stream` and `Workflow.stream`. `Agent.stream` has not been removed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's special about Agent.stream?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replied above.

Comment on lines -131 to 134
Here is how you can override the Embedding Driver that is used by default in Structures.
Here is how you can override the Embedding Driver that is used by default in Structures.

```python
--8<-- "docs/griptape-framework/drivers/src/embedding_drivers_10.py"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separating the snippets from the docs makes proof reading more difficult

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, but the type checking/linting was essential during development.

Comment on lines 19 to 21
config.drivers = OpenAiDriverConfig(prompt=OpenAiChatPromptDriver(model="gpt-4o", stream=True))

pipeline = Pipeline()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems weird that we are "setting" the stream flag at this level. (like you don't know where it is going to be used yet and it could be used for streaming or not). Is changing that outside of the scope of this PR? If so, let's create a task to change it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I just moved the location to a more natural location.

task = ToolkitTask(self.input, tools=self.tools, max_meta_memory_entries=self.max_meta_memory_entries)
task = ToolkitTask(
self.input,
prompt_driver=self.prompt_driver,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not take this from config too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does. self.prompt_driver defaults to config.drivers.prompt

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I mean, why do we need prompt_driver on agent at all?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We technically don't, it's just a convenience field to avoid dealing with the configuration object.

else:
task = PromptTask(self.input, max_meta_memory_entries=self.max_meta_memory_entries)
task = PromptTask(
self.input, prompt_driver=self.prompt_driver, max_meta_memory_entries=self.max_meta_memory_entries
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, why not take prompt driver from config?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, updated stream to default to config.drivers.prompt.stream.

vachillo
vachillo previously approved these changes Aug 13, 2024
@collindutter collindutter dismissed stale reviews from vachillo and dylanholmes via 1ff7e88 August 13, 2024 17:36
dylanholmes
dylanholmes previously approved these changes Aug 13, 2024
Copy link
Contributor

@dylanholmes dylanholmes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine, but I replied to some comments

pipeline.add_tasks(
ToolkitTask(
"Based on https://griptape.ai, tell me what griptape is.",
prompt_driver=OpenAiChatPromptDriver(model="gpt-4o", stream=True),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose passing stream in to the driver works, but I think its a little confusing still. I'd expect either pipeline.run(stream=True) or maybe Pipeline(stream=True)...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A Pipeline may not contain any Tasks that use Prompt Drivers therefore streaming would be irrelevant. For Agents, it's always either be a Prompt Task or Toolkit Task (unless a user overrides tasks).

task = ToolkitTask(self.input, tools=self.tools, max_meta_memory_entries=self.max_meta_memory_entries)
task = ToolkitTask(
self.input,
prompt_driver=self.prompt_driver,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I mean, why do we need prompt_driver on agent at all?

@collindutter collindutter merged commit e600334 into dev Aug 13, 2024
13 checks passed
@collindutter collindutter deleted the refactor/global-config branch August 13, 2024 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Merge Config Does Not Reinitialize Non-Serializable Fields
3 participants