So I have added in the creds - now what
Nothing seems to happen.
Can I upload docs with this Action or do I need to create my own one ?
Iain
So I have added in the creds - now what
Nothing seems to happen.
Can I upload docs with this Action or do I need to create my own one ?
Iain
@ihmunro sorry mate, completely missed this post. Do you still need help with this?
H AB
Yes - I did not progress passed this.
Can you tell me what the use case is?
Do you want to send data to Pinecone or retrieve it?
Hi AB
I did not have a specific use case.
I was trying to send data, then retrieve it.
@ihmunro got it.
Then you need to create an agent in Pinecone and add files in it.
Then you can create a Pinecone action in Pickaxe to hit the assistant API endpoint with your question as a variable.
This is the code:
import os
import requests
import json
def pinecone_assistant(question: str):
"""
Send the question to the Pinecone assistant to retrieve an answer
Args:
question (string): User's question
"""
# Insert your PYTHON code below. You can access environment variables using os.environ[].
# Currently, only the requests library is supported, but more libraries will be available soon.
# Use print statements or return values to display results to the user.
# If you save a png, pdf, csv, jpg, webp, gif, or html file in the root directory, it will be automatically displayed to the user.
# You do not have to call this function as the bot will automatically call and fill in the parameters.
# Pinecone Assistant API endpoint
url = "https://prod-1-data.ke.pinecone.io/assistant/chat/*assistant name*"
# Payload containing the user's question
payload = {
"messages": [
{
"role": "user",
"content": question
}
],
"stream": False,
"model": "gpt-4o"
}
# Headers including the API key for authentication
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer pcsk_6T6btv_LEyA7BxeAdzErJoogVeVKRAhS94hXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
}
try:
# Make the POST request
response = requests.post(url, headers=headers, json=payload, timeout=10)
# Parse the JSON response
response_data = response.json()
# Log the full response (for debugging)
print("Full Response JSON:", json.dumps(response_data, indent=2))
# Extract assistant reply
assistant_reply = response_data.get("message", {}).get("content", "No response received.")
# Extract file details (assuming first citation exists)
citations = response_data.get("citations", [])
if citations:
first_citation = citations[0].get("references", [])[0].get("file", {})
file_name = first_citation.get("name", "No file name available")
file_url = first_citation.get("signed_url", "No file URL available")
else:
file_name = "No citations available"
file_url = "No file URL available"
# Return all details as plain text
result = (
f"""GIVE THE FOLLOWING REPLY DIRECTLY INCLUDING THE POSITION:
{assistant_reply}
At the end of your response, LINK THE FOLLOWING FILES, STARTING WITH THE POSITION:
File Name: {file_name}
File URL: {file_url}"""
)
return result
except Exception as e:
# Return error information
return f"An error occurred: {e}"