A Python client for the Interlify API
Project description
Interlify Client
A Python client for the Interlify API.
Installation
Install via pip:
pip install interlify
Usage:
from openai import OpenAI
from interlify import Interlify
client = OpenAI()
# Initialize the client
interlify = Interlify(
api_key="YOUR_API_KEY",
project_id="YOUR_PROJECT_ID",
auth_headers=[
{"Authorization": "Bearer YOUR_TOKEN"}
]
)
# Prepare tools
tools = client.get_tools()
completion = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "What is the weather like in Paris today?"}],
# Use tools
tools=tools
)
response_message = response.choices[0].message
tool_calls = response_message.tool_calls
messages.append(response_message)
for tool_call in tool_calls:
function_name = tool_call.function.name
function_args = json.loads(tool_call.function.arguments)
# Call the tool using interlify
function_response = interlify.call_tool(function_name, function_args)
messages.append(
{
"role": "tool",
"content": str(function_response),
"tool_call_id": tool_call.id,
}
)
final_response = client.chat.completions.create(
model=model, messages=messages, tools=tools, tool_choice="auto"
)
print(final_response.choices[0].message.content)
Work with OpenAI Agent SDK
OpenAI just released its Agent SDK. The Agents SDK is designed to be highly flexible, allowing you to model a wide range of LLM workflows including deterministic flows, iterative loops, and more.
Interlify's latest version supports OpenAI agent for tools calling, which makes integrating your APIs or services to the modern agent capability in a flash!
Here is the code:
import asyncio
import os
from dotenv import load_dotenv
from openai import AsyncOpenAI
from agents import (
Agent,
OpenAIChatCompletionsModel,
Runner,
set_tracing_disabled,
FunctionTool
)
from interlify import Interlify
load_dotenv()
# Set these variables in your .env file
BASE_URL = os.getenv("BASE_URL") or ""
API_KEY = os.getenv("API_KEY") or ""
MODEL_NAME = os.getenv("MODEL_NAME") or ""
INTERLIFY_API_KEY = os.getenv("INTERLIFY_API_KEY") or ""
PROJECT_ID = os.getenv("PROJECT_ID") or ""
ACCESS_TOKEN = os.getenv("ACCESS_TOKEN") or ""
if not BASE_URL or not API_KEY or not MODEL_NAME or not INTERLIFY_API_KEY or not PROJECT_ID or not ACCESS_TOKEN:
raise ValueError(
"Please set BASE_URL, API_KEY, MODEL_NAME, INTERLIFY_API_KEY, PROJECT_ID, ACCESS_TOKEN via env var or code."
)
# works for non-openai model as well
client = AsyncOpenAI(base_url=BASE_URL, api_key=API_KEY)
# disable tracing if you are using non-openai model
set_tracing_disabled(disabled=True)
# Initialize the client
interlify = Interlify(
api_key=INTERLIFY_API_KEY,
project_id=PROJECT_ID,
auth_headers=[{"Authorization": f"Bearer {ACCESS_TOKEN}"}],
)
# Prepare tools for agent: convert tools to FunctionTool format that agent can use
agent_tools = interlify.openai_agent_tools()
async def main():
agent = Agent(
name="Assistant",
instructions="You are a shoe shop assistant.",
model=OpenAIChatCompletionsModel(model=MODEL_NAME, openai_client=client),
tools=agent_tools,
)
result = await Runner.run(agent, "please update the price of the second shoe to 100.")
print(result.final_output)
if __name__ == "__main__":
asyncio.run(main())
That's it!
To setup the tools and projects, please visit to interlify website.
Project details
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 interlify-1.0.5.tar.gz.
File metadata
- Download URL: interlify-1.0.5.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d142b5e3c0d16e7e7c33817ff54824f57c4fa2ec504fb66c8fd8f81412bd64f0
|
|
| MD5 |
4474909eee150387eab5fb4f966e7dc3
|
|
| BLAKE2b-256 |
d808703525cb75e3bb0acd2fe6d53ad899290e1681e99a59769d9a34c6b07bae
|
File details
Details for the file interlify-1.0.5-py3-none-any.whl.
File metadata
- Download URL: interlify-1.0.5-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
588796db9ae1e2e3463a52a61bb7a5a45d81d8c3a47dbabdd03cd24694903987
|
|
| MD5 |
7bd22de297dbce2a818188ca34d171ab
|
|
| BLAKE2b-256 |
90fb394915e5c8c6fb181909a133dddf8f982fbc62f101cfc224eb047f2e634c
|