-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hack: add a bit of code to create/update assistant itself
- Loading branch information
Showing
2 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"os" | ||
"time" | ||
|
||
openai "github.com/sashabaranov/go-openai" | ||
) | ||
|
||
const ( | ||
assistantID = "asst_eMM9QaWLi6cajHE4PdG1yU53" // Botkube | ||
) | ||
|
||
func main() { | ||
client := openai.NewClient(os.Getenv("OPENAI_API_KEY")) | ||
|
||
// Update assistant with latest tools. | ||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) | ||
defer cancel() | ||
|
||
_, err := updateAssistant(ctx, client, assistantID) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func updateAssistant(ctx context.Context, c *openai.Client, id string) (openai.Assistant, error) { | ||
instructions := `You are an experienced DevOps engineer. | ||
You have deep understand how to operate a kubernetes cluster and troubleshoot running workloads in kubernetes. | ||
You have access to tools which can help you to find needed information.` | ||
|
||
return c.ModifyAssistant(ctx, id, openai.AssistantRequest{ | ||
Model: openai.GPT4TurboPreview, | ||
Instructions: &instructions, | ||
Tools: openAITools, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/sashabaranov/go-openai" | ||
"github.com/sashabaranov/go-openai/jsonschema" | ||
) | ||
|
||
var openAITools = []openai.AssistantTool{ | ||
{ | ||
Type: openai.AssistantToolType(openai.ToolTypeFunction), | ||
Function: &openai.FunctionDefinition{ | ||
Name: "kubectlGetPods", | ||
Description: "Useful for getting one pod or all pods in a kubernetes namespace.", | ||
Parameters: jsonschema.Definition{ | ||
Type: jsonschema.Object, | ||
Properties: map[string]jsonschema.Definition{ | ||
"namespace": { | ||
Type: jsonschema.String, | ||
Description: "Kubernetes namespace, e.g. kube-system", | ||
}, | ||
"pod_name": { | ||
Type: jsonschema.String, | ||
Description: "Kubernetes pod name, e.g. botkube-6c6fd8b4d6-f559q", | ||
}, | ||
}, | ||
Required: []string{"namespace"}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Type: openai.AssistantToolType(openai.ToolTypeFunction), | ||
Function: &openai.FunctionDefinition{ | ||
Name: "kubectlGetSecrets", | ||
Description: "Useful for getting one secret or all secrets in a kubernetes namespace.", | ||
Parameters: jsonschema.Definition{ | ||
Type: jsonschema.Object, | ||
Properties: map[string]jsonschema.Definition{ | ||
"namespace": { | ||
Type: jsonschema.String, | ||
Description: "Kubernetes namespace, e.g. kube-system", | ||
}, | ||
"secret_name": { | ||
Type: jsonschema.String, | ||
Description: "Kubernetes secret name, e.g. api-key", | ||
}, | ||
}, | ||
Required: []string{"namespace"}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Type: openai.AssistantToolType(openai.ToolTypeFunction), | ||
Function: &openai.FunctionDefinition{ | ||
Name: "kubectlDescribePod", | ||
Description: "Useful for describing a pod in a kubernetes namespace.", | ||
Parameters: jsonschema.Definition{ | ||
Type: jsonschema.Object, | ||
Properties: map[string]jsonschema.Definition{ | ||
"namespace": { | ||
Type: jsonschema.String, | ||
Description: "Kubernetes namespace, e.g. kube-system", | ||
}, | ||
"pod_name": { | ||
Type: jsonschema.String, | ||
Description: "Kubernetes pod name, e.g. botkube-6c6fd8b4d6-f559q", | ||
}, | ||
}, | ||
Required: []string{"namespace", "pod_name"}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Type: openai.AssistantToolType(openai.ToolTypeFunction), | ||
Function: &openai.FunctionDefinition{ | ||
Name: "kubectlLogs", | ||
Description: "Useful for getting container logs.", | ||
Parameters: jsonschema.Definition{ | ||
Type: jsonschema.Object, | ||
Properties: map[string]jsonschema.Definition{ | ||
"namespace": { | ||
Type: jsonschema.String, | ||
Description: "Kubernetes namespace, e.g. kube-system", | ||
}, | ||
"pod_name": { | ||
Type: jsonschema.String, | ||
Description: "Kubernetes pod name, e.g. botkube-6c6fd8b4d6-f559q", | ||
}, | ||
"container_name": { | ||
Type: jsonschema.String, | ||
Description: "Pod container name, e.g. botkube-api-server.", | ||
}, | ||
}, | ||
Required: []string{"namespace", "pod_name"}, | ||
}, | ||
}, | ||
}, | ||
} |