-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathinterview_jp.ts
168 lines (165 loc) · 5.09 KB
/
interview_jp.ts
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import "dotenv/config";
import { graphDataTestRunner } from "@receptron/test_utils";
import * as llm_agents from "@graphai/llm_agents";
import * as agents from "@graphai/agents";
export const graph_data = {
version: 0.5,
nodes: {
system_interviewer: {
value:
"You are a professional interviewer. It is your job to dig into the personality of the person, making some tough questions. In order to engage the audience, ask questions one by one, and respond to the answer before moving to the next topic.",
},
name: {
// Asks the user to enter the name of the person to interview.
agent: "textInputAgent",
params: {
message: "インタビューしたい人の名前を入力してください:",
},
},
context: {
// prepares the context for this interview.
agent: "copyAgent",
inputs: {
person0: {
name: "Interviewer",
system: ":system_interviewer",
},
person1: {
name: ":name.text",
system: "You are ${:name.text}.",
greeting: "Hi, I'm ${:name.text}",
},
},
},
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",
},
isResult: true,
graph: {
loop: {
count: 6,
},
nodes: {
messages: {
// Holds the conversation, array of messages.
value: [], // to be filled with inputs[2]
update: ":swappedMessages",
isResult: true,
},
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: "openAIAgent",
params: {
model: "gpt-4o",
},
inputs: { messages: ":messages" },
},
translate: {
// Asks the LLM to translate it into Japanese.
agent: "openAIAgent",
params: {
system: "この文章を日本語に訳して。意訳でも良いので、出来るだけ自然に相手に敬意を払う言葉遣いで。余計なことは書かずに、翻訳の結果だけ返して。",
model: "gpt-4o",
},
inputs: { prompt: ":messages.$last.content" },
},
output: {
// Displays the response to the user.
agent: "stringTemplateAgent",
console: {
after: true,
},
inputs: { text: "\x1b[32m${:context.person1.name}:\x1b[0m ${:translate.text}\n" },
},
reducer: {
// Append the responce to the messages.
agent: "pushAgent",
inputs: { array: ":messages", item: ":llm.message" },
},
swappedContext: {
// Swaps the context
agent: "propertyFilterAgent",
params: {
swap: {
person0: "person1",
},
},
inputs: { item: ":context" },
isResult: true,
},
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"] },
isResult: true,
},
},
},
},
translate: {
// This node sends those messages to Llama3 on llm to get the answer.
agent: "openAIAgent",
params: {
system: "この文章を日本語に訳して。出来るだけ自然な口語に。余計なことは書かずに、翻訳の結果だけ返して。",
},
inputs: { prompt: ":chat.swappedMessages.$last.content" },
},
output: {
// This node displays the responce to the user.
agent: "stringTemplateAgent",
console: {
after: true,
},
inputs: { text: "\x1b[32m${:chat.swappedContext.person1.name}:\x1b[0m ${:translate.text}\n" },
},
},
};
export const main = async () => {
const result = await graphDataTestRunner<{ messages: { role: string; content: string }[] }>(
__dirname + "/../",
__filename,
graph_data,
{ ...agents, ...llm_agents },
() => {},
false,
);
if (result?.chat) {
console.log("Complete", result.chat["messages"].length);
}
};
if (process.argv[1] === __filename) {
main();
}