forked from Chat_things/NeuroDock
Added Wikipedia API wrapper
GetWikiPegeText: - Fetches a Wikipedia wiki page WikipediaTool: - The base for this module, Initialise a Wiki instance and add the Wikipedia API endpoints
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package me.zacharias.neuro.dock.wikipedia;
|
||||
|
||||
import io.github.fastily.jwiki.core.Wiki;
|
||||
import me.zacharias.chat.ollama.OllamaFunctionArgument;
|
||||
import me.zacharias.chat.ollama.OllamaFunctionTool;
|
||||
import me.zacharias.chat.ollama.OllamaPerameter;
|
||||
import me.zacharias.chat.ollama.OllamaToolRespnce;
|
||||
|
||||
public class GetWikiPageText extends OllamaFunctionTool {
|
||||
Wiki wiki = WikipediaTool.wiki;
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "get_wiki_page_text";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return "Gets the text of a Wikipedia page by its title.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public OllamaPerameter parameters() {
|
||||
return OllamaPerameter.builder()
|
||||
.addProperty("title", OllamaPerameter.OllamaPerameterBuilder.Type.STRING, "The title of the Wikipedia page to retrieve text from.", true)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OllamaToolRespnce function(OllamaFunctionArgument... args) {
|
||||
return new OllamaToolRespnce(name(), wiki.getPageText((String) args[0].value()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package me.zacharias.neuro.dock.wikipedia;
|
||||
|
||||
import io.github.fastily.jwiki.core.Wiki;
|
||||
import me.zacharias.chat.core.Core;
|
||||
import me.zacharias.chat.ollama.OllamaFunctionTools;
|
||||
|
||||
public class WikipediaTool {
|
||||
private OllamaFunctionTools wikipediaToolsInstance;
|
||||
|
||||
public static Wiki wiki = new Wiki.Builder()
|
||||
//.withDomain("en.wikipedia.org")
|
||||
.build();
|
||||
|
||||
public WikipediaTool() {
|
||||
this.wikipediaToolsInstance = OllamaFunctionTools.builder()
|
||||
.addTool(new GetWikiPageText(), Core.Source.INTERNAL)
|
||||
.build();
|
||||
}
|
||||
|
||||
public OllamaFunctionTools getWikipediaToolsInstance() {
|
||||
return wikipediaToolsInstance;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user