Skip to content

Commit

Permalink
use yaml to render chat messages in trace
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed May 31, 2024
1 parent db09cc2 commit ad2471d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,8 @@ export async function executeChatSession(

let genVars: Record<string, string>
while (true) {
trace.detailsFenced(`💬 messages`, messages, "yaml")
trace.startDetails(`📤 llm request (${messages.length} messages)`)
trace.detailsFenced(`💬 messages`, messages, "json")
let resp: ChatCompletionResponse
try {
checkCancelled(cancellationToken)
Expand Down
8 changes: 6 additions & 2 deletions packages/sample/genaisrc/injection.genai.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
script({
system: [],
files: "src/xpai/write-a-poem.txt",
})

const file = await workspace.readText("src/xpai/write-a-poem.txt")
const file = env.files[0]

$`Translate the following text from English to French:
> ${file.content}`
\`\`\`
${file.content}
\`\`\`
`
16 changes: 8 additions & 8 deletions packages/sample/genaisrc/translate.genai.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ const lang = env.vars.lang || "French"

for (const file of env.files) {
const canary = Math.random().toString(36).substring(7)
const res = await runPrompt((_) => {
_.$`Respond with ${canary}.`
_.def("FILE", file)
})
console.log(res.text)
if (res.text !== canary) {
cancel("file contains adverse content")
}
const res = await runPrompt(
(_) => {
_.$`Respond with ${canary}.`
_.def("FILE", file)
},
{ label: file.filename }
)
if (res.text !== canary) cancel("file contains adverse content")
}

def("FILE", env.files)
Expand Down

0 comments on commit ad2471d

Please sign in to comment.