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

Implement munit for agent api #23

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,45 @@
http://www.mulesoft.org/schema/mule/munit http://www.mulesoft.org/schema/mule/munit/current/mule-munit.xsd
http://www.mulesoft.org/schema/mule/munit-tools http://www.mulesoft.org/schema/mule/munit-tools/current/mule-munit-tools.xsd
http://www.mulesoft.org/schema/mule/mulechain http://www.mulesoft.org/schema/mule/mulechain/current/mule-mulechain.xsd">
<munit:config name="mulechain-llm-operation-testing-suite.xml" />
<munit:config name="langchain-llm-operation-testing-suite.xml" />
<mulechain:llm-configuration-config name="OPENAI" llmType="OPENAI" configType="Configuration Json" doc:name="MuleChain AI Llm configuration"
doc:id="74b85066-1569-4f10-a06b-e49e854eeef2"
filePath='/Users/dipeshkumar.dutta/src/open/mulechain-ai-connector/src/test/resources/envVars.json'
temperature="0.1"/>
filePath='${app.home}/envVars.json'
temperature="0.1"/>
<munit:test name="ChatAnswerPrompt-test" doc:id="772d135a-26b0-43d1-8acf-7000815da82f" >
<munit:behavior >
<munit:set-event doc:name="Set Input" doc:id="7cc98574-6c6f-4306-89d3-7a64e1c8242e" >
<munit:payload value="#[output application/json --- readUrl('classpath://ChatAnswerPrompttest/set-event_payload.dwl')]" encoding="UTF-8" mediaType="application/json" />
</munit:set-event>
</munit:behavior>
<munit:execution>
<!-- <set-variable-->
<!-- value='#[%dw 2.0&#10;output application/json&#10;-&#45;&#45;&#10;readUrl("classpath://ChatAnswerPrompttest/set-event_payload.dwl",encoding="UTF-8","application/json")]'-->
<!-- doc:name="Set Variable" doc:id="3a3c37c8-2647-4979-bfa8-a0aa258c9c79" variableName="userMessage"/>userMessage-->
<logger level="INFO" doc:name="Logger" message="#[vars.userMessage]"/>
<munit:set-event doc:name="Set Event" doc:id="ee8ce128-b7a9-4b57-ab9d-8a0daee2ddb9" >
<munit:payload value='#[{"data": "What is the capital of Switzerland"}]' />
</munit:set-event>
<logger level="INFO" doc:name="Logger" message="#[payload.data]"/>
<mulechain:chat-answer-prompt doc:name="CHAT-answer-prompt" doc:id="553233cb-8b97-42ae-ab73-b3d98ea58e83"
config-ref="OPENAI" prompt="#[payload.data]">
config-ref="OPENAI" prompt="#[payload.data]">
</mulechain:chat-answer-prompt>
</munit:execution>
<munit:validation >
<munit-tools:assert doc:name="Assert payload" doc:id="fb6f5175-8f5a-442e-9a18-83a5785cdc9c" message="The payload does not match">
<munit-tools:assert-that doc:name="Assert that" doc:id="f9ca3113-706b-49bd-9dc7-08f40b66f157" expression="#[MunitTools::containsString('Bern')]" is="#[MunitTools::notNullValue()]" message="Output response is not matching"/>
</munit:validation>
</munit:test>

<munit:test name="agent-define-prompt-template-test" doc:id="3d111d5d-2ce9-464d-b4b2-114bac36b2e4" >
<munit:behavior >
<munit:set-event doc:name="Set Input" doc:id="01b3a666-0856-440c-a499-c1374896a95b" >
<munit:payload value="#[output application/json --- readUrl('classpath://agentdefineprompttemplatetest/set-event_payload.dwl')]" encoding="UTF-8" mediaType="application/json" />
<munit:attributes value="#[readUrl('classpath://agentdefineprompttemplatetest/set-event_attributes.dwl')]" />
</munit:set-event>
</munit:behavior>
<munit:execution >
<mulechain:agent-define-prompt-template doc:name="CHAT-answer-prompt" doc:id="553233cb-8b97-42ae-ab73-b3d98ea58e83"
config-ref="OPENAI" template="#[payload.template]" instructions="#[payload.instructions]"
dataset="#[payload.data]"/>
</munit:execution>
<munit:validation >
<munit-tools:assert doc:name="Assert payload" doc:id="8aacf144-da60-494c-9b61-8a8e4ff36bc7" message="The payload does not match">
<munit-tools:that ><![CDATA[#[%dw 2.0
import ChatAnswerPrompttest::assert_expression_payload
import agentdefineprompttemplatetest::assert_expression_payload
---
assert_expression_payload::main({payload: payload, attributes: attributes, vars: vars})]]]></munit-tools:that>
</munit-tools:assert>
</munit:validation>
</munit:test>

</mule>
</mule>
3 changes: 0 additions & 3 deletions src/test/resources/ChatAnswerPrompttest/set-event_payload.dwl

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%dw 2.0
import * from dw::test::Asserts
---
payload must contain("Bern")
payload must contain("negative")
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"headers": {
"content-type": "application/json",
"user-agent": "PostmanRuntime/7.36.3",
"accept": "*/*",
"postman-token": "10a6a55c-3d90-4164-88cb-d2f787eb55f0",
"host": "localhost:8081",
"accept-encoding": "gzip, deflate, br",
"connection": "keep-alive",
"content-length": "607"
},
"clientCertificate": null,
"method": "POST",
"scheme": "http",
"queryParams": {},
"requestUri": "/agent",
"queryString": "",
"version": "HTTP/1.1",
"maskedRequestPath": null,
"listenerPath": "/agent",
"relativePath": "/agent",
"localAddress": "/127.0.0.1:8081",
"uriParams": {},
"rawRequestUri": "/agent",
"rawRequestPath": "/agent",
"remoteAddress": "/127.0.0.1:61582",
"requestPath": "/agent"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"template": "You are a customer satisfaction agent, who analyzes the customer feedback in the dataset. Answer via json output & add a type for the result only with positive or negative as well as the complete answer",
"instructions": "If the customer feedback in the dataset is negative, open a service satisfaction case and aplogize to the customer. If the customer feedback in the dataset is positive, thank the customer and wish them a nice day. Don't repeat the feedback and be more direct starting the conversation with formal greetings",
"data": "It was a horrible training last week"
}
2 changes: 1 addition & 1 deletion src/test/resources/envVars.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"MISTRAL_AI_API_KEY": ""
},
"OLLAMA": {
"OLLAMA_BASE_URL": "http://baseurl.ollama.com"
"OLLAMA_BASE_URL": "http://localhost:11434"
},
"ANTHROPIC": {
"ANTHROPIC_API_KEY": "YOUR_ANTHROPIC_API_KEY"
Expand Down