Following the fourth article, since I didn't know what to write, I happened to see someone in the group mention how to call the anythingllm API elsewhere, which led to this blog post, intended for technical learning purposes. For more application methods, please refer to the anythingllm API documentation.
Now that we have built a knowledge base using the private knowledge base set up with cloud studio, how can we call it elsewhere, or can we provide an API for our use?
anythingllm actually provides an API, but you need to have a bit of programming knowledge to use it. After all, having an API means we can use it under any project, as the data we feed in needs to be utilized, and we want to use it wherever we want, not just under anythingllm.
Alright, without further ado, let's start the tutorial.
Now that we have fed data to deepseek through the fourth article, how can we use it via the API?
- Open the anythingllm settings interface [wrench icon].
- Scroll through the left menu and select Tools ---> API Key
- Click to generate a new API key, a new pop-up will appear, we create the API key.
- Then click copy key and read the API doc in sequence,
- On the opened AnythingLLM Developer API page, we click
Authorize
, paste the API key we just copied.
- Close the pop-up.
- Scroll down to find /v1/workspace/{slug}/stream-chat under the Workspaces group and click it.
- Click the try out button and modify the slug value, the slug value is the name of the workspace we created initially.
See the image: Workspace
My value here is demo.
And modify the Request body content to:
Finally, click execute.
As shown in the image:
After a moment, we will see the response content.
Here, we are testing whether this API can be used normally.
So how can we call it elsewhere?
Suppose we call it from a webpage.
This requires using node + html.
Since this is a test, I will directly provide my demo code.
main.js
index.html
These two files can be directly written in cs.
The directory structure is as follows:
Then in the terminal, run, I simply use python to provide the web service on port 8089, press enter, nginx or nodejs can also be used.
Click to open the browser.
Paste the key we created earlier and click save.
Enter our question in the dialog box.
Let's see how the response is.
At this point, we have already called the data from our private knowledge base in the demo workspace.