Skip to content

Commit

Permalink
some better logs and assistants=v2
Browse files Browse the repository at this point in the history
  • Loading branch information
radiantspace committed May 19, 2024
1 parent e484c63 commit 26f422a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
6 changes: 3 additions & 3 deletions backend/app/ai/openai/assistants.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func CreateAssistant(ctx context.Context, assistant *models.AssistantRequest) (*
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+config.CONFIG.OpenAIAPIKey)
req.Header.Set("OpenAI-Beta", "assistants=v1")
req.Header.Set("OpenAI-Beta", "assistants=v2")

resp, err := HTTP_CLIENT.Do(req)
if err != nil {
Expand Down Expand Up @@ -108,7 +108,7 @@ func GetAssistant(ctx context.Context, assistantID string) (*models.AssistantRes
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+config.CONFIG.OpenAIAPIKey)
req.Header.Set("OpenAI-Beta", "assistants=v1")
req.Header.Set("OpenAI-Beta", "assistants=v2")

resp, err := HTTP_CLIENT.Do(req)
if err != nil {
Expand Down Expand Up @@ -143,7 +143,7 @@ func ListAssistants(ctx context.Context, limit int, order string, after string,
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+config.CONFIG.OpenAIAPIKey)
req.Header.Set("OpenAI-Beta", "assistants=v1")
req.Header.Set("OpenAI-Beta", "assistants=v2")

q := req.URL.Query()
if limit > 0 {
Expand Down
31 changes: 18 additions & 13 deletions backend/app/ai/openai/threads.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func CreateThreadAndRun(ctx context.Context, assistantId string, thread *models.
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+config.CONFIG.OpenAIAPIKey)
req.Header.Set("OpenAI-Beta", "assistants=v1")
req.Header.Set("OpenAI-Beta", "assistants=v2")

timeNow := time.Now()
status := fmt.Sprintf("status:%d", 0)
Expand Down Expand Up @@ -107,7 +107,7 @@ func CreateRun(ctx context.Context, assistantId string, threadId string) (*model

req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+config.CONFIG.OpenAIAPIKey)
req.Header.Set("OpenAI-Beta", "assistants=v1")
req.Header.Set("OpenAI-Beta", "assistants=v2")

timeNow := time.Now()
status := fmt.Sprintf("status:%d", 0)
Expand Down Expand Up @@ -150,7 +150,7 @@ func GetThread(ctx context.Context, threadId string) (*models.ThreadResponse, er
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+config.CONFIG.OpenAIAPIKey)
req.Header.Set("OpenAI-Beta", "assistants=v1")
req.Header.Set("OpenAI-Beta", "assistants=v2")

timeNow := time.Now()
status := fmt.Sprintf("status:%d", 0)
Expand Down Expand Up @@ -194,7 +194,7 @@ func CancelRun(ctx context.Context, threadId, runId string) (*models.ThreadRunRe
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+config.CONFIG.OpenAIAPIKey)
req.Header.Set("OpenAI-Beta", "assistants=v1")
req.Header.Set("OpenAI-Beta", "assistants=v2")

resp, err := HTTP_CLIENT.Do(req)
if err != nil {
Expand Down Expand Up @@ -229,7 +229,7 @@ func GetThreadRun(ctx context.Context, threadId, runId string) (*models.ThreadRu
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+config.CONFIG.OpenAIAPIKey)
req.Header.Set("OpenAI-Beta", "assistants=v1")
req.Header.Set("OpenAI-Beta", "assistants=v2")

timeNow := time.Now()
status := fmt.Sprintf("status:%d", 0)
Expand Down Expand Up @@ -273,7 +273,7 @@ func GetLastThreadRun(ctx context.Context, threadId string) (*models.ThreadRunRe

req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+config.CONFIG.OpenAIAPIKey)
req.Header.Set("OpenAI-Beta", "assistants=v1")
req.Header.Set("OpenAI-Beta", "assistants=v2")

q := req.URL.Query()
q.Add("limit", fmt.Sprintf("%d", 1))
Expand Down Expand Up @@ -324,7 +324,7 @@ func ListThreadRunSteps(ctx context.Context, threadId, runId string) (*models.Th
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+config.CONFIG.OpenAIAPIKey)
req.Header.Set("OpenAI-Beta", "assistants=v1")
req.Header.Set("OpenAI-Beta", "assistants=v2")

timeNow := time.Now()
status := fmt.Sprintf("status:%d", 0)
Expand Down Expand Up @@ -372,7 +372,7 @@ func CreateThreadMessage(ctx context.Context, threadId string, message *models.M
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+config.CONFIG.OpenAIAPIKey)
req.Header.Set("OpenAI-Beta", "assistants=v1")
req.Header.Set("OpenAI-Beta", "assistants=v2")

timeNow := time.Now()
status := fmt.Sprintf("status:%d", 0)
Expand Down Expand Up @@ -422,7 +422,7 @@ func GetThreadMessage(ctx context.Context, threadId, messageId string) (*models.
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+config.CONFIG.OpenAIAPIKey)
req.Header.Set("OpenAI-Beta", "assistants=v1")
req.Header.Set("OpenAI-Beta", "assistants=v2")

timeNow := time.Now()
status := fmt.Sprintf("status:%d", 0)
Expand Down Expand Up @@ -468,7 +468,7 @@ func DeleteThread(ctx context.Context, threadId string) (*models.DeletedResponse
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+config.CONFIG.OpenAIAPIKey)
req.Header.Set("OpenAI-Beta", "assistants=v1")
req.Header.Set("OpenAI-Beta", "assistants=v2")

timeNow := time.Now()
status := fmt.Sprintf("status:%d", 0)
Expand Down Expand Up @@ -514,7 +514,7 @@ func ListThreadMessagesForARun(ctx context.Context, threadId string, runId strin
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+config.CONFIG.OpenAIAPIKey)
req.Header.Set("OpenAI-Beta", "assistants=v1")
req.Header.Set("OpenAI-Beta", "assistants=v2")

q := req.URL.Query()
q.Add("limit", fmt.Sprintf("%d", 10))
Expand Down Expand Up @@ -597,7 +597,7 @@ func CreateThreadAndRunStreaming(ctx context.Context, assistantId string, model
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+config.CONFIG.OpenAIAPIKey)
req.Header.Set("OpenAI-Beta", "assistants=v1")
req.Header.Set("OpenAI-Beta", "assistants=v2")

client := sse.NewClientFromReq(req)
messages := make(chan string)
Expand Down Expand Up @@ -643,7 +643,7 @@ func CreateRunStreaming(ctx context.Context, assistantId string, model models.En
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+config.CONFIG.OpenAIAPIKey)
req.Header.Set("OpenAI-Beta", "assistants=v1")
req.Header.Set("OpenAI-Beta", "assistants=v2")

client := sse.NewClientFromReq(req)
messages := make(chan string)
Expand Down Expand Up @@ -714,6 +714,11 @@ func subscribeAndProcess(
return
}

if string(msg.Event) == "thread.run.created" {
log.Infof("[%s] got thread.run.created event for user id %s", apiName, userId)
return
}

log.Debugf("[%s] got event %s for user id %s, skipping processing..", apiName, string(msg.Event), userId)
})
if err != nil {
Expand Down

0 comments on commit 26f422a

Please sign in to comment.