File size: 3,676 Bytes
fbae247 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
from langchain import LLMChain, PromptTemplate
from agents.tools.smart_domain.common import getPrefix
from models import llm
from langchain.agents import tool
association_impl_architecture = """* Association Impletation: This component provide implementation of Association of domain layer, rely on Repository.
---eaxmple code:
@Component
@RequiredArgsConstructor
public class FeaturesImpl implements Features{{
private final FeatureDbRepository featureDbRepository;
Flux<Feature> findAll() {{
return featureDbRepository.findAll().map(FeatureDb::toFeature);
}}
Mono<Feature> save(Feature feature) {{
return featureDbRepository.save(FeatureDb.fromFeature(feature)).map(FeatureDb::toFeature);
}}
}}
---end of eaxmple code"""
association_impl_test_strategy="""For Association Impletation,we writ unit test, and stub repository method with Mockito.
---eaxmple code:
@ExtendWith(MockitoExtension.class)
class FeatureImplTest {{
@Mock
FeatureDbRepository repository;
Features features;
@BeforeEach
void setUp() {{
features = new FeaturesImpl(repository);
}}
@Test
void should_add_success() {{
when(repository.save(any(FeatureDb.class))).thenAnswer(invocation -> {{
FeatureDb featureDb = invocation.getArgument(0);
return Mono.just(featureDb);
}});
features.add(createFeature("featureKey1"))
.as(StepVerifier::create)
.expectNextMatches(config -> config.getId().featureKey().equals("featureKey1")
&& config.getDescription().updatedAt() != null
&& config.getDescription().createdAt() != null
)
.verifyComplete();
}}
@Test
void should_add_return_error_when_repository_save_error() {{
Feature feature = createFeature("featureKey1");
when(repository.save(any(FeatureDb.class))).thenReturn(Mono.error(new DuplicateKeyException("save error")));
features.add(feature)
.as(StepVerifier::create)
.expectError()
.verify();
}}
}}"""
association_impl_task = """Your task is to generate the Association Impletation tests and product code."""
association_impl_teck_stack = """Java17、reactor、lombok、Junit5、reactor test、Mockito、 Spring Data Reactive Couchbase"""
ASSOCIATION_IMPL = getPrefix(association_impl_task, association_impl_teck_stack, association_impl_architecture, association_impl_test_strategy) + """
Use the following format:
request: the request that you need to fulfill
Association Impletation:
```
the Association Impletation code that you write to fulfill the request, follow TechStack and Architecture
```
Test:
```
the test code of Association Impletation that you write to fulfill the request, follow TechStack Architecture and TestStrategy
```
request: {input}
"""
ASSOCIATION_IMPL_PROMOPT = PromptTemplate(input_variables=["input"], template=ASSOCIATION_IMPL,)
asociationChain = LLMChain(llm = llm(temperature=0.1), prompt=ASSOCIATION_IMPL_PROMOPT)
@tool("Generate Asociation Impletation Code", return_direct=True)
def asociationImplCodeGenerator(input: str) -> str:
'''useful for when you need to generate Asociation Impletation code'''
response = asociationChain.run(input)
return response |