Spaces:
Sleeping
Sleeping
File size: 1,465 Bytes
b35b8c6 25392ae b35b8c6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import requests
import json
# API Gateway Invoke URL (Replace with your actual API endpoint)
API_URL = "https://zyqnod20re.execute-api.us-east-1.amazonaws.com/dev/test_bedrock_v4_deepseek"
def query_deepseek(prompt: str, max_gen_len: int, temperature: float, top_p: float) -> str:
"""
Sends a request to the DeepSeek-R1 model via AWS Bedrock API and returns the response.
Args:
prompt (str): The user input query.
max_gen_len (int): The maximum length of the generated response.
temperature (float): Controls the randomness of the model output.
top_p (float): The nucleus sampling parameter.
Returns:
str: The generated response from the model.
"""
payload = {
"prompt": prompt,
"max_gen_len": max_gen_len,
"temperature": temperature,
"top_p": top_p
}
headers = {"Content-Type": "application/json"}
try:
response = requests.post(API_URL, headers=headers, data=json.dumps(payload))
if response.status_code == 200:
full_response = response.json()
# Extract the output text from the model response
output_text = full_response.get("model_response").get("choices")[0].get("text")
return output_text
else:
return f"Error {response.status_code}: {response.text}"
except requests.exceptions.RequestException as e:
return f"Request failed: {e}"
|