import requests
url = "https://api.keywordsai.co/api/request-logs/create/"
headers = {
"Authorization": "Bearer YOUR_KEYWORDS_AI_API_KEY",
"Content-Type": "application/json"
}
payload = {
"model": "gpt-4",
"prompt_messages": [
{
"role": "user",
"content": "Hi"
},
{
"role": "assistant",
"content": None,
"tool_calls": [
{
"id": "xxxx",
"type": "function",
"function": {
"name": "get_current_weather", # Function name
"arguments": "{\n\"location\": \"Boston, MA\"\n}" # Function arguments
}
}
]
}, #optional
],
"completion_message": {
"role": "assistant",
"content": "Hi, how can I assist you today?"
},
"tool_choice": {
"type": "function",
"function": {
"name": "get_current_weather"
}
},
"tools":[
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA",
},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
},
"required": ["location"],
},
},
}
],
"customer_params": {
"customer_identifier": "customer_123",
"name": "Hendrix Liu", # optional
"email": "hendrix@keywordsai.co" # optional
},
"prompt_tokens": 8,
"completion_tokens": 16,
"cost": 0.00042,
"latency": 0.0,
"timestamp": "2024-04-15T08:30:37.721313Z",
"time_to_first_token": 0.0,
"metadata": {},
"stream": False,
"status_code": 200,
"warnings": "",
"error_message": "",
"type":"text", # "json_schema", "json_object"
}
response = requests.request("POST", url, headers=headers, json=payload)