Skip to content

Latest commit

 

History

History
89 lines (59 loc) · 2.38 KB

File metadata and controls

89 lines (59 loc) · 2.38 KB

Superwise Logo

Agents hallucinate and it's not going anywhere. Introduce supervision and sandboxes in mission critical systems to reduce the blast radius of the hallucinations.

Get started with Superwise using Python and OpenAI

Setup Environment

mkdir superwise-demo && cd superwise-demo

Install the required package with pip:

pip install langchain langchain-openai trysuperwise

Next, get your OpenAI API key from the OpenAI dashboard.

export OPENAI_API_KEY=<your-openai-api-key>

and set your Superwise Project ID and API key

export SUPERWISE_PROJECT_ID=<your-superwise-project-id>
export SUPERWISE_API_KEY=<your-superwise-api-key>

Create a Simple Agent

import re
from langchain_openai import ChatOpenAI

from trysuperwise import request_approval

llm = ChatOpenAI(model="gpt-4o", temperature=0)

prompt = """
Generate a linkedin message for an executive from linkedin for connection request.
You must return just the message and nothing before and after it.
Make sure there are no placeholders in the message.
Don't give me a template. If you don't have certain information keep it generic.
"""

def extract_main_content(text):
    cleaned_text = re.sub(r'<think>.*?</think>s*', '', text, flags=re.DOTALL)
    return cleaned_text.strip()


@request_approval(channel_id=<your-slack-channel-id>, channel="slack")
def generate_message():
    llm_response = llm.invoke(prompt)
    message = extract_main_content(llm_response.content)
    return message

def agent():
    message, response = generate_message()
    print('Message: ', message)
    print('Response: ', response)
    return message

if __name__ == '__main__':
    print(agent())