A unified library for interacting with various AI APIs through a standardized interface.
Project description
SwitchAI
Function Calling
from pyexpat.errors import messages
from src.switchai import SwitchAI
if name == "main": # client = SwitchAI("gpt-4o-mini", 'sk-proj-dp0ZzYC8IvFbOq7nRWFwT3BlbkFJqyW0WROn28sTyOx5R1Bx') # client = SwitchAI("mistral-small-latest", '2JflG1vbNRFEnoK8mSGXCf8kdNzGF4is') # client = SwitchAI("grok-beta", "xai-ArfuFlafSw0ODUmjuq79YPmc3CnFX4XZe2aG7GE5jKqH1hHAzGASRh1pHpyiwCIGv0Kij2yTmUYQOUZu") client = SwitchAI("claude-3-5-haiku-latest", "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") # client = SwitchAI("models/text-embedding-004", "AIzaSyDYqWgtMzgNLB-xNJmJp36PsBEu8iYH2pU")
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string"}
},
},
},
}
]
messages = [
{"role": "user", "content": "What's the weather like in Paris today?"}
]
response = client.chat(
messages=messages,
tools=tools,
max_tokens=1024
)
print(response)
tool_calls = response.choices[0].tool_calls
tool_call = tool_calls[0]
function_call_result_message = {
"role": "tool",
"content": "The weather in Paris today is 20°C and sunny.",
"tool_call_id": tool_call.id
}
messages.append(response.choices[0])
messages.append(function_call_result_message)
response = client.chat(
messages=messages,
max_tokens=1024,
tools=tools
)
print(response)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file switchai-0.1.0.tar.gz.
File metadata
- Download URL: switchai-0.1.0.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09e964434eecd9e5e7272493c15cd90d4e9462e4610ac588c6301f5f04efdbdf
|
|
| MD5 |
2d3e3d2d1ff86afb169ae0bca5ac8db6
|
|
| BLAKE2b-256 |
7989b8417d6a4e719bc1e64f979cd40999e4a03879031f0d5c1e8510e44485c1
|
File details
Details for the file switchai-0.1.0-py3-none-any.whl.
File metadata
- Download URL: switchai-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f3c7f86edc48a0e6cf965bfeeb537e2aa2c8804f7c48899922e488d8dc6a0c4
|
|
| MD5 |
3f3d38d508edab377f43fe84c99b2b3f
|
|
| BLAKE2b-256 |
381fa7e06df64721927caed585036dba549adc08cdb46a63c908a0decddf0c65
|