-
Notifications
You must be signed in to change notification settings - Fork 3
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
Showing
5 changed files
with
76 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,7 @@ | |
"NEOC", | ||
"nonlatin", | ||
"OPENAI", | ||
"openstreetmap", | ||
"OPFS", | ||
"pageid", | ||
"Panjshir", | ||
|
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
File renamed without changes.
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,36 @@ | ||
import { Tool } from "langchain/tools"; | ||
|
||
export class Nominatim extends Tool { | ||
name = "nominatim-geocode"; | ||
description = `useful for when you need to geocode address or name of location to latitude, longitude. Input: a address or a name of location.`; | ||
|
||
async _call(input: string) { | ||
console.debug("Tool nominatim, input:", input); | ||
try { | ||
const endpoint = "https://nominatim.openstreetmap.org/search"; | ||
const searchParams = new URLSearchParams(); | ||
searchParams.append("format", "jsonv2"); | ||
searchParams.append("polygon_geojson", "0"); | ||
searchParams.append("q", input); | ||
|
||
const res = await fetch(`${endpoint}?${searchParams.toString()}`); | ||
const json = await res.json(); | ||
|
||
if (json.length === 0) { | ||
return "fetch failed. change query"; | ||
} | ||
|
||
const answer = { | ||
latitude: json[0].lat, | ||
longitude: json[0].lon, | ||
}; | ||
|
||
console.debug("Tool nominatim, answer:"); | ||
console.debug(answer); | ||
console.debug(""); | ||
return answer; | ||
} catch (error) { | ||
return "I don't know."; | ||
} | ||
} | ||
} |
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,38 @@ | ||
import { Tool } from "langchain/tools"; | ||
|
||
export class Nominatim extends Tool { | ||
name = "nominatim-search-openstreetmap"; | ||
description = `useful for when you need to get OpenStreetMap entity by name of location. Input: a name of location.`; | ||
|
||
async _call(input: string) { | ||
console.debug("Tool nominatim, input:", input); | ||
try { | ||
const endpoint = "https://nominatim.openstreetmap.org/search"; | ||
const searchParams = new URLSearchParams(); | ||
searchParams.append("format", "jsonv2"); | ||
searchParams.append("polygon_geojson", "0"); | ||
searchParams.append("q", input); | ||
|
||
const res = await fetch(`${endpoint}?${searchParams.toString()}`); | ||
const json = await res.json(); | ||
|
||
if (json.length === 0) { | ||
return "failed to fetch. change query"; | ||
} | ||
|
||
const answer = { | ||
osm_id: json[0].osm_id, | ||
osm_type: json[0].osm_type, | ||
name: json[0].name, | ||
display_name: json[0].display_name, | ||
}; | ||
|
||
console.debug("Tool nominatim, answer:"); | ||
console.debug(answer); | ||
console.debug(""); | ||
return answer; | ||
} catch (error) { | ||
return "I don't know."; | ||
} | ||
} | ||
} |