Skip to content

Commit

Permalink
Do now add context to the knowledge questions
Browse files Browse the repository at this point in the history
Signed-off-by: Anil Vishnoi <[email protected]>
  • Loading branch information
vishnoianil committed Sep 12, 2024
1 parent d7b21da commit 9e0124f
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions worker/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,6 @@ func (w *Worker) runKnowledgePrecheck(lab string, labDiffOutput []string, modelN
continue
}
filePath := path.Join(w.ilabConfig.Generate.TaxonomyPath, file)
w.logger.Infof("ANIL: opening knowledge yaml : %s", filePath)
f, err := os.Open(filePath)
if err != nil {
w.logger.Errorf("Could not open taxonomy knowledge yaml file: %v", err)
Expand Down Expand Up @@ -515,11 +514,19 @@ func (w *Worker) runKnowledgePrecheck(lab string, labDiffOutput []string, modelN
continue
}

originalAnswer, ok := qna["answer"].(string)
if !ok {
w.logger.Errorf("Answer not found or not a string in knowledge seed example %d", seIndex)
continue
}

// Escape sequences of two or more hyphens in the question to avoid ilab seeing a flag request
originalQuestion := question
question = escapeHyphens(question)
// Append the context to the question with a specific format
question = fmt.Sprintf("%s %s %s.", question, ctxPrompt, context)
// In case of knowledge, it doesn't make sense to provide the context with the question
// Commenting out the context appending in case we need to revert back
// question = fmt.Sprintf("%s %s %s.", question, ctxPrompt, context)

commandStr := fmt.Sprintf("model chat --quick-question %s", question)
if TlsInsecure {
Expand Down Expand Up @@ -549,11 +556,10 @@ func (w *Worker) runKnowledgePrecheck(lab string, labDiffOutput []string, modelN
}

logData := map[string]interface{}{
"context": originalContext,
"input": map[string]string{
"question": originalQuestion,
},
"output": out.String(),
"context": originalContext,
"question": originalQuestion,
"original-answer": originalAnswer,
"model-answer": out.String(),
}
logYAML, err := yaml.Marshal(logData)
if err != nil {
Expand All @@ -570,7 +576,7 @@ func (w *Worker) runKnowledgePrecheck(lab string, labDiffOutput []string, modelN
}

// Create a combined .log file
logText := fmt.Sprintf("Context:\n%s\nInput:\n%s\nOutput:\n%s\n", originalContext, originalQuestion, out.String())
logText := fmt.Sprintf("Context:\n%s\nQuestion:\n%s\nOriginalAnswer:\n%s\nModelAnswer:\n%s\n", originalContext, originalQuestion, originalAnswer, out.String())
logFileName = fmt.Sprintf("chat_%s.log", timestamp)
err = os.WriteFile(path.Join(chatlogDir, logFileName), []byte(logText), 0644)
if err != nil {
Expand Down Expand Up @@ -635,6 +641,11 @@ func (w *Worker) runSkillPrecheck(lab string, labDiffOutput []string, modelName
w.logger.Error("Question not found or not a string in the skill")
continue
}
originalAnswer, ok := example["answer"].(string)
if !ok {
w.logger.Error("Answer not found or not a string in the skill")
continue
}

context, hasContext := example["context"].(string)
originalQuestion := question
Expand Down Expand Up @@ -677,14 +688,13 @@ func (w *Worker) runSkillPrecheck(lab string, labDiffOutput []string, modelName
}

logData := map[string]interface{}{
"input": map[string]string{
"question": originalQuestion,
},
"output": out.String(),
"question": originalQuestion,
"original-answer": originalAnswer,
"model-answer": out.String(),
}

if hasContext {
logData["input"].(map[string]string)["context"] = context
logData["context"] = context
}

logYAML, err := yaml.Marshal(logData)
Expand Down

0 comments on commit 9e0124f

Please sign in to comment.