Gleen provides an API that allows developers to engage with their application (knowledgebase hosted on Gleen). To obtain your API key, visit your account at https://www.gleen.ai/login and navigate to the bottom of the page.
Good to know: Please note that you need the api key only if you are try to use curl request to call Gleen AI services from your backend. For front end integration take a look at Website SDK
Getting the Access token
Access token can be created in developer api section
Important : API keys are visible once. If api key is lost then you need to create a new one.
Terminology
A user query is the question a customer enters and the developer sends to Gleen AI.
A Gleen AI Response is what Gleen AI returns after a user query is submitted.
A thread is all user queries from a specific user and all associated Gleen AI responses. All user queries and Gleen AI responses that belong to a thread will have the same unique thread_id associated to them.
For example, the user queries and Gleen AI responses below are all one thread:
user: Hello
Gleen AI: How can I help you?
user: What is Gleen AI?
Gleen AI: A customer success product
How does thread_id work?
Gleen AI api has an optional parameter thread_id. When a given user ask first question then developer needs to pass empty or simple don't pass thread_id. In this case gleen ai return the response and generate the thread_id
For the next follow up conversation, developers need to pass the thread_id. By passing thread_id, developers intent to convey that this is a follow up message rather a new conversation
Gleen AI will return the thread_id in every response. If it's a new conversation then new thread_id is returned. If it is a follow up conversation then Gleen AI return the same thread_id
Send Message
Using send message api
send_message api returns the generate response given the user's query
POSThttps://api.gleen.ai/api/v1/send_message
send a query to gleen ai endpoint
Headers
Request Body
{"thread_id"="802300","conversation_id"="232312","response": {"text":"Hello how can I help you?", }}
Making requests VIA CURL
You can paste the command below into your terminal to run your first API request. Make sure to replace $GLEENAI_API_KEY with your secret API key.
curlhttps://api.gleen.ai/api/v1/send_message \-H"Content-Type: application/json" \-H"Authorization: Bearer $GLEEN_API_KEY" \-d'{ "query_text": "What is the weather in celsius in San Francisco, CA?", }'
You should get a response back that resembles the following:
{
"result_text": "I'm sorry, but as a text-based virtual assistant, I don't have the capability to execute functions or retrieve real-time data. However, you can use the `get_current_weather` function in your environment to get the current weather. Here's how you can use it:\n\n```javascript\nfunctions.get_current_weather({\n location: \"San Francisco, CA\",\n unit: \"celsius\"\n})\n```\n\nPlease replace `functions` with the actual namespace or object where the function resides in your environment.",
"response_time": 12.15244152606465,
}
Making requests via python sdk
python installation
pip install gleenai
Setting up GLEENAI_API_KEY
gleenai.set_api_key("YOUR_API_KEY")
Sending requests
response = gleenai.send_message(
query_text="YOUR_QUERY_TEXT",
thread_id="optional - Your thread from prevois call"
)
Sample response
'result_text': 'Sure, I\'d be happy to help. The Dockerfile you\'ve provided seems mostly correct, but there are a couple of potential issues that might be causing the build to fail.\n\n1. **Requirements File:** The `RUN pip install -r requirement.txt` command assumes that a file named `requirement.txt` exists in the `src` directory. If the file doesn\'t exist or is named differently (commonly it\'s named `requirements.txt`), this could cause the build to fail. Make sure the file exists and is correctly named.\n\n2. **CMD Syntax:** The CMD command should use double quotes ("") instead of single quotes (\'\'). This could be causing an issue.\n\nHere\'s an updated version of your Dockerfile:\n\n```Dockerfile\nFROM python:3.9\n\nWORKDIR /app\n\nCOPY src /app\n\nRUN pip install -r requirements.txt\n\nCMD ["python", "./app.py"]\n```\n\nPlease replace `requirements.txt` with your actual requirements file name if it\'s different. Also, ensure that `app.py` is present in the `src` directory. \n\nTry building the Docker image again with this updated Dockerfile. If you\'re still encountering issues, please provide the error message you\'re seeing during the build process for further assistance. \n\nHere is a [link](https://docs.docker.com/language/python/build-images/) that may be relevant.',
'thread_id': 'c62614c9-ef57-4697-8105-f0c9a970bb13'}
Example - 1
query_text = "I recently attempted to build a Docker image using a Dockerfile, but the build process failed. I suspect there'\''s an issue with one of the commands in the Dockerfile, but I'\''m not sure how to resolve it. Can you help me update the Dockerfile to fix the build issue? Here is the dockerfile\n\n``` FROM python:3.9\n\nWORKDIR /app\n\nCOPY src /app\n\nRUN pip install -r requirement.txt\n\nCMD ['\''python'\'', '\''./app.py'\'']"
response = gleenai.send_message(query_text=query_text)
response is
{
'result_text': 'Sure, I\'d be happy to help. The Dockerfile you\'ve provided seems mostly correct, but there are a couple of potential issues that might be causing the build to fail.\n\n1. **Requirements File:** The `RUN pip install -r requirement.txt` command assumes that a file named `requirement.txt` exists in the `src` directory. If the file doesn\'t exist or is named differently (commonly it\'s named `requirements.txt`), this could cause the build to fail. Make sure the file exists and is correctly named.\n\n2. **CMD Syntax:** The CMD command should use double quotes ("") instead of single quotes (\'\'). This could be causing an issue.\n\nHere\'s an updated version of your Dockerfile:\n\n```Dockerfile\nFROM python:3.9\n\nWORKDIR /app\n\nCOPY src /app\n\nRUN pip install -r requirements.txt\n\nCMD ["python", "./app.py"]\n```\n\nPlease replace `requirements.txt` with your actual requirements file name if it\'s different. Also, ensure that `app.py` is present in the `src` directory. \n\nTry building the Docker image again with this updated Dockerfile. If you\'re still encountering issues, please provide the error message you\'re seeing during the build process for further assistance. \n\nHere is a [link](https://docs.docker.com/language/python/build-images/) that may be relevant.',
'thread_id': 'c62614c9-ef57-4697-8105-f0c9a970bb13'
}
Name
Type
Description
Name
Type
Description
GLEENAI_API_KEY*
String
auth key for your gleen api
query_text*
string
query text sent to gleen ai for the response generation