Closed tigflanker closed 2 months ago
I found two similar unsolved discussions that might be relevant to your issue:
Regarding your issue, it seems that the API function is not being effectively referenced when calling it in the general application. Dify requires the API to return result=pong
when it receives point=ping
to verify the availability of the API. Ensure that your API correctly handles this verification request.
Here is a relevant code snippet to handle the ping
request:
from fastapi import FastAPI, Body, HTTPException, Header
from pydantic import BaseModel
app = FastAPI()
class InputData(BaseModel):
point: str
params: dict = {}
@app.post("/api/dify/receive")
async def dify_receive(data: InputData = Body(...), authorization: str = Header(None)):
expected_api_key = "123456" # TODO Your API key of this API
auth_scheme, _, api_key = authorization.partition(' ')
if auth_scheme.lower() != "bearer" or api_key != expected_api_key:
raise HTTPException(status_code=401, detail="Unauthorized")
point = data.point
# for debug
print(f"point: {point}")
if point == "ping":
return {
"result": "pong"
}
if point == "app.current_time":
from datetime import datetime
return {
"result": datetime.now().isoformat()
}
# elif point == "{point name}":
# TODO other point implementation here
raise HTTPException(status_code=400, detail="Not implemented")
Make sure this part of the code is correctly implemented and that your API is returning the expected response for the ping
request. Additionally, ensure that your API endpoint is correctly configured to handle the Authorization
header and the Content-Type
as application/json
.
According to the Dify documentation, the API should be set up to handle requests with the following headers and body:
Headers:
Content-Type: application/json
Authorization: Bearer {api_key}
Request Body:
{
"point": "ping"
}
Expected Response:
{
"result": "pong"
}
Ensure that your API adheres to these specifications to be correctly referenced and utilized by the general application [3][4][5].
To continue talking to Dosu, mention @dosu.
@dosu I have already tested "point": "ping" and successfully received a response with "result": "pong". Now it appears that the service can pass the test, and the API can be set up successfully. The issue might be with the API invocation (variable reference) in the large language model application step.
If the API passes the "ping" test successfully but the variable reference in the large language model application step is not working, it might be due to incorrect or missing credentials. Ensure that the environment variables for the API credentials are correctly set with valid values:
os.environ.get("VOLC_API_KEY")
os.environ.get("VOLC_SECRET_KEY")
os.environ.get("VOLC_MODEL_ENDPOINT_ID")
If these values are not set or are incorrect, the API invocation will fail even if the "ping" test passes [1].
Additionally, specific logs or error messages are generated when the variable reference fails. The invoke
method in the LargeLanguageModel
class includes a try-except block that catches exceptions and triggers error callbacks. Ensure to check these logs for any exceptions that might provide more insight into the issue [2].
To continue talking to Dosu, mention @dosu.
Self Checks
Dify version
v0.7.3
Cloud or Self Hosted
Self Hosted (Docker)
Steps to reproduce
Hello, I have set up the API in the web API extension, but it seems that it is not being effectively referenced when calling it.
This is the API code, service, and test call situation:
This is the API extension setup interface:
This is the general application's invocation interface, where I have not been able to successfully invoke it in the opening remarks and prompts:
✔️ Expected Behavior
No response
❌ Actual Behavior
No response