-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathweb-tools.lisp
More file actions
90 lines (86 loc) · 4.82 KB
/
web-tools.lisp
File metadata and controls
90 lines (86 loc) · 4.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
;;; -*- Lisp -*-
(in-package "GEMINI")
(defun web-tools-and-handlers ()
"Return a list of web-related functions and their handlers."
(list
(cons
(function-declaration
:name "httpGet"
:description "Performs an HTTP GET request to the specified URL and returns the response body as a string."
:behavior :blocking
:parameters (schema :type :object
:properties (object :url
(schema :type :string
:description "The URL to send the GET request to."))
:required (vector :url))
:response (schema :type :string))
(lambda (&key url)
(dexador:get url)))
(when (and (google:hyperspec-search-engine-id)
(google:search-engine-api-key))
(cons
(function-declaration
:name "hyperspecSearch"
:description "Search the Common Lisp Hyperspec for pages about a topic."
:behavior :blocking
:parameters (schema :type :object
:properties (object :search-terms
(schema :type :string
:description "The search terms to use for the hyperspec search. Use spaces to separate terms."))
:required (vector :search-terms))
:response (schema :type :object
:properties (object :items
(schema :type :array
:items (schema :type :object
:properties (object
:title (schema :type :string)
:link (schema :type :string)
:snippet (schema :type :string))
:required (vector :link :snippet :title))))
:required (vector :items)))
(lambda (&key search-terms)
(format *trace-output* "~&;; Search Terms: ~{~a~^ ~}~%" (str:split " " search-terms :omit-nulls t))
(finish-output *trace-output*)
(object :items
(map 'list (lambda (item)
(object :title (get-title item)
:link (get-link item)
:snippet (get-snippet item))
)
(get-items
(google:hyperspec-search
(str:join "+" (str:split " " search-terms :omit-nulls t)))))))))
(when (and (google:google-search-engine-id)
(google:search-engine-api-key))
(cons
(function-declaration
:name "webSearch"
:description "Search the Web for pages about a topic."
:behavior :blocking
:parameters (schema :type :object
:properties (object :search-terms
(schema :type :string
:description "The search terms to use for the web search. Use spaces to separate terms."))
:required (vector :search-terms))
:response (schema :type :object
:properties (object :items
(schema :type :array
:items (schema :type :object
:properties (object
:title (schema :type :string)
:link (schema :type :string)
:snippet (schema :type :string))
:required (vector :link :snippet :title))))
:required (vector :items)))
(lambda (&key search-terms)
(format *trace-output* "~&;; Search Terms: ~{~a~^ ~}~%" (str:split " " search-terms :omit-nulls t))
(finish-output *trace-output*)
(object :items
(map 'list (lambda (item)
(object :title (get-title item)
:link (get-link item)
:snippet (get-snippet item))
)
(get-items
(google:web-search
(str:join "+" (str:split " " search-terms :omit-nulls t)))))))))))