from openai import OpenAI
from base64 import b64encode
import json
client = OpenAI(
base_url="https://api.keywordsai.co/api",
api_key="Your_Keywords_AI_API_Key",
)
keywordsai_params = {
"metadata": {
"paid_user": "true",
}
# Other keywordsai params
}
keywordsai_params_header = {
"X-Data-Keywordsai-Params": b64encode(json.dumps(keywordsai_params).encode()).decode(),
}
def test_file_search():
tools = [
{
"type": "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", "unit"],
}
}
]
response = client.responses.create(
model="gpt-4o",
tools=tools,
input="What is the weather like in Boston today?",
tool_choice="auto",
extra_headers=keywordsai_params_header,
)
print(response)
if __name__ == "__main__":
test_file_search()