Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question]: I have an api with student mark details deployed in fast api #17336

Open
1 task done
navaneethstabilix opened this issue Dec 20, 2024 · 1 comment
Open
1 task done
Labels
question Further information is requested

Comments

@navaneethstabilix
Copy link

Question Validation

  • I have searched both the documentation and discord for an answer.

Question

how to create an agent to use api and extract the details and give response according to api response.api consist of student details.send input to api as name use and agent for it

@navaneethstabilix navaneethstabilix added the question Further information is requested label Dec 20, 2024
Copy link

dosubot bot commented Dec 20, 2024

To create an agent that interacts with your FastAPI-based API to extract student mark details, you can follow these steps:

  1. Set Up the API Client: Use a library like httpx or requests to make HTTP requests to your API. This client will send requests to the API endpoint with the student's name as a parameter.

  2. Define the API Endpoint: Ensure you know the exact URL of your API endpoint that provides student mark details. This typically involves a GET request with a query parameter for the student's name.

  3. Create the Agent: Implement a function or class that acts as an agent. This agent will:

    • Accept a student's name as input.
    • Use the API client to send a request to the API.
    • Parse the API response to extract the necessary details.
  4. Handle the API Response: Once you receive the response from the API, process it to extract the student details. Ensure you handle any potential errors, such as network issues or invalid responses.

  5. Return the Response: Format the extracted details into a user-friendly response. This could be a simple text message or a structured data format, depending on your requirements.

Here's a basic example using httpx:

import httpx

class StudentAgent:
    def __init__(self, api_url):
        self.api_url = api_url

    def get_student_details(self, student_name):
        try:
            response = httpx.get(f"{self.api_url}/student", params={"name": student_name})
            response.raise_for_status()
            student_details = response.json()
            return student_details
        except httpx.HTTPStatusError as e:
            return f"Error: {e.response.status_code} - {e.response.text}"
        except Exception as e:
            return f"An error occurred: {str(e)}"

# Usage
agent = StudentAgent("http://your-api-url.com")
details = agent.get_student_details("John Doe")
print(details)

Make sure to replace "http://your-api-url.com" with the actual URL of your API. This example assumes the API returns a JSON response with the student details. Adjust the code as needed based on your API's specific requirements and response structure.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant