-
Notifications
You must be signed in to change notification settings - Fork 134
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
Prompt reorg for caching + usage collection #743
Conversation
The changes in this diff primarily focus on the introduction of a new function Concerns and Suggestions:
export async function renderPromptNode(
...
- await resolvePromptNode(model, node)
- await tracePromptNode(trace, node)
+ if (await layoutPromptNode(model, node))
+ await tracePromptNode(trace, node, { label: "layout" })
+
+ await resolvePromptNode(model, node)
+ await tracePromptNode(trace, node)
...
|
@@ -874,6 +900,9 @@ export async function renderPromptNode( | |||
await resolvePromptNode(model, node) | |||
await tracePromptNode(trace, node) | |||
|
|||
if (await layoutPromptNode(model, node)) | |||
await tracePromptNode(trace, node, { label: "layout" }) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function layoutPromptNode
is called with await but it does not return a promise. This might lead to unexpected behavior. Please ensure that the function returns a promise or remove the await keyword if it's not needed. 😊
generated by pr-review-commit
async_function
Investigator reportSummary of Root CauseThe failure is caused by a Key Points:
Code Causing the IssueThe error is occurring in: at Function.entries (<anonymous>)
at runScript (/home/runner/work/genaiscript/genaiscript/packages/cli/built/genaiscript.cjs:87676:37) This suggests a problem with object manipulation, likely related to incorrect assumptions about data structure or missing data. Suggested Fix--- a/packages/cli/src/genaiscript.ts
+++ b/packages/cli/src/genaiscript.ts
@@ -87673,7 +87673,11 @@ export function runScript() {
// Existing code...
- Object.entries(someVar).forEach(([key, value]) => {
+ if (someVar && typeof someVar === 'object') {
+ Object.entries(someVar).forEach(([key, value]) => {
+ // Existing logic...
+ });
+ }
// Existing code... Explanation:
|
This pull request optimizes chat caching by moving definitions to the back of the prompt structure. The
layoutPromptNode
function is introduced to sort the children of a prompt node, ensuring that definitions are placed after other types of nodes. This change improves the efficiency of chat caching with OpenAI.layoutPromptNode
has been added which aims to optimize chat caching with OpenAI by reordering nodes inside the prompt. It places the "def" type nodes towards the end. This function is triggered before the node tracing functionality.layoutPromptNode
function is called. If it identifies a change in the order of the nodes, the trace of the prompt node is called again with the label "layout".All these modifications will help to better leverage OpenAI's chat caching functionality, thus potentially improving performance.