Skip to content

Commit

Permalink
https://github.com/elmsln/issues/issues/1948
Browse files Browse the repository at this point in the history
  • Loading branch information
btopro committed May 2, 2024
1 parent 9d368e5 commit 51d1fae
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
10 changes: 8 additions & 2 deletions api/apps/haxcms/aiChat.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ curl -X POST http://ec2-44-205-57-53.compute-1.amazonaws.com/handle-query \
import { stdPostBody, stdResponse, invalidRequest } from "../../../utilities/requestHelpers.js";
import { resolveSiteData } from "./lib/JOSHelpers.js";

const aiChatSource = "https://askalfred.vercel.app/api/query";
// LLM response agents
const engines = {
alfred: "https://askalfred.vercel.app/api/query",
robin: "http://ec2-44-205-57-53.compute-1.amazonaws.com/embed-and-store",
};

// site object to validate response from passed in url
export default async function handler(req, res) {
Expand Down Expand Up @@ -46,7 +50,8 @@ export default async function handler(req, res) {
}
// @todo don't hardcode, leverage site that was requested for context assignment
context = "haxcellence";
let data = await fetch(aiChatSource, {
let engine = body.engine || "alfred";
let data = await fetch(engines[engine], {
method: "POST",
headers: {
'Accept': 'application/json',
Expand All @@ -57,6 +62,7 @@ export default async function handler(req, res) {
body: JSON.stringify({
"question": body.question,
"course": context,
"engine": engine,
}),
})
.then((d) => {
Expand Down
24 changes: 20 additions & 4 deletions elements/haxcms-elements/lib/ui-components/magic/site-ai-chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ MicroFrontendRegistry.add({
site: "location of the HAXcms site OR site.json data",
type: "site for site.json or link for remote loading",
question: "Question to ask of the AI",
engine: "which engine to use as we test multiple",
},
});

Expand All @@ -31,11 +32,13 @@ export class SiteAiChat extends DDDPulseEffectSuper(DDD) {
this.question = null;
this.answers = [];
this.loading = false;
this.engine = "alfred";
this.dataPulse = "1";
}

askQuestion(e) {
e.preventDefault();
this.engine = e.target.getAttribute('name');
this.question = this.shadowRoot.querySelector("#question").value;
}

Expand All @@ -51,19 +54,20 @@ export class SiteAiChat extends DDDPulseEffectSuper(DDD) {
this.shadowRoot.querySelector("dialog").close();
}
}
if (changedProperties.has("question") && this.question) {
if (changedProperties.has("question") && this.question && this.engine) {
const site = toJS(store.manifest);
var base = "";
if (globalThis.document.querySelector("base")) {
base = globalThis.document.querySelector("base").href;
}
const params = {
type: "site",
site: {
file: base + "site.json",
metadata: site.metadata,
},
type: "site",
question: this.question,
engine: this.engine,
};
this.loading = true;
MicroFrontendRegistry.call(
Expand All @@ -88,12 +92,23 @@ export class SiteAiChat extends DDDPulseEffectSuper(DDD) {
>Close</simple-icon-button-lite>
<form action="#">
<simple-icon-lite class="hat" icon="${this.loading ? "hax:loading" : "hax:wizard-hat"}"></simple-icon-lite>
<input id="question" type="text" placeholder="Ask your question.." /><button
<input id="question" type="text" placeholder="Ask your question.." />
<button
id="submit"
type="submit"
name="alfred"
@click="${this.askQuestion}"
>
Ask Alfred
</button>
<button
id="submit2"
type="submit"
name="robin"
@click="${this.askQuestion}"
>
Ask question
Ask Robin
</button>
</form>
${this.question ? html`
Expand Down Expand Up @@ -199,6 +214,7 @@ export class SiteAiChat extends DDDPulseEffectSuper(DDD) {
static get properties() {
return {
...super.properties,
engine: { type: String },
question: { type: String },
answers: { type: Array },
opened: { type: Boolean, reflect: true },
Expand Down

0 comments on commit 51d1fae

Please sign in to comment.