-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d6e39be
commit 7a87e03
Showing
13 changed files
with
146 additions
and
43 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
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
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
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 |
---|---|---|
@@ -1,13 +1,3 @@ | ||
package crawler | ||
|
||
import ( | ||
"net/http" | ||
) | ||
|
||
type Option func(*Tool) | ||
|
||
func WithClient(client *http.Client) Option { | ||
return func(t *Tool) { | ||
t.client = client | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
package duckduckgo | ||
|
||
type Result struct { | ||
Title string | ||
Content string | ||
Location string | ||
URL string `json:"url"` | ||
|
||
Title string `json:"title"` | ||
Content string `json:"content"` | ||
} |
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,3 @@ | ||
package retriever | ||
|
||
type Option func(*Tool) |
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,7 @@ | ||
package retriever | ||
|
||
type Result struct { | ||
Title string `json:"title,omitempty"` | ||
Content string `json:"content,omitempty"` | ||
Location string `json:"location,omitempty"` | ||
} |
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,84 @@ | ||
package retriever | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/adrianliechti/llama/pkg/index" | ||
"github.com/adrianliechti/llama/pkg/tool" | ||
) | ||
|
||
var _ tool.Tool = &Tool{} | ||
|
||
type Tool struct { | ||
index index.Provider | ||
} | ||
|
||
func New(index index.Provider, options ...Option) (*Tool, error) { | ||
t := &Tool{ | ||
index: index, | ||
} | ||
|
||
for _, option := range options { | ||
option(t) | ||
} | ||
|
||
if t.index == nil { | ||
return nil, errors.New("missing index provider") | ||
} | ||
|
||
return t, nil | ||
} | ||
|
||
func (t *Tool) Name() string { | ||
return "retriever" | ||
} | ||
|
||
func (t *Tool) Description() string { | ||
return "Query the knowledge base to find relevant documents to answer questions" | ||
} | ||
|
||
func (*Tool) Parameters() any { | ||
return map[string]any{ | ||
"type": "object", | ||
|
||
"properties": map[string]any{ | ||
"query": map[string]any{ | ||
"type": "string", | ||
"description": "The natural language query input. The query input should be clear and standalone", | ||
}, | ||
}, | ||
|
||
"required": []string{"query"}, | ||
} | ||
} | ||
|
||
func (t *Tool) Execute(ctx context.Context, parameters map[string]any) (any, error) { | ||
query, ok := parameters["query"].(string) | ||
|
||
if !ok { | ||
return nil, errors.New("missing query parameter") | ||
} | ||
|
||
options := &index.QueryOptions{} | ||
|
||
data, err := t.index.Query(ctx, query, options) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
results := []Result{} | ||
|
||
for _, r := range data { | ||
result := Result{ | ||
Title: r.Title, | ||
Content: r.Content, | ||
Location: r.Location, | ||
} | ||
|
||
results = append(results, result) | ||
} | ||
|
||
return results, nil | ||
} |
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
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
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
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