Spaces:
Sleeping
Sleeping
try 2.1
Browse files- api/chain.go +20 -20
api/chain.go
CHANGED
|
@@ -31,10 +31,10 @@ func InvokeChain(apiKey string, userQuery string) (ChatOutput, error) {
|
|
| 31 |
prompt := string(systemPrompt) + "\n\nUser Query: " + userQuery
|
| 32 |
|
| 33 |
// Write prompt to log file ==> To be removed in production
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
|
| 39 |
ctx := context.Background()
|
| 40 |
|
|
@@ -71,19 +71,19 @@ func extractResponse(responseContent string) string {
|
|
| 71 |
return responseContent
|
| 72 |
}
|
| 73 |
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
|
|
|
| 31 |
prompt := string(systemPrompt) + "\n\nUser Query: " + userQuery
|
| 32 |
|
| 33 |
// Write prompt to log file ==> To be removed in production
|
| 34 |
+
err = writePromptToLogFile(prompt)
|
| 35 |
+
if err != nil {
|
| 36 |
+
return ChatOutput{}, fmt.Errorf("error writing prompt to log file: %v", err)
|
| 37 |
+
}
|
| 38 |
|
| 39 |
ctx := context.Background()
|
| 40 |
|
|
|
|
| 71 |
return responseContent
|
| 72 |
}
|
| 73 |
|
| 74 |
+
func writePromptToLogFile(prompt string) error {
|
| 75 |
+
if _, err := os.Stat("./log"); os.IsNotExist(err) {
|
| 76 |
+
os.Mkdir("./log", 0755)
|
| 77 |
+
}
|
| 78 |
+
file, err := os.OpenFile("./log/prompt.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
| 79 |
+
if err != nil {
|
| 80 |
+
return fmt.Errorf("error opening log file: %v", err)
|
| 81 |
+
}
|
| 82 |
+
defer file.Close()
|
| 83 |
+
|
| 84 |
+
if _, err := file.WriteString(prompt); err != nil {
|
| 85 |
+
return fmt.Errorf("error writing to log file: %v", err)
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
return nil
|
| 89 |
+
}
|