Skip to main content

The Knit OpenAI SDK enables seamless integration between OpenAI-powered agents and SaaS applications. This toolkit allows developers to easily connect AI agents with hundreds of SaaS platforms using Knit's integration platform. With minimal code, expand your AI assistant's capabilities by incorporating external data and functionalities from popular business applications.

Project description

Knit OpenAI SDK

Welcome to the Knit's OpenAI SDK, a powerful toolkit designed to integrate AI-powered agents built using OpenAI with a wide range of SaaS applications.

As an embedded integration platform, Knit provides a white-labeled solution empowering SaaS companies to effortlessly scale integrations within their own products, enriching customer experiences with dynamic, out-of-the-box functionality.

The Knit OpenAI SDK is designed to facilitate seamless integration between LLM agents and SaaS applications by leveraging Knit's platform and its wide range of connectors.

Installation

Kickstart your journey with the Knit OpenAI SDK by installing it via pip:

pip install knit-openai

Quick Start

First, get your Knit API Key by signing up at https://dashboard.getknit.dev/signup

Now, we're ready to start using the SDK. Here's a simple guide to help you start integrating with the Knit OpenAI SDK:

from openai import OpenAI
from knit_openai import KnitOpenAI, ToolFilter


client = OpenAI()
knit = KnitOpenAI()

integration_id = "b29fcTlZc2IwSzViSUF1NXI5SmhqOHdydTpjaGFybGllaHI="

tools = knit.find_tools(app_id="charliehr")
tool_defs = knit.get_tools(tools=[ToolFilter(app_id="charliehr", tool_ids=[tool.tool_id for tool in tools])])

assistant = client.beta.assistants.create(
    instructions="You are a bot for employee data in an HRIS system. Use the provided functions to answer questions",
    model="gpt-4o",
    tools=tool_defs,
)
thread = client.beta.threads.create()

print("Adding user message to thread...")
message = client.beta.threads.messages.create(
    thread_id=thread.id,
    role="user",
    content="I want to get the list of offices of the company",
)

run = client.beta.threads.runs.create_and_poll(
    thread_id=thread.id,
    assistant_id=assistant.id,
)

if run.status == "completed":
    messages = client.beta.threads.messages.list(thread_id=thread.id)
    for msg in messages.data:
        print(f"Message {msg.id} from {msg.role}: {msg.content}")
else:
    print(f"Run ended with status: {run.status}")

# Check if required_action exists
if hasattr(run, "required_action") and run.required_action:
    print("Run requires action. Tool calls:")
    # Loop through each tool in the required action section

    tool_outputs = []

    for i, tool in enumerate(run.required_action.submit_tool_outputs.tool_calls):
        print(tool)
        print(f"Tool call {i+1}:")
        print(f"ID: {tool.id}")
        print(f"Function: {tool.function.name}")
        print(f"Arguments: {tool.function.arguments}")

        tool_outputs.append(knit.handle_tool_call(tool, integration_id))

    run = client.beta.threads.runs.submit_tool_outputs_and_poll(
        thread_id=thread.id, run_id=run.id, tool_outputs=tool_outputs
    )
else:
    print("No tool actions required")

if run.status == "completed":
    messages = client.beta.threads.messages.list(thread_id=thread.id)
    for msg in messages.data:
        print(f"Message {msg.id} from {msg.role}: {msg.content}")
else:

That's it! It's that easy to get started and add hundreds of SaaS applications to your AI Agent.

Detailed Information

That was a quick introduction of how to get started with Knit's OpenAI SDK.

To know more about how to use its advanced features and for more in depth information, please refer to the detailed guide here: Knit OpenAI SDK Guide

Support

For support, reach out to kunal@getknit.dev

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

knit_openai-0.1.1.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

knit_openai-0.1.1-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file knit_openai-0.1.1.tar.gz.

File metadata

  • Download URL: knit_openai-0.1.1.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.9.13 Windows/10

File hashes

Hashes for knit_openai-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1f203825cde8dff6085e9bc354d4e138d894e6b51f0eaf6ca25067f1d30e1078
MD5 671e7c786597620c8ce25840ac7c1a49
BLAKE2b-256 7bc3ceb604d24646dfb528ab4f98c114f3263fc5d471c098fc97aa935f6265ed

See more details on using hashes here.

File details

Details for the file knit_openai-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: knit_openai-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.9.13 Windows/10

File hashes

Hashes for knit_openai-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4f049d9b7bee28f7357c63ef7d1dfedf6b87977a0f1321c782062bf4e176ce46
MD5 02fda9e03616d64c1c477abfcc3c02f4
BLAKE2b-256 ac86b4d7a1727856f28c72f2f89465226389c2c6bca441fd9f3e1e06fb0b5aca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page