@@ -248,15 +248,15 @@ func (r *weaviateWrapper) SimilaritySearch(ctx context.Context, query string, nu
248248 return nil , fmt .Errorf ("query weaviate failed: %w" , err )
249249 }
250250
251- items , err := r .unmarshalSimilarSearchResponse (res , options .CodebasePath , options .ClientId )
251+ items , err := r .unmarshalSimilarSearchResponse (res , options .CodebasePath , options .ClientId , options . Authorization )
252252 if err != nil {
253253 return nil , fmt .Errorf ("failed to unmarshal response: %w" , err )
254254 }
255255
256256 return items , nil
257257}
258258
259- func (r * weaviateWrapper ) unmarshalSimilarSearchResponse (res * models.GraphQLResponse , codebasePath , clientId string ) ([]* types.SemanticFileItem , error ) {
259+ func (r * weaviateWrapper ) unmarshalSimilarSearchResponse (res * models.GraphQLResponse , codebasePath , clientId string , authorization string ) ([]* types.SemanticFileItem , error ) {
260260 // Get the data for our class
261261 data , ok := res .Data ["Get" ].(map [string ]interface {})
262262 if ! ok {
@@ -299,7 +299,7 @@ func (r *weaviateWrapper) unmarshalSimilarSearchResponse(res *models.GraphQLResp
299299
300300 // 通过fetchCodeContent接口获取代码片段
301301 if codebasePath != "" {
302- fetchedContent , err := fetchCodeContent (context .Background (), r .cfg , clientId , codebasePath , filePath , startLine , endLine )
302+ fetchedContent , err := fetchCodeContent (context .Background (), r .cfg , clientId , codebasePath , filePath , startLine , endLine , authorization )
303303 if err == nil && fetchedContent != "" {
304304 content = fetchedContent
305305 }
@@ -694,7 +694,7 @@ func (r *weaviateWrapper) Query(ctx context.Context, query string, topK int, opt
694694}
695695
696696// fetchCodeContent 通过API获取代码片段的Content
697- func fetchCodeContent (ctx context.Context , cfg config.VectorStoreConf , clientId , codebasePath , filePath string , startLine , endLine int ) (string , error ) {
697+ func fetchCodeContent (ctx context.Context , cfg config.VectorStoreConf , clientId , codebasePath , filePath string , startLine , endLine int , authorization string ) (string , error ) {
698698 // 构建API请求URL
699699 baseURL := cfg .BaseURL
700700
@@ -730,8 +730,19 @@ func fetchCodeContent(ctx context.Context, cfg config.VectorStoreConf, clientId,
730730
731731 tracer .WithTrace (ctx ).Infof ("fetchCodeContent %s: " , requestURL )
732732
733+ // 创建HTTP请求
734+ req , err := http .NewRequestWithContext (ctx , "GET" , requestURL , nil )
735+ if err != nil {
736+ return "" , fmt .Errorf ("failed to create request: %w" , err )
737+ }
738+
739+ // 添加Authorization头
740+ if authorization != "" {
741+ req .Header .Set ("Authorization" , authorization )
742+ }
743+
733744 // 发送HTTP GET请求
734- resp , err := http .Get ( requestURL )
745+ resp , err := http .DefaultClient . Do ( req )
735746 if err != nil {
736747 return "" , fmt .Errorf ("failed to fetch code content: %w" , err )
737748 }
0 commit comments