GCP HTTP Function to communicate with custom OpenAI GPT Assistant. This repository provides an example to create an assistant with knowledge base, faq and general information about its identity. It is perfectly suitable to use as a Customer Support.
- Go to Openai API Keys page and create an API key for this project
- Permissions should be write to Assistants, Threads, and Files.
- Add API key (2 options)
- Via GCP Secret Manager: You need to create a secret and put its name into .env.yaml file ,(refer to.env.yaml.example)
OPENAI_SECRET_NAME=projects/0020090084006/secrets/OPENAI_API_KEY
- Manually: Put API key into .env file
OPENAI_API_KEY=Your API KEY
Use your own package manager to install and test locally with the start npm command. (pnpm recommended)
npm install
npm run build
npm run start
- Install Google Cloud CLI (known as Cloud CDK)
gcloud init
- Create a project and set it as your default project
gcloud config set project YOUR_PROJECT_ID
npm install
npm run build
npm run gcp-deploy
You can use the function at http://localhost:8080/ locally and/or with your Cloud Function Public URL via HTTP Post methods.
Initially you will need to send an starting message to the Assistant with the following format:
{
"content": "Tell me about Quick Chat API"
}
The answer will have the threadId, status, runId and the result array with the message thread.
{
"result": [
{
"id": "string",
"object": "string",
"created_at": 0,
"assistant_id": "string",
"thread_id": "string",
"run_id": "string",
"role": "assistant",
"content": [
{
"type": "text",
"text": {
"value": "Hi, I am happy to help.",
"annotations": []
}
},
{
"type": "text",
"text": {
"value": "Tell me about Quick Chat API",
"annotations": []
}
}
],
"attachments": [],
"metadata": {}
}
],
"threadId": "string",
"status": "string",
"runId": "string"
}
Extract the threadId, and use it in the next message from now on to continue the conversation.
{
"content": "This is my second question",
"threadId": "{{threadId}}"
}
There are many ways to contribute to GPT Cloud Functions.
- Submit bugs and help us verify fixes as they are checked in.
- Review the source code changes.
- Contribute bug fixes.