made jina api key optional

This commit is contained in:
Noam Siegel 2024-09-16 11:44:21 -07:00
parent 6f116ca527
commit 4534ef6544

View File

@ -25,7 +25,7 @@ func NewJinaClient() *JinaClient {
EnvNamePrefix: common.BuildEnvVariablePrefix(label),
},
}
client.ApiKey = client.AddSetupQuestion("API Key", true)
client.ApiKey = client.AddSetupQuestion("API Key", false)
return client
}
@ -37,10 +37,10 @@ func (jc *JinaClient) ScrapeURL(url string) (string, error) {
return "", fmt.Errorf("error creating request: %w", err)
}
apiKey := jc.ApiKey.Value
// Set the Authorization header with the Bearer token
// if api keys exist, set the header
if apiKey := jc.ApiKey.Value; apiKey != "" {
req.Header.Set("Authorization", "Bearer "+apiKey)
}
client := &http.Client{}
resp, err := client.Do(req)
@ -57,13 +57,22 @@ func (jc *JinaClient) ScrapeURL(url string) (string, error) {
return string(body), nil
}
// search engine call that returns top-5 results with their URLs and contents, each in clean, LLM-friendly text.
func (jc *JinaClient) ScrapeQuestion(question string) (string, error) {
url := "https://s.jina.ai/" + question
resp, err := http.Get(url)
requestURL := "https://s.jina.ai/" + question
req, err := http.NewRequest("GET", requestURL, nil)
if err != nil {
return "", fmt.Errorf("error making GET request: %w", err)
return "", fmt.Errorf("error creating request: %w", err)
}
// if api keys exist, set the header
if apiKey := jc.ApiKey.Value; apiKey != "" {
req.Header.Set("Authorization", "Bearer "+apiKey)
}
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return "", fmt.Errorf("error sending request: %w", err)
}
defer resp.Body.Close()