Power of Compound LLM
User: make a query to the spacex api and print its response
AI: To make a query to the SpaceX API and print its response, I will use the requests
library in Python to send a GET request to the API endpoint. Based on the search results, I found that the SpaceX API has several endpoints for different types of data. The most relevant endpoint for this task appears to be https://api.spacexdata.com/v4/launches/latest
. This endpoint returns information about the latest launch.
Here is the Python code to make a query to the SpaceX API and print its response:
import requests
import json
def get_latest_launch():
url = 'https://api.spacexdata.com/v4/launches/latest'
try:
response = requests.get(url)
response.raise_for_status() # Raise an exception for HTTP errors
return response.json()
except requests.RequestException as e:
print(f"An error occurred: {e}")
return None
latest_launch = get_latest_launch()
print(json.dumps(latest_launch, indent=4))
This code sends a GET request to the https://api.spacexdata.com/v4/launches/latest
endpoint and prints the response in a JSON format.
The response from the API includes various details such as the launch date, rocket used, crew members, and more. Here is an example of the response:
{
"fairings": null,
"links": {
"patch": {
"small": "https://images2.imgbox.com/eb/d8/D1Yywp0w_o.png",
"large": "https://images2.imgbox.com/33/2e/k6VE4iYl_o.png"
},
"reddit": {
"campaign": null,
"launch": "https://www.reddit.com/r/spacex/comments/xvm76j/rspacex_crew5_launchcoast_docking_discussion_and/",
"media": null,
"recovery": null
},
"flickr": {
"small": [],
"original": []
},
"presskit": null,
"webcast": "https://youtu.be/5EwW8ZkArL4",
"youtube_id": "5EwW8ZkArL4",
"article": null,
"wikipedia": "https://en.wikipedia.org/wiki/SpaceX_Crew-5"
},
"static_fire_date_utc": null,
"static_fire_date_unix": null,
"net": false,
"window": null,
"rocket": "5e9d0d95eda69973a809d1ec",
"success": true,
"failures": [],
"details": null,
"crew": [
"62dd7196202306255024d13c",
"62dd71c9202306255024d13d",
"62dd7210202306255024d13e",
"62dd7253202306255024d13f"
],
"ships": [],
"capsules": [
"617c05591bad2c661a6e2909"
],
"payloads": [
"62dd73ed202306255024d145"
],
"launchpad": "5e9e4502f509094188566f88",
"flight_number": 187,
"name": "Crew-5",
"date_utc": "2022-10-05T16:00:00.000Z",
"date_unix": 1664985600,
"date_local": "2022-10-05T12:00:00-04:00",
"date_precision": "hour",
"upcoming": false,
"cores": [
{
"core": "633d9da635a71d1d9c66797b",
"flight": 1,
"gridfins": true,
"legs": true,
"reused": false,
"landing_attempt": true,
"landing_success": true,
"landing_type": "ASDS",
"landpad": "5e9e3033383ecbb9e534e7cc"
}
],
"auto_update": true,
"tbd": false,
"launch_library_id": "f33d5ece-e825-4cd8-809f-1d4c72a2e0d3",
"id": "62dd70d5202306255024d139"
}
This response provides information about the latest launch, including the launch date, rocket used, crew members, and more.
This is the power of Groq Compound LLMs search, execute code!