-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add mirror plugin, null store explicitly configurable, and add test f…
…or null store
- Loading branch information
1 parent
699f447
commit 4aef434
Showing
8 changed files
with
247 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.meta.cp4m.llm; | ||
|
||
import com.meta.cp4m.message.Message; | ||
import com.meta.cp4m.message.ThreadState; | ||
import java.io.IOException; | ||
import java.time.Instant; | ||
|
||
public class MirrorPlugin<T extends Message> implements LLMPlugin<T> { | ||
|
||
@Override | ||
public T handle(ThreadState<T> threadState) throws IOException { | ||
return threadState.newMessageFromBot(Instant.now(), threadState.tail().message()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.meta.cp4m.llm; | ||
|
||
import com.meta.cp4m.message.Message; | ||
|
||
public record MirrorPluginConfig(String name) implements LLMConfig { | ||
|
||
@Override | ||
public <T extends Message> LLMPlugin<T> toPlugin() { | ||
return new MirrorPlugin<>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.meta.cp4m.store; | ||
|
||
import com.meta.cp4m.message.Message; | ||
|
||
public record NullStoreConfig(String name) implements StoreConfig { | ||
|
||
@Override | ||
public <T extends Message> ChatStore<T> toStore() { | ||
return new NullStore<>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.meta.cp4m.llm; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.dataformat.toml.TomlMapper; | ||
import com.meta.cp4m.Identifier; | ||
import com.meta.cp4m.configuration.ConfigurationUtils; | ||
import com.meta.cp4m.configuration.RootConfiguration; | ||
import com.meta.cp4m.message.FBMessage; | ||
import com.meta.cp4m.message.Message; | ||
import com.meta.cp4m.message.ThreadState; | ||
import java.io.IOException; | ||
import java.time.Instant; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class MirrorPluginTest { | ||
|
||
private static final String TOML = | ||
""" | ||
port = 8081 | ||
[[plugins]] | ||
name = "mirror_test" | ||
type = "mirror" | ||
[[stores]] | ||
name = "memory_test" | ||
type = "memory" | ||
storage_duration_hours = 1 | ||
storage_capacity_mbs = 1 | ||
[[handlers]] | ||
type = "messenger" | ||
name = "messenger_test" | ||
verify_token = "imgibberish" | ||
app_secret = "imnotasecret" | ||
page_access_token = "imnotasecreteither" | ||
[[services]] | ||
webhook_path = "/messenger" | ||
plugin = "mirror_test" | ||
store = "memory_test" | ||
handler = "messenger_test" | ||
"""; | ||
|
||
@Test | ||
void sanity() throws IOException { | ||
MirrorPlugin<FBMessage> plugin = new MirrorPlugin<>(); | ||
FBMessage output = | ||
plugin.handle( | ||
ThreadState.of( | ||
new FBMessage( | ||
Instant.now(), | ||
Identifier.random(), | ||
Identifier.random(), | ||
Identifier.random(), | ||
"test", | ||
Message.Role.USER))); | ||
assertThat(output.message()).isEqualTo("test"); | ||
} | ||
|
||
@Test | ||
void configLoads() throws JsonProcessingException { | ||
TomlMapper mapper = ConfigurationUtils.tomlMapper(); | ||
RootConfiguration config = | ||
ConfigurationUtils.tomlMapper() | ||
.convertValue(mapper.readTree(TOML), RootConfiguration.class); | ||
|
||
assertThat(config.toServicesRunner().services()) | ||
.hasSize(1) | ||
.allSatisfy(p -> assertThat(p.plugin()).isOfAnyClassIn(MirrorPlugin.class)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters