[Need help] Create Custom Tools for Redmine
Self Checks
- [X] I have searched for existing issues search for existing issues, including closed ones.
- [X] I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
- [X] Pleas do not modify this template :) and fill in all the required fields.
Provide a description of the help you need
Hello,
I would like to create a custom tool that allows the LLM to search for tickets in Redmine when I ask a question like:
"Have we ever had an Alpha network problem on Redmine?"
With this question, the LLM would use OpenAPI Swagger to search for relevant tickets, then synthesize and send a response based on the tickets it has retrieved from Redmine, including the ticket numbers.
However, I'm struggling with this. Could I get some help?
Here is my code.
` openapi: "3.1.0" info: title: "Redmine Project Ticket Search API" description: "API for searching tickets in the 'informatique' project on Redmine." version: "v1.0.0" servers:
- url: "http://172.21.0.2:3000" paths: /projects/informatique/issues: get: summary: "Search tickets in 'informatique'" description: "Retrieve a list of tickets from the 'informatique' project by keywords." parameters: - name: "subject" in: "query" required: false description: "Subject to search for in the project's tickets" schema: type: "string" responses: "200": description: "A list of tickets matching the query in the 'informatique' project" content: application/json: schema: type: "array" items: $ref: "#/components/schemas/Issue" components: schemas: Issue: type: "object" properties: id: type: "integer" subject: type: "string" securitySchemes: api_key: type: "apiKey" name: "X-Redmine-API-Key" in: "header" security:
- api_key: []
`
Thank you in advance.
🤖
Based on the OpenAPI Swagger code you've shared, it seems like you're on the right track. However, without knowing the exact error message or issue you're encountering, it's a bit difficult to provide a precise solution.
As for the screenshots you've attached, I'm sorry but I'm unable to view images or URLs. Could you please provide the error message or describe the issue you're facing in text form? This would greatly help in diagnosing the problem.
Regarding your goal to create a custom tool that allows the LLM to search for tickets in Redmine, you might need to modify your code to include a method that performs a search on Redmine's API. Here's a basic Python example of how you could implement this:
def search_tickets(self, query: str) -> str:
"""
Search for tickets in Redmine based on a query.
:param query: The query to search for.
:return: The search results.
"""
# The Redmine API endpoint for searching issues
url = f"{self.api_bundle.server_url}/issues.json"
# The parameters for the search
parameters = {
'subject': query,
}
# Assemble the request
headers = self.assembling_request(parameters)
# Do the HTTP request
response = self.do_http_request(url, 'get', headers, parameters)
# Validate the response
response = self.validate_and_parse_response(response)
# Parse the response JSON
response_json = json.loads(response)
# Extract the ticket numbers from the response
ticket_numbers = [issue['id'] for issue in response_json['issues']]
# Return the ticket numbers
return ticket_numbers
This method sends a GET request to the Redmine API's /issues.json endpoint, passing the query as the subject parameter. It then validates the response, extracts the ticket numbers from the response JSON, and returns them.
Please note that this is a basic example and might need to be adjusted based on your specific needs and the exact structure of the Redmine API's response. Also, you would need to handle the authentication to the Redmine API, which is not covered in this example.
I hope this helps! If you could provide more details about the issue you're facing, I'd be more than happy to assist you further.
Sources
About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.
🤖
Based on the OpenAPI Swagger code you've shared, it seems like you're on the right track. However, without knowing the exact error message or issue you're encountering, it's a bit difficult to provide a precise solution.
As for the screenshots you've attached, I'm sorry but I'm unable to view images or URLs. Could you please provide the error message or describe the issue you're facing in text form? This would greatly help in diagnosing the problem.
Regarding your goal to create a custom tool that allows the LLM to search for tickets in Redmine, you might need to modify your code to include a method that performs a search on Redmine's API. Here's a basic Python example of how you could implement this:
def search_tickets(self, query: str) -> str: """ Search for tickets in Redmine based on a query. :param query: The query to search for. :return: The search results. """ # The Redmine API endpoint for searching issues url = f"{self.api_bundle.server_url}/issues.json" # The parameters for the search parameters = { 'subject': query, } # Assemble the request headers = self.assembling_request(parameters) # Do the HTTP request response = self.do_http_request(url, 'get', headers, parameters) # Validate the response response = self.validate_and_parse_response(response) # Parse the response JSON response_json = json.loads(response) # Extract the ticket numbers from the response ticket_numbers = [issue['id'] for issue in response_json['issues']] # Return the ticket numbers return ticket_numbersThis method sends a GET request to the Redmine API's
/issues.jsonendpoint, passing the query as thesubjectparameter. It then validates the response, extracts the ticket numbers from the response JSON, and returns them.Please note that this is a basic example and might need to be adjusted based on your specific needs and the exact structure of the Redmine API's response. Also, you would need to handle the authentication to the Redmine API, which is not covered in this example.
I hope this helps! If you could provide more details about the issue you're facing, I'd be more than happy to assist you further.
Sources
* [api/core/tools/tool/api_tool.py](https://github.com/langgenius/dify/blob/main/api/core/tools/tool/api_tool.py)About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.
@dosu-bot When I test a ticket search request, I get this error: [Errno 99] Cannot assign requested address.
I thought that to create a custom tool, you just had to write the OpenAPI Swagger code in YAML and not use Python?
If Python script is required, where should I do it?
🤖
Based on the OpenAPI Swagger code you've provided, it seems like you're trying to bind to localhost:3000. The error "[Errno 99] Cannot assign requested address" is typically a network-related error that occurs when a network operation tries to bind to an IP address that is not available on the system.
Here are a few things you could check:
-
Make sure that the IP address and port you're using (
localhost:3000in this case) are correct and available. You can check if the port is already in use by another process with the following command in your terminal:lsof -i :3000. If this command returns any output, it means the port is already in use. -
If you're running your application in a Docker container, this error can occur if the application inside the Docker container tries to bind to a non-loopback address (i.e., an address other than
127.0.0.1). In this case, you should bind your application to0.0.0.0or127.0.0.1. -
If you're running your application on a cloud platform, make sure the IP address and port you're using are allowed by your cloud provider's firewall rules.
Regarding your question about Python, OpenAPI Swagger is a specification for building APIs and doesn't require Python specifically. You can use any language that supports HTTP to make requests to an API defined with OpenAPI Swagger. However, if you're using a library or tool that uses Python to interact with the API, you might need to write some Python code.
If you're still encountering this error after checking these things, could you provide more details about your network setup and the part of your code that's causing this error? This would help in providing a more precise solution.
Sources
About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.
@dosu-bot my port is open, is not a network problem :
(base) gpt-lab@gpt-lab-tower:~$ curl -H "X-Redmine-API-Key: b43cafdbdf667039bf920943b9f3ab281f1da1ef" "http://localhost:3000/projects/informatique/issues.json" {"issues":[{"id":50,"project":{"id":1,"name":"Informatique"},"tracker":{"id":1,"name":"test"},"status":{"id":1,"name":"test","is_closed":false},"priority":{"id":2,"name":"test"},"author":{"id":1,"name":"Redmine Admin"},"subject":"Intégration d'un système de contrôle de version pour le code source","description":"Un système de supervision réseau doit être déployé pour surveiller l'état du réseau et détecter les anomalies de manière proactive.","start_date":"2024-02-23","due_date":null,"done_ratio":0,"is_private":false,"estimated_hours":null,"total_estimated_hours":null,"spent_hours":0.0,"total_spent_hours":0.0,"created_on":"2024-02-23T14:26:32Z","updated_on":"2024-02-23T14:35:04Z","closed_on":null},{"id":49,"project":{"id":1,"name":"Informatique"},"tracker":{"id":1,"name":"test"},"status":{"id":1,"name":"test","is_closed":false},"priority":{"id":2,"name":"test"},"author":{"id":1,"name":"Redmine Admin"},"subject":"Intégration d'un système de gestion de configuration","description":"Un tableau de bord de surveillance système doit être développé pour permettre aux administrateurs de suivre en temps réel les performances du réseau.","start_date":"2024-02-23","due_date":null,"done_ratio":0,"is_private":false,"estimated_hours":null,"total_estimated_hours":null,"spent_hours":0.0,"total_spent_hours":0.0,"created_on":"2024-02-23T14:26:32Z","updated_on":"2024-02-23T14:35:04Z","closed_on":null}
The issue here is resolved; it was a network problem. Now I have another problem: the output is not what I expected. I thought I would receive a ticket or tickets that would then be synthesized by the LLM, but I receive an HTML page. Can someone help me, please?
I thought that to create a custom tool, you just had to write the OpenAPI Swagger code in YAML and not use Python? If Python script is required, where should I do it? @MrBrabus75 Hello
OpenAPI code is just a documentation for LLM, it stills needs some third party service to retrieve it for you. For example, I wrote a cloudflare worker to generate and respond at the same time. The code is written in JavaScript, but it's quite simple.
https://github.com/crazywoola/dify-tools-worker
The issue here is resolved; it was a network problem. Now I have another problem: the output is not what I expected. I thought I would receive a ticket or tickets that would then be synthesized by the LLM, but I receive an HTML page. Can someone help me, please?
And I think you need this tool(maybe not mine) to process the html code to you or you can just let the llm itself to parse it for you, but some tags will occupy the space in context window. So I suggest you to write a simpler API to get only required information for you.
@dosu-bot
how to use self.create_blob_message() to show the audio player in the frontpage?
Hi, @MrBrabus75,
I'm helping the team manage their backlog and am marking this issue as stale. From what I understand, you were seeking help to create a custom tool for Redmine using OpenAPI Swagger to search for relevant tickets and provide a response based on the retrieved tickets. There were discussions about troubleshooting a network error, which was confirmed to be resolved by you. However, you still needed assistance with the unexpected output. Additionally, ZJ-CAI had a question related to using self.create_blob_message() to show the audio player in the front page.
Could you please confirm if this issue is still relevant to the latest version of the repository? If it is, please let the team know by commenting on the issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days. Thank you!