generated from isamu/firebase-vue3-startup-kit
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:receptron/graphai-demo-web
- Loading branch information
Showing
5 changed files
with
254 additions
and
2 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,116 @@ | ||
export const graph_data = { | ||
version: 0.5, | ||
nodes: { | ||
system_interviewer: { | ||
value: | ||
"あなたはプロのインタビュアーです。相手の個性や本質を深掘りし、時には鋭い質問を投げかけながら、核心に迫るインタビューを行ってください。観客を引き込むために、質問は一つずつ投げかけ、相手の回答にしっかり反応してから次の話題に進んでください。対話の流れを大切にし、相手の言葉からさらに深い洞察を引き出してください。", | ||
}, | ||
name: { | ||
value: "", | ||
}, | ||
context: { | ||
// prepares the context for this interview. | ||
agent: "copyAgent", | ||
inputs: { | ||
person0: { | ||
name: "interviewer", | ||
system: ":system_interviewer", | ||
}, | ||
person1: { | ||
name: ":name", | ||
system: "あなたは${:name}です.", | ||
greeting: "こんにちは、私は${:name}です", | ||
}, | ||
}, | ||
}, | ||
chat: { | ||
// performs the conversation using nested graph | ||
agent: "nestedAgent", | ||
inputs: { | ||
messages: [ | ||
{ | ||
role: "system", | ||
content: ":context.person0.system", | ||
}, | ||
{ | ||
role: "user", | ||
content: ":context.person1.greeting", | ||
}, | ||
], | ||
context: ":context", | ||
}, | ||
graph: { | ||
loop: { | ||
count: 6, | ||
}, | ||
nodes: { | ||
messages: { | ||
// Holds the conversation, array of messages. | ||
value: [], // to be filled with inputs[2] | ||
update: ":swappedMessages", | ||
}, | ||
context: { | ||
// Holds the context, which is swapped for each iteration. | ||
value: {}, // te be mfilled with inputs[1] | ||
update: ":swappedContext", | ||
}, | ||
llm: { | ||
// Sends those messages to the LLM to get a response. | ||
agent: "tinyswallowAgent", | ||
isResult: true, | ||
params: { | ||
model: "gpt-4o", | ||
stream: true, | ||
}, | ||
inputs: { messages: ":messages" }, | ||
}, | ||
output: { | ||
// Displays the response to the user. | ||
agent: "copyAgent", | ||
inputs: { | ||
message: { | ||
content: ":llm.text", | ||
role: ":context.person1.name", | ||
}, | ||
}, | ||
}, | ||
reducer: { | ||
// Append the responce to the messages. | ||
agent: "pushAgent", | ||
inputs: { array: ":messages", item: { content: ":llm.message.content", role: ":llm.message.role" } }, | ||
}, | ||
swappedContext: { | ||
// Swaps the context | ||
agent: "propertyFilterAgent", | ||
params: { | ||
swap: { | ||
person0: "person1", | ||
}, | ||
}, | ||
inputs: { item: ":context" }, | ||
}, | ||
swappedMessages: { | ||
// Swaps the user and assistant of messages | ||
agent: "propertyFilterAgent", | ||
params: { | ||
inject: [ | ||
{ | ||
propId: "content", | ||
index: 0, | ||
from: 1, | ||
}, | ||
], | ||
alter: { | ||
role: { | ||
assistant: "user", | ||
user: "assistant", | ||
}, | ||
}, | ||
}, | ||
inputs: { array: [":reducer.array", ":swappedContext.person0.system"] }, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; |
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,131 @@ | ||
<template> | ||
<div class="home"> | ||
<div class="items-center justify-center"> | ||
<div> | ||
<div class="w-10/12 h-60 bg-white rounded-md mt-4 p-2 mx-auto border-2"> | ||
<div ref="cytoscapeRef" class="w-full h-full" /> | ||
</div> | ||
</div> | ||
<div class="mt-2"> | ||
<div class="w-10/12 m-auto text-left"> | ||
<div v-for="(m, k) in messages" :key="k"> | ||
<div v-if="m.role !== 'interviewer'" class="mr-8">👱{{ m.content }}</div> | ||
<div class="ml-20" v-else>🤖{{ m.content }}</div> | ||
</div> | ||
<div class="ml-20" v-if="isStreaming['llm'] && currentRole === 'interviewer'">🤖{{ streamData["llm"] }}</div> | ||
<div class="mr-8" v-if="isStreaming['llm'] && currentRole !== 'interviewer'">👱{{ streamData["llm"] }}</div> | ||
</div> | ||
</div> | ||
<div class="mt-2 hidden"> | ||
<button class="text-white font-bold items-center rounded-full px-4 py-2 m-1 bg-sky-500 hover:bg-sky-700" @click="run">Run</button> | ||
</div> | ||
|
||
<div> | ||
<div class="w-10/12 m-auto my-4"> | ||
<div class="flex"> | ||
<input v-model="userInput" @keyup.enter="callSubmit" class="border-2 p-2 rounded-md flex-1" :disabled="isSubmit" /> | ||
<button | ||
class="text-white font-bold items-center rounded-md px-4 py-2 ml-1 hover:bg-sky-700 flex-none" | ||
:class="isSubmit ? 'bg-sky-200' : 'bg-sky-500'" | ||
@click="callSubmit" | ||
> | ||
Submit | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent, ref, computed } from "vue"; | ||
import { GraphAI } from "graphai"; | ||
import * as agents from "@graphai/vanilla"; | ||
import { graph_data } from "@/graph/interview2"; | ||
import tinyswallowAgent from "../agents/tinyswallow"; | ||
import { useStreamData } from "@/utils/stream"; | ||
import { useChatPlugin } from "../utils/graphai"; | ||
import { useCytoscape } from "@receptron/graphai_vue_cytoscape"; | ||
export default defineComponent({ | ||
name: "HomePage", | ||
components: {}, | ||
setup() { | ||
const selectedGraph = computed(() => { | ||
return graph_data; | ||
}); | ||
// input | ||
const userInput = ref("トム・クルーズ"); | ||
const isSubmit = ref(false); | ||
const currentRole = ref(""); | ||
const callSubmit = () => { | ||
isSubmit.value = true; | ||
run(); | ||
}; | ||
// end of input | ||
const { updateCytoscape, cytoscapeRef } = useCytoscape(selectedGraph); | ||
// streaming | ||
const { streamData, streamAgentFilter, streamPlugin, isStreaming } = useStreamData(); | ||
const agentFilters = [ | ||
{ | ||
name: "streamAgentFilter", | ||
agent: streamAgentFilter, | ||
}, | ||
]; | ||
// end of streaming | ||
const { messages, chatMessagePlugin } = useChatPlugin(); | ||
const run = async () => { | ||
const graphai = new GraphAI( | ||
selectedGraph.value, | ||
{ | ||
...agents, | ||
tinyswallowAgent, | ||
}, | ||
{ | ||
agentFilters, | ||
config: { | ||
}, | ||
}, | ||
); | ||
graphai.injectValue("name", userInput.value); | ||
graphai.registerCallback(updateCytoscape); | ||
graphai.registerCallback(chatMessagePlugin(["output"])); | ||
graphai.registerCallback(({ nodeId, result }) => { | ||
console.log(nodeId, result ); | ||
if (nodeId === "context" && result) { | ||
currentRole.value = (result as { person1: { name: string } }).person1.name; | ||
console.log(currentRole.value); | ||
} | ||
}); | ||
graphai.registerCallback(streamPlugin(["llm"])); | ||
await graphai.run(); | ||
}; | ||
return { | ||
run, | ||
cytoscapeRef, | ||
selectedGraph, | ||
streamData, | ||
isStreaming, | ||
callSubmit, | ||
userInput, | ||
messages, | ||
currentRole, | ||
isSubmit, | ||
}; | ||
}, | ||
}); | ||
</script> |